when i call dice.roll() it "randomly" picks a number from 1-6 for the dice...etc
the first time i ran the game, it worked nicely...
the second time appears nice...
third time, i got suspicious, and looked at the rolls more closely
every battle, each round rolls the same as the last battle, every time, exactly
for example, this is what it keeps rolling (in order of attacking, then defending dice, each row is another "roll")
66556
55355
35455
41625
21116
64532
end of attack
this exact same rolls happen everytime i start a game
here is the Dice class
Code: Select all
class Dice{
public:
int number;
int drawNumber;
int x;
int y;
int relx;
int rely;
int rolling;
IGUIElement* parent;
void roll(bool keep=true){
drawNumber=(rand()%6)+1;
if(keep)number=drawNumber;
}
void animateRolling(){
rolling=60;
}
void updateAnimation(){
if(rolling==0)return;
if(rolling%5==0)roll(false);
rolling--;
if(rolling==0)drawNumber=number;
}
void setPos(int x1, int y1){
relx=x1;
rely=y1;
}
void setParent(IGUIElement* p){
parent=p;
}
void updatePosition(){
rect<s32> prev=parent->getRelativePosition();
x=prev.UpperLeftCorner.X+relx;
y=prev.UpperLeftCorner.Y+rely;
}
void draw(){
this->updatePosition();
this->updateAnimation();
Video->draw2DRectangle(White2,rect<s32>(x,y,x+30,y+30));
if(drawNumber%2==1)Video->draw2DRectangle(Black2,rect<s32>(x+12,y+12,x+18,y+18));
if(drawNumber!=1){
Video->draw2DRectangle(Black2,rect<s32>(x+22,y+22,x+28,y+28));
Video->draw2DRectangle(Black2,rect<s32>(x+2,y+2,x+8,y+8));
}
if(drawNumber>3){
Video->draw2DRectangle(Black2,rect<s32>(x+22,y+2,x+28,y+8));
Video->draw2DRectangle(Black2,rect<s32>(x+2,y+22,x+8,y+28));
}
if(drawNumber==6){
Video->draw2DRectangle(Black2,rect<s32>(x+2,y+12,x+8,y+18));
Video->draw2DRectangle(Black2,rect<s32>(x+22,y+12,x+28,y+18));
}
}
};
rand() uses:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>