mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2026-02-04 11:07:59 -08:00
Code cleanup
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Roulette;
|
||||
|
||||
internal class Game
|
||||
@@ -7,14 +5,14 @@ internal class Game
|
||||
private readonly IReadWrite _io;
|
||||
private readonly IRandom _random;
|
||||
private readonly Table _table;
|
||||
private readonly Croupier _house;
|
||||
private readonly Croupier _croupier;
|
||||
|
||||
public Game(IReadWrite io, IRandom random)
|
||||
{
|
||||
_io = io;
|
||||
_random = random;
|
||||
_house = new();
|
||||
_table = new(_house, io, random);
|
||||
_croupier = new();
|
||||
_table = new(_croupier, io, random);
|
||||
}
|
||||
|
||||
public void Play()
|
||||
@@ -27,13 +25,18 @@ internal class Game
|
||||
|
||||
while (_table.Play());
|
||||
|
||||
if (!_house.PlayerIsBroke)
|
||||
{
|
||||
_house.CutCheck(_io, _random);
|
||||
}
|
||||
else
|
||||
if (_croupier.PlayerIsBroke)
|
||||
{
|
||||
_io.Write(Streams.LastDollar);
|
||||
_io.Write(Streams.Thanks);
|
||||
return;
|
||||
}
|
||||
|
||||
if (_croupier.HouseIsBroke)
|
||||
{
|
||||
_io.Write(Streams.BrokeHouse);
|
||||
}
|
||||
|
||||
_croupier.CutCheck(_io, _random);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,11 +4,11 @@ internal class Table
|
||||
{
|
||||
private readonly IReadWrite _io;
|
||||
private readonly Wheel _wheel;
|
||||
private readonly Croupier _house;
|
||||
private readonly Croupier _croupier;
|
||||
|
||||
public Table(Croupier house, IReadWrite io, IRandom random)
|
||||
public Table(Croupier croupier, IReadWrite io, IRandom random)
|
||||
{
|
||||
_house = house;
|
||||
_croupier = croupier;
|
||||
_io = io;
|
||||
_wheel = new(random);
|
||||
}
|
||||
@@ -19,20 +19,9 @@ internal class Table
|
||||
var slot = SpinWheel();
|
||||
SettleBets(bets, slot);
|
||||
|
||||
_io.Write(_house.Totals);
|
||||
_io.Write(_croupier.Totals);
|
||||
|
||||
if (_house.PlayerIsBroke)
|
||||
{
|
||||
_io.Write(Streams.LastDollar);
|
||||
_io.Write(Streams.Thanks);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_house.HouseIsBroke)
|
||||
{
|
||||
_io.Write(Streams.BrokeHouse);
|
||||
return false;
|
||||
}
|
||||
if (_croupier.PlayerIsBroke || _croupier.HouseIsBroke) { return false; }
|
||||
|
||||
return _io.ReadString(Prompts.Again).ToLowerInvariant().StartsWith('y');
|
||||
}
|
||||
@@ -76,7 +65,7 @@ internal class Table
|
||||
{
|
||||
foreach (var bet in bets)
|
||||
{
|
||||
_io.Write(slot.IsCoveredBy(bet) ? _house.Pay(bet) : _house.Take(bet));
|
||||
_io.Write(slot.IsCoveredBy(bet) ? _croupier.Pay(bet) : _croupier.Take(bet));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user