コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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();
            }
        }
コード例 #4
0
        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));
        }
コード例 #5
0
        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);
        }
コード例 #6
0
ファイル: ConsoleUtilsFixture.cs プロジェクト: oskar/pistol
        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: "));
                }
        }