..
C++ Language
1. Write a program to
roll a random character. Declare an enum with all the different
character types in
your game. Then use the rand()to generate a random number between
the min and max values of your
enum (e.g. if you have 4 character classes, then enum values are 0,
1, 2, 3). Finally, depending on the type
of character that was randomly selected, generate the rest of the
stats, either randomly or hardcoded.
Example Output
Press enter to roll a random character...
Type: Warrior
HP: 93
MP: 1
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
enum Characters
{
king, warrior, goblin, horse
};
int main()
{
srand(time(NULL));
cout<<"Press enter to roll a random character...";
cin.get();
int character = rand() % 4;//Generate a random character
switch(character)
{
case king: cout<<"Type: King
";
cout<<"HP: 200
";
cout<<"MP: 10
";
break;
case warrior: cout<<"Type: Warrior
";
cout<<"HP: 93
";
cout<<"MP: 1
";
break;
case goblin: cout<<"Type: Goblin
";
cout<<"HP: 40
";
cout<<"MP: 2
";
break;
case horse: cout<<"Type: Horse
";
cout<<"HP: 20
";
cout<<"MP: 0
";
break;
}
return 0;
}
SAMPLE OUTPUT:
.. C++ Language 1. Write a program to roll a random character. Declare an enum with...