Here's my code, any ways in shortening it?
Okay heres the code...Ive just finished programming this, is there any way to save space. It seems a bit big. Also I deleted my name from privacy reasons.
Code:
//This program will play ASCLLAND - Intermediate Division
//Look at ICT 11 "Switch Statements" for rules.
#include <iostream.h>
void ASCLLAND(); //Plays the game ASCLLAND
int main()
{
ASCLLAND();
return(0);
}
void ASCLLAND()
//Pre:Takes moves in from user
//Post:Outputs location based on rules of ASCLLAND
{
bool WhichPlayer; //To decide which player is rolling
int DiceRoll; //The Amount of spaces moved
int PlayerA; //Where Player A is
int PlayerB; //Where Player B is
DiceRoll = 0;
PlayerA = 0;
PlayerB = 0;
WhichPlayer = true;
//It continues to loop until a 0 is entered
do
{
//To ensure that the user only inputs a number from 0-8
//Also adds up users moves
do
{
if (WhichPlayer == true)
{
cout << "Enter Move for Player A:(1-8, 0 to exit) ";
cin >> DiceRoll;
}
else if (WhichPlayer == false)
{
cout << "Enter Move for Player B:(1-8, 0 to exit) ";
cin >> DiceRoll;
}
//Switch statement to find out the spaces moved the players make
switch(DiceRoll)
{
case 1:
case 2:
case 3:
case 5:
case 7:
case 8:
{
//If statement is true, it will add up the dice roll
//If Player A exceeds 40, s/he is automatically brought back to 40
//Makes the statement false to allow player B to have next roll
if (WhichPlayer == true)
{
if (PlayerA >= 40 || PlayerB >= 40)
{break;}
else
{
PlayerA += DiceRoll;
WhichPlayer = false;
break;
}
}
//If statement is false, it will add up dice roll for player B
//If Player B exceeds 40, s/he is automatically brought back to 40
//Makes the statement true so the next move is player A's.
else if (WhichPlayer == false)
{
if (PlayerA >= 40 || PlayerB >= 40)
{break;}
else
{
PlayerB += DiceRoll;
WhichPlayer = true;
break;
}
}
}
case 4:
case 6:
{
//Same as above but with subtraction
if(WhichPlayer == true)
{
PlayerA -= DiceRoll;
if (PlayerA < 0)
{
PlayerA = 0;
}
WhichPlayer = false;
break;
}
else if (WhichPlayer == false)
{
PlayerB -= DiceRoll;
if (PlayerB < 0)
{
PlayerB = 0;
}
WhichPlayer = true;
break;
}
}
case 0:
{
break;
}
}
//If player A lands on player B or vice versa
//The player that first there returns to start(rules of game)
if(PlayerA == PlayerB)
{
if(WhichPlayer == true)
{
PlayerA = 0;
}
else if (WhichPlayer == false)
{
PlayerB = 0;
}
}
}
while(DiceRoll > 8 || DiceRoll < 0);
}
while(DiceRoll != 0);
if (PlayerA >= 40)
{
cout << "A - End" << endl;
}
else
{
cout << "A - " << PlayerA << endl;
}
if (PlayerB >= 40)
{
cout << "B - End" << endl;
}
else
{
cout << "B - " << PlayerB << endl;
}
}