Hi, I am fairly new to C++ but love to learn, so I wanted to create a simple program base on the group-party game mafia A.K.A "werewolf."
Just so whoever is not familiar gets the background. I will use just an example of 10 players. In a ten player game, there consists of 4 roles and this is how many there will be in the game:
3 Mafia
1 Cop
1 Doctor
5 Innocent
I figured I would assign those roles "randomly" to each player using those limits. So
0= mafia, 1= cop, 2= doctor, and 3 = innocent
I got somewhat of the code running ok only when generating a 3 player game. I only know how to use a bunch of "IF's" statement, if anyone knows how to make things easier, please feel free to teach me. When I try to compile a 10 player game, after getting all the player's names, the program just goes to a blank new line and nothing happens.
int main()
{
int numOfPlayers = getNumOfPlayers();
char playerName[numOfPlayers][256];
//getPlayerName(numOfPlayers, playerName);
getPlayerName(numOfPlayers, playerName);
int player[10];
//assign the roles to the players
assignRoles(numOfPlayers, player);
return 0;
}
int getNumOfPlayers()
{
int numOfPlayers;
cout << "How many players are there? ";
cin >> numOfPlayers;
return numOfPlayers;
}
char getPlayerName(int numOfPlayers, char playerName[][256])
{
for(int count = 0; count < numOfPlayers; count++)
{
cout << "Please enter the players name: ";
cin >> playerName[count];
}
}
int assignRoles(int numOfPlayers, int player[])
{
int mafia = 0;
int cop = 0;
int doc = 0;
int innocent = 0;
srand ( time(NULL) );
for (int i = 0; i < numOfPlayers; i++)
{
if (mafia < 3 && cop < 1 && doc < 1)
{player[i] = rand() % 4;
switch(player[i])
{
case 0:
mafia++;
break;
case 1:
cop++;
break;
case 2:
doc++;
break;
case 3:
innocent++;
}
}
else if (mafia < 3 && cop == 1 && doc < 1)
{
do (player[i] = rand() % 4);
while(player[i] != 1);
switch(player[i])
{
case 1:
mafia++;
break;
case 2:
cop++;
break;
case 3:
doc++;
break;
case 4:
innocent++;
}
}
else if (mafia < 3 && cop < 1 && doc == 1 )
{
do (player[i] = rand() % 4);
while(player[i] != 2);
switch(player[i])
{
case 1:
mafia++;
break;
case 2:
cop++;
break;
case 3:
doc++;
break;
case 4:
innocent++;
}
}
else if (mafia == 3 && cop < 1 && doc < 1 )
{
do (player[i] = rand() % 4);
while(player[i] != 0);
switch(player[i])
{
case 1:
mafia++;
break;
case 2:
cop++;
break;
case 3:
doc++;
break;
case 4:
innocent++;
}
}
else if (mafia == 3 && cop == 1 && doc < 1)
{
do (player[i] = rand() % 4);
while((player[i] != 0) || (player[i] != 1));
switch(player[i])
{
case 1:
mafia++;
break;
case 2:
cop++;
break;
case 3:
doc++;
break;
case 4:
innocent++;
}
}
else if (mafia == 3 && cop < 1 && doc == 1 )
{
do (player[i] = rand() % 4);
while((player[i] !=0) || (player[i] != 2));
switch(player[i])
{
case 1:
mafia++;
break;
case 2:
cop++;
break;
case 3:
doc++;
break;
case 4:
innocent++;
}
}
else if (mafia < 3 && cop == 1 && doc == 1)
{
do (player[i] = rand() % 4);
while((player[i] != 1) || (player[i] != 2));
switch(player[i])
{
case 1:
mafia++;
break;
case 2:
cop++;
break;
case 3:
doc++;
break;
case 4:
innocent++;
}
}
}
cout << "There are " << mafia << " mafias" << endl;
cout << "There are " << cop << " cops" << endl;
cout << "There are " << doc << " doctors" << endl;
cout << "There are " << innocent << " innocent" << endl;
return 0;
}
So basically, playerName[0] will be player[0],
playerName[1] will be player[1],
Oh, This user will be playing this as playerName[0], and the rest of the players will be computers.
The game continues in 2 Phases, a NIGHT time, and a DAY time.
During the NIGHT time, the mafia's will choose first who do they want to "kill, or get rid of" How should I write it that the mafia's will know who each other is, and if all the mafias are computers, they will randomly choose a person to kill other than mafias. If there is a 1 to 1 ness where more people are chosen, then it loops until there is a majority vote. They can only kill 1 per NIGHT time. The Cop then gets to choose who to investigate and find out their ROLES, this knowledge comes in handy. The Doctor, gets to choose who does he want to heal, which will negate the kill of a mafia if the same person gets chosen.
DAY TIME:
The revealed person whom the Mafia choose is announced dead.
Everyone Gets to vote who they think is the mafia. Of course mafias won't vote for mafias, and the COP will know who is innocent so he won't vote for that person. These votes will all be randomized unless stated above.
Then display who each person voted for.
Whoever gets the most vote, gets killed, reveal their role.
Show how many players are left, and what roles.
REPEAT NIGHT and DAY
Until All Mafias are killed, OR the # of Mafia's are equal to # of The others combine.
Whew, that was long, So, is this writable?? Or is it too much?
Thanks for any help!