//First Game!
//Coder: FireCoder.
//Date: 9/2/15
//Version 1.3
/*
Cleaned Code.
Now able to add multible players.
*/
#include <iostream>
#include <cstdlib>
#include <ctime>
void checkSurvival(int i); //To print your death message.
int main()
{
bool dead = false;
int slot, player = 1, players = 2;
constint BULLET_POS = 2; //Unchangable do to request.
srand(time(0)); //Changes seed every secound.
std::cout << "How many players?\t"; //Sets players.
std::cin >> players;
std::cin.ignore(); // This is to make sure after you press "Enter" it will not
// miss fire.
while(dead == false) //Game only works while alive.
{
slot = (rand() % 6) + 1; //What slot will be fired.
std::cout << "Press 'Enter' to pull trigger...";
std::cin.ignore(); //We only need a non-spesific input.
if(BULLET_POS != slot) //If bullet was not shot.
{
std::cout << "*click*\n";
checkSurvival(0);
if(player != players) //If Player 1 finished last.
{
player++;
}
else //If player 2 finished last.
{
player = 1;
}
std::cout << "Player "<< player <<": your turn.\n";
}
else //If bullet was shot.
{
std::cout << "BANG!!!\n";
checkSurvival(1);
dead = true; //Ends game.
}
}
std::cout << "Player "<< player <<" died...\n"; //Game ending message.
}
void checkSurvival(int i) //To print your death message.
{
if(i == 0) //If survived.
{
std::cout << "You survived for now...\n" ;
}
else //IF died.
{
std::cout << "R.I.P.\n";
}
}
There are variations of that game. I am just saying that not-spinning-between-turns is fair version. Another approach would be spinning barrel after each pair of turns.