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); }
private static bool TryReadInteger(this IReadWrite io, string prompt, out int intValue) { var floatValue = io.ReadNumber(prompt); intValue = (int)floatValue; return(intValue == floatValue); }
internal static float ReadParameter(this IReadWrite io, string parameter) { var value = io.ReadNumber(parameter); io.WriteLine(); return(value); }
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); }
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 float ReadDefense(this IReadWrite io, string prompt) { while (true) { var defense = io.ReadNumber(prompt); if (defense >= 6) { return(defense); } } }
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; } }
private float GetPhaserStrength() { while (true) { _io.WriteLine($"Energy available = {_enterprise.Energy} units"); var phaserStrength = _io.ReadNumber("Number of units to fire"); if (phaserStrength <= _enterprise.Energy) { return(phaserStrength); } } }
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 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 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); }
private int GetFunctionIndex() { while (true) { var index = (int)_io.ReadNumber("Computer active and waiting command"); if (index >= 0 && index <= 5) { return(index); } for (int i = 0; i < _functions.Length; i++) { _io.WriteLine($" {i} = {_functions[i].Description}"); } } }
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); }
internal static Strategy ReadHumanStrategy(this IReadWrite io, bool noCurrentBets) { while (true) { io.WriteLine(); var bet = io.ReadNumber("What is your bet"); if (bet != (int)bet) { if (noCurrentBets && bet == .5) { return(Strategy.Check); } io.WriteLine("No small change, please."); continue; } if (bet == 0) { return(Strategy.Fold); } return(Strategy.Bet(bet)); } }
public void Draw() { var diamondSize = _io.ReadNumber(Prompts.TypeNumber); _io.WriteLine(); var diamondCount = (int)(60 / diamondSize); var diamondLines = new List <string>(GetDiamondLines(diamondSize)).AsReadOnly(); for (int patternRow = 0; patternRow < diamondCount; patternRow++) { for (int diamondRow = 0; diamondRow < diamondLines.Count; diamondRow++) { var line = new StringBuilder(); for (int patternColumn = 0; patternColumn < diamondCount; patternColumn++) { line.PadToLength((int)(patternColumn * diamondSize)).Append(diamondLines[diamondRow]); } _io.WriteLine(line); } } }
internal static float ReadNumber(this IReadWrite io) => io.ReadNumber("");