mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2026-01-04 17:17:59 -08:00
First cut at implementing the game.
Added .gitignore file.
This commit is contained in:
5
29 Craps/csharp/Craps/.gitignore
vendored
Normal file
5
29 Craps/csharp/Craps/.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
.vs
|
||||
TestResults
|
||||
bin
|
||||
obj
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
42
29 Craps/csharp/Craps/Craps/UserInterface.cs
Normal file
42
29 Craps/csharp/Craps/Craps/UserInterface.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user