Beispiel #1
0
        public TenSticksGame(TenSticksPlayer player1, TenSticksPlayer player2, int sticks = 10)
        {
            Random      = new Random();
            _gameStatus = GameStatus.NotStarted;

            SticksInit    = sticks;
            SticksCurrent = sticks;

            players[(int)Player.One] = player1;
            players[(int)Player.Two] = player2;

            Current = Random.Next(0, 2) == 0 ? Player.One : Player.Two;
        }
Beispiel #2
0
        private static int Game_GameInProgress(TenSticksGame game, TenSticksPlayer player)
        {
            var sticksToTake = -1;
            var max          = game.SticksCurrent >= 3 ? 3 : game.SticksCurrent;

            // Console.WriteLine($"Remaining sticks: game.SticksCurrent");
            Console.WriteLine($"Remaining sticks: {game.SticksCurrent} --> {new string('|', game.SticksCurrent)}");
            Console.Write($"\t{player.Name} take from 1 to {max}.");

            if (player.SticksPlayerType == SticksPlayerType.Cpu)
            {
                sticksToTake = game.Random.Next(1, max + 1);
                return(sticksToTake);
            }

            while (sticksToTake < 1 || sticksToTake > max)
            {
                switch (sticksToTake)
                {
                case -1:
                    break;

                default:
                    Console.Write($"\tWrong Number. Enter number from 1 to {max}: ");
                    break;
                }

                var answer = Console.ReadLine();
                try
                {
                    sticksToTake = int.Parse(answer);
                }
                catch (FormatException)
                {
                    sticksToTake = -2;
                }
            }

            return(sticksToTake);
        }
Beispiel #3
0
        private static void TenSticks()
        {
            var p1 = new TenSticksPlayer("John", SticksPlayerType.Human);
            var p2 = new TenSticksPlayer("Karl", SticksPlayerType.Human);
            var p3 = new TenSticksPlayer("R2D2", SticksPlayerType.Cpu);
            var p4 = new TenSticksPlayer("C3PO", SticksPlayerType.Cpu);

            // var game = new TenSticksGame(p1,p2);
            // var game = new TenSticksGame(p1,p3);
            var game = new TenSticksGame(p3, p4);

            game.GameInProgress += Game_GameInProgress;
            game.SticksTaken    += Game_SticksTaken;
            game.EndGame        += Game_EndGame;
            // game.Start();

            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine("\t\tStarting 10 Sticks Demo.\n");
                game.Start();
                ConsoleUtils.PrintInternalSeparator();
            }
        }
Beispiel #4
0
 private static void Game_EndGame(TenSticksPlayer player)
 {
     Console.WriteLine("\t---------------");
     Console.WriteLine($"\tPlayer {player.Name} wins!");
 }
Beispiel #5
0
 private static void Game_SticksTaken(TenSticksPlayer player, int sticks)
 {
     Console.WriteLine($"\t{player.Name} took {sticks} sticks");
 }