private void Deal(IRandom random) { Deck.Shuffle(random); Pot = Human.AnteUp() + Computer.AnteUp(); Human.NewHand(); Computer.NewHand(); _io.WriteLine("Your hand:"); _io.Write(Human.Hand); }
public void Play() { _io.Write(Resource.Streams.Introduction); if (!_io.ReadString("Do you want instructions").Equals("no", InvariantCultureIgnoreCase)) { _io.Write(Resource.Streams.Instructions); } BuildBugs(); _io.Write(Resource.Streams.PlayAgain); }
internal void Play() { _io.Write(Resource.Streams.Title); _io.Write(Resource.Streams.Instructions); var deck = new Deck(); var human = new Human(200, _io); var computer = new Computer(200, _io, _random); var table = new Table(_io, _random, deck, human, computer); do { table.PlayHand(); } while (table.ShouldPlayAnotherHand()); }
protected override CommandResult ExecuteCommandCore(Quadrant quadrant) { if (!quadrant.HasKlingons) { _io.WriteLine(Strings.NoEnemyShips); return(CommandResult.Ok); } if (_enterprise.Computer.IsDamaged) { _io.WriteLine("Computer failure hampers accuracy"); } _io.Write($"Phasers locked on target; "); var phaserStrength = GetPhaserStrength(); if (phaserStrength < 0) { return(CommandResult.Ok); } _enterprise.UseEnergy(phaserStrength); var perEnemyStrength = GetPerTargetPhaserStrength(phaserStrength, quadrant.KlingonCount); foreach (var klingon in quadrant.Klingons.ToList()) { ResolveHitOn(klingon, perEnemyStrength, quadrant); } return(quadrant.KlingonsFireOnEnterprise()); }
protected override void DrawCards(Deck deck) { var keepMask = Strategy.KeepMask ?? Hand.KeepMask; var count = 0; for (var i = 1; i <= 5; i++) { if ((keepMask & (1 << (i - 1))) == 0) { Hand = Hand.Replace(i, deck.DealCard()); count++; } } _io.WriteLine(); _io.Write($"I am taking {count} card"); if (count != 1) { _io.WriteLine("s"); } Strategy = (Hand.IsWeak, Hand.Rank < HandRank.Three, Hand.Rank < HandRank.FullHouse) switch { _ when Strategy is Bluff => Strategy.Bluff(28), (true, _, _) => Strategy.Fold, (false, true, _) => _random.Next(10) == 0 ? Strategy.Bet(19) : Strategy.Raise, (false, false, true) => _random.Next(10) == 0 ? Strategy.Bet(11) : Strategy.Bet(19), (false, false, false) => Strategy.Raise }; }
internal void Play() { _io.Write(Streams.Introduction); if (_io.ReadNumber(Prompts.ForInstructions) != 0) { _io.Write(Streams.Instructions); } do { new Game(_io, _random).Play(); } while (_io.ReadNumber(Prompts.WantToTryAgain) == 1); _io.Write(Streams.Thanks); }
internal static void WaitForAnyKeyButEnter(this IReadWrite io, string prompt) { io.Write($"Hit any key but Enter {prompt} "); while (io.ReadCharacter() == '\r') { ; } }
public void Play() { _io.Write(Streams.Introduction); do { var board = new Board(); do { _io.WriteLine(board); _io.WriteLine(); } while (board.PlayMove(_io)); _io.WriteLine(board.GetReport()); } while (_io.ReadYesNo(Prompts.TryAgain) == "yes"); _io.Write(Streams.Bye); }
public void Play() { while (true) { _io.Write(Streams.Introduction); var limit = _io.ReadNumber(Prompts.Limit); _io.WriteLine(); // There's a bug here that exists in the original code. // If the limit entered is <= 0 then the program will crash. var targetGuessCount = checked ((int)Math.Log2(limit) + 1); PlayGuessingRounds(limit, targetGuessCount); _io.Write(Streams.BlankLines); } }
public static Shot?ReadShot(this IReadWrite io, string prompt) { while (true) { if (io.TryReadInteger(prompt, out var value) && Shot.TryGet(value, out var shot)) { return(shot); } io.Write("Incorrect answer. Retype it. "); } }
internal void WriteDamageReport() { _io.WriteLine(); _io.WriteLine("Device State of Repair"); foreach (var system in _enterprise.Systems) { _io.Write(system.Name.PadRight(25)); _io.WriteLine((int)(system.Condition * 100) * 0.01F); } _io.WriteLine(); }
internal static int ReadNumber(this IReadWrite io, string prompt, int max, string maxPrompt) { io.Write(prompt); while (true) { var response = io.ReadNumber(); if (response <= max) { return((int)response); } io.WriteLine(maxPrompt); } }
internal static string ReadYesNo(this IReadWrite io, string prompt) { while (true) { var response = io.ReadString(prompt).ToLower(); if (response == "yes" || response == "no") { return(response); } io.Write(Streams.YesOrNo); } }
public void Play(Func <bool> playAgain) { _io.Write(Streams.Title); _io.Write(Streams.Instructions); while (playAgain.Invoke()) { var timeIncrement = _io.ReadParameter("Time increment (sec)"); var velocity = _io.ReadParameter("Velocity (fps)"); var elasticity = _io.ReadParameter("Coefficient"); var bounce = new Bounce(velocity); var bounceCount = (int)(Graph.Row.Width * timeIncrement / bounce.Duration); var graph = new Graph(bounce.MaxHeight, timeIncrement); var time = 0f; for (var i = 0; i < bounceCount; i++, bounce = bounce.Next(elasticity)) { time = bounce.Plot(graph, time); } _io.WriteLine(graph); } }
internal void Play() { _io.Write(Resource.Streams.Introduction); if (_io.ReadNumber("Do you want the rules (1=Yes, 0=No!)") != 0) { _io.Write(Resource.Streams.Rules); } while (true) { _io.Write(Resource.Streams.HereWeGo); var(playerCount, rowCount, columnCount) = _io.ReadParameters(); var loser = Play(new Cookie(rowCount, columnCount), new PlayerNumber(playerCount)); _io.WriteLine(string.Format(Resource.Formats.YouLose, loser)); if (_io.ReadNumber("Again (1=Yes, 0=No!)") != 1) { break; } } }
internal static IEnumerable <int> Read10Digits(this IReadWrite io, string prompt, Stream retryText) { while (true) { var numbers = new float[10]; io.ReadNumbers(prompt, numbers); if (numbers.All(n => n == 0 || n == 1 || n == 2)) { return(numbers.Select(n => (int)n)); } io.Write(retryText); } }
protected override CommandResult ExecuteCommandCore(Quadrant quadrant) { _io.WriteLine($"Energy available = {_enterprise.TotalEnergy}"); var requested = _io.ReadNumber($"Number of units to shields"); if (Validate(requested)) { ShieldEnergy = requested; _io.Write(Strings.ShieldsSet, requested); } else { _io.WriteLine("<SHIELDS UNCHANGED>"); } return(CommandResult.Ok); }
protected override void DrawCards(Deck deck) { var count = _io.ReadNumber("How many cards do you want", 3, "You can't draw more than three cards."); if (count == 0) { return; } _io.WriteLine("What are their numbers:"); for (var i = 1; i <= count; i++) { Hand = Hand.Replace((int)_io.ReadNumber(), deck.DealCard()); } _io.WriteLine("Your new hand:"); _io.Write(Hand); }
private bool TryGetDistanceToMove(float warpFactor, out int distanceToTravel) { distanceToTravel = (int)Math.Round(warpFactor * 8, MidpointRounding.AwayFromZero); if (distanceToTravel <= _enterprise.Energy) { return(true); } _io.WriteLine("Engineering reports, 'Insufficient energy available"); _io.WriteLine($" for maneuvering at warp {warpFactor} !'"); if (distanceToTravel <= _enterprise.TotalEnergy && !_enterprise.ShieldControl.IsDamaged) { _io.Write($"Deflector control room acknowledges {_enterprise.ShieldControl.ShieldEnergy} "); _io.WriteLine("units of energy"); _io.WriteLine(" presently deployed to shields."); } return(false); }
internal static float?ReadWager(this IReadWrite io, float balance) { io.Write(Streams.Wager); if (io.ReadNumber("") == 0) { return(null); } var prompt = Prompts.HowMuch; while (true) { var wager = io.ReadNumber(prompt); if (wager <= balance) { return(wager); } prompt = Prompts.BetAgain; } }
internal bool TryRepair(Enterprise enterprise, out float repairTime) { repairTime = enterprise.DamagedSystemCount * 0.1f + _repairDelay; if (repairTime >= 1) { repairTime = 0.9f; } _io.Write(Strings.RepairEstimate, repairTime); if (_io.GetYesNo(Strings.RepairPrompt, IReadWriteExtensions.YesNoMode.TrueOnY)) { foreach (var system in enterprise.Systems) { system.Repair(); } return(true); } repairTime = 0; return(false); }
internal void Play() { DoIntroduction(); var result = _io.ReadNumber(Prompts.Answer); if (_io.ReadYes(Formats.Bet, Math.CalculateOriginal(result))) { _io.Write(Streams.Bye); return; } var original = _io.ReadNumber(Prompts.Original); _io.WriteLine(Math.ShowWorking(original)); if (_io.ReadYes(Prompts.Believe)) { _io.Write(Streams.Bye); return; } _io.Write(Streams.Lightning); }
public Pattern(IReadWrite io) { _io = io; io.Write(Streams.Introduction); }