The code below is for a game of Craps. I am not sure if the logic of the code is correct. I want to test it, but when I run this code no output is given. It compiles and a blank screen is displayed with no output. I can't figure out why nothing is displayed. Also, any advice on the logic of the code would be appreciated. I am having difficulty with how to do the reroll process when 2, 3, 7, 11, or 12 are not rolled initially. Thanks
For those unfamiliar with the game: 2 dice are rolled and rolling a 7 or 11 is a win. 2, 3, or 12 is a loss. Any other number becomes the "point" and the player rerolls until the point or a 7 is rolled. Matching the point is a victory. This time a 7 is a loss.
class Craps
{
const int dieSides = 6;
int roll;
//const int repeatGame = 1000;
Random random = new Random();
public void RollDice()
{
int die1 = 0;
int die2 = 0;
die1 = random.Next(6) + 1;
die2 = random.Next(6) + 1;
roll = die1 + die2;
Console.WriteLine("The shooter roled: {0}", roll);
}
public void PlayCraps()
{
RollDice();
int gameStatus = 0;
int point = roll;
int numRolls = 1;
while (gameStatus < 1)
{
if (roll == 7 || roll == 11)
{
Console.WriteLine("You won!");
break;
}
else if (roll == 2 || roll == 3 || roll == 12)
{
Console.WriteLine("You lost.");
break;
}
else
{
RollDice();
Console.WriteLine("The point is: {0}", point);
while (point != roll || roll != 7)
{
if (roll == point)
{
Console.WriteLine("You won!");
numRolls++;
gameStatus++;
}
if (roll == 7)
{
Console.WriteLine("You lost");
numRolls++;
gameStatus++;
}
RollDice();
numRolls++;
}
}
}
}
static void Main(string[] args)
{
Craps NewGame = new Craps();
Console.ReadLine();
}
}
}
Aucun commentaire:
Enregistrer un commentaire