This is the beginning of a simple text game. In the game, you are supposed to go around finding dungeons and collecting artifacts. I use srand(time(0))
to do things such as find what stage to go to, attack, and what items you find, I haven' gotten far in the programming, but i have already encountered a problem. My rand() returns all outcomes. When i run the game (this is not the complete code, btw), it returns "You entered a dungeon!", "Oh No, an enemy has arrived!", and "you have found an artifact!
void mainScreen()
{
srand(time(0));
cout << "Health: \n";
cout << health;
cout << endl;
_sleep(500);
cout << "Inventory: \n";
cout << inventory;
cout << endl;
_sleep(500);
cout << "Gold: \n";
cout << gold;
cout << endl;
_sleep(500);
cout << "Artifacts: \n";
cout << artifacts;
cout << endl;
_sleep(500);
cout << "Rolling the dice of fate... \n";
int diceRoll = 1 + (rand() % 10);
if (diceRoll = 1, 2, 3, 4, 5, 6) {
cout << "You entered a dungeon! \n";
}
if (diceRoll = 7, 8) {
cout << "Oh No! An enemy has arrived! \n";
}
if (diceRoll = 9, 10) {
cout << "You found an artifact! \n";
}
}