First cut at implementing the game.

Added .gitignore file.
This commit is contained in:
rbamforth
2021-04-11 23:54:46 +01:00
parent e1f2c92b19
commit 815dc4ae72
3 changed files with 117 additions and 0 deletions

5
29 Craps/csharp/Craps/.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
.vs
TestResults
bin
obj

View File

@@ -6,8 +6,78 @@ namespace Craps
{
class Program
{
enum Result
{
naturalWin,
snakeEyesLoss,
loss,
pointLoss,
pointWin,
};
static void Main(string[] args)
{
var dice1 = new Dice();
var dice2 = new Dice();
var ui = new UserInterface();
int winnings = 0;
ui.Intro();
do
{
var bet = ui.PlaceBet();
var diceRoll = dice1.Roll() + dice2.Roll();
bool isWinner = false;
if (Win(diceRoll))
{
winnings += bet;
isWinner = true;
}
else if (Lose(diceRoll))
{
winnings -= bet;
isWinner = false;
}
else
{
var point = diceRoll;
ui.Point(point);
while (true)
{
var newRoll = dice1.Roll() + dice2.Roll();
if (newRoll == point)
{
winnings += bet;
isWinner = true;
break;
}
else if (newRoll == 7)
{
winnings -= bet;
isWinner = false;
break;
}
ui.RollAgain();
}
}
ui.ShowResult(isWinner, bet);
} while (ui.PlayAgain(winnings));
}
private static bool Lose(int diceRoll)
{
throw new NotImplementedException();
}
private static bool Win(int diceRoll)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,42 @@
using System;
namespace Craps
{
public class UserInterface
{
public UserInterface()
{
}
public void Intro()
{
}
public int PlaceBet()
{
return 0;
}
public bool PlayAgain(int bet)
{
throw new NotImplementedException();
}
internal void ShowResult(bool isWinner, int winnings)
{
throw new NotImplementedException();
}
internal void RollAgain()
{
throw new NotImplementedException();
}
internal void Point(int point)
{
throw new NotImplementedException();
}
}
}