public Gun BangTwoOnOne(int shooterLeftGun, int shooterRightGun, int victimGun) { var command = ConsoleUtils.Ask(string.Format("Your turn, {0}, opponent only has one gun [L, R]: ", this.name_), new[] { "L", "R" }); var shooterGun = CommandLetterToGun(command[0]); return(shooterGun); }
public Gun BangOneOnTwo(int shooterGun, int victimLeftGun, int victimRightGun) { var command = ConsoleUtils.Ask(string.Format("Your turn, {0}, you only have one gun [L, R]: ", this.name_), new[] { "L", "R" }); var victimGun = CommandLetterToGun(command[0]); return(victimGun); }
private static void Main(string[] args) { var options = new Options(); if (CommandLine.Parser.Default.ParseArguments(args, options)) { var mode = options.Mode; if (string.IsNullOrEmpty(mode)) { mode = ConsoleUtils.Ask("Please enter game mode: ", input => input.Length > 1 && input.All(c => c == 'H' || c == 'C')); } var players = new List <Player>(); var playerNumber = 1; foreach (var modeLetter in mode) { players.Add(CreatePlayerFromModeLetter(modeLetter, playerNumber)); playerNumber++; } // Play a game of pistol var game = new Game(); game.Play(players); Console.ReadLine(); } }
public Tuple <Gun, Gun> Bang(int shooterLeftGun, int shooterRightGun, int victimLeftGun, int victimRightGun) { var command = ConsoleUtils.Ask(string.Format("Your turn, {0} [LL, LR, RL, RR]: ", this.name_), new[] { "LL", "LR", "RL", "RR" }); var shooterGun = CommandLetterToGun(command[0]); var victimGun = CommandLetterToGun(command[1]); return(new Tuple <Gun, Gun>(shooterGun, victimGun)); }
private static Player CreatePlayerFromModeLetter(char modeLetter, int playerNumber) { if (modeLetter == 'H') { var playerName = ConsoleUtils.Ask(string.Format("Player {0}, please enter your name: ", playerNumber), 1, Player.MaxNameLength); return(new Player(playerName, new HumanBangStrategy(playerName), null)); } if (modeLetter == 'C') { return(new Player(random_.NextItem(computerNames_), null, new RandomMultiPlayerBangStrategy())); } throw new InvalidOperationException("Unexpected char in mode string: " + modeLetter); }
public void TestAsk() { using (var outputResult = new StringWriter()) using (var inputReader = new StringReader("My input")) { // Arrange Console.SetOut(outputResult); Console.SetIn(inputReader); // Act var result = ConsoleUtils.Ask("My question: ", 1, 20); // Assert Assert.That(result, Is.EqualTo("My input")); Assert.That(outputResult.ToString(), Is.EqualTo("My question: ")); } }