Ejemplo n.º 1
0
        // Draw unplaced player pieces before moving
        public void DrawPlayerUnplacedPieces(Player player)
        {
            int allPieces = 9;
            int numberOfPieceForPlacing = player.piece.Count - player.piece.GetPiecesPlacedOnBoard();
            int col = player.Display.x;
            int row = player.Display.y;

            for (int i = 0; i < allPieces; i++)
            {
                Console.ResetColor();
                if (i % 3 == 0)
                {
                    row += 2;
                    col = player.Display.x;
                }
                if (i < numberOfPieceForPlacing)
                {
                    DrawPiecePlace(col, row, player.piece.PiecesColor, "███");
                }
                else
                {
                    DrawPiecePlace(col, row, ConsoleColor.Black, "███");
                }
                col += 4;
            }
        }
Ejemplo n.º 2
0
        // Draw centered player names before moving
        public void DrawPlayerName(Player player, int width, int lenght)
        {
            int placeForName = 11;
            int nameLength = player.Name.Length;
            int nameXPosition = (placeForName - nameLength) / 2;

            // Check player 1 or 2 and center his name position
            Console.SetCursorPosition(
               player.Display.x + nameXPosition + ((player.Display.x < width / 2) ? lenght + 1 : -(lenght + 3)),
               player.Display.y + 4);

            Console.ForegroundColor = player.piece.PiecesColor;
            Console.WriteLine(player.Name);
            Console.ResetColor();
        }
Ejemplo n.º 3
0
        private static void GameOver(Player p1, Player p2)
        {
            /*********************************************************/
            bool winP1 = p2.Loose(p1.piece.positionsOnBoard);
            bool winP2 = p1.Loose(p2.piece.positionsOnBoard);
            if (winP1 || winP2)
            {
                Console.Clear();
                Console.SetCursorPosition(0, 0);
                Console.ForegroundColor = ConsoleColor.Yellow;
                PrintTextFileToConsole(WinMsg);
                if (winP1)
                {
                    Console.ForegroundColor = p1.piece.PiecesColor;
                    Console.SetCursorPosition((WindowWidth - p1.Name.Length) / 2, 0);
                    Console.Write("{0} wins!", p1.Name);
                }

                if (winP2)
                {
                    Console.ForegroundColor = p2.piece.PiecesColor;
                    Console.SetCursorPosition((WindowWidth - p2.Name.Length) / 2, 0);
                    Console.Write("{0} wins!", p2.Name);
                }

                PlaySound(WinSound, false, soundON, 1350);
                Console.ReadLine();
                Console.Clear();
                cursorCurrentRow = defaultCursorStartRow;
                option = 1;
                StartMenu();
                // да се измисли нещо за изход
            }
            /*********************************************************/
        }
Ejemplo n.º 4
0
        private static void PlayGame()
        {
            byte gameMode;
            do
            {
                Console.Clear();
                Console.SetCursorPosition(0, 0);
                Console.Write("Press 1 for singleplayer or 2 for multiplayer: ");
            }
            while (!byte.TryParse(Console.ReadLine(), out gameMode) || (gameMode != 1 && gameMode != 2));

            List<string> playersName = (InputPlayersNames(gameMode));

            // SinglePlayer is started when the name of the 2nd player is 'PC'
            if (gameMode == 1)
            {
                playersName.Add("PC");
                secondPlayer = new Robot(new Piece(), playersName[1]);
            }
            else
            {
                secondPlayer = new RealPlayer(new Piece(), playersName[1], 0);
            }

            gameBoard = new Board();
            gameBoard.DrawBoard();

            firstPlayer = new RealPlayer(new Piece(), playersName[0], 0);

            firstPlayer.piece.LoadPiecesPositionsFromBoard(gameBoard);
            secondPlayer.piece.LoadPiecesPositionsFromBoard(gameBoard);

            firstPlayer.Display = new Position(35, 11);
            secondPlayer.Display = new Position(47, 17);

            secondPlayer.piece.PiecesColor = ConsoleColor.Red;

            PiecePlacing();
            PieceMoving();
        }
Ejemplo n.º 5
0
        private static string Check(Player p1, Player p2)
        {
            Console.ForegroundColor = p1.piece.PiecesColor;
            Console.Write("{0}: ", p1.Name);
            PlaySound(WaitingSound, true, soundON);

            string input = String.Empty;
            if (p1 is Robot)
            {
                input = (p1 as Robot).GenerateInputForPlacing(AllPossibleMills, p2.piece);
            }
            else
            {
                input = ReadString(2);
            }

            // positions temp for this player
            bool[,] playerPositionTemp = (bool[,])p1.piece.positionsOnBoard.Clone();

            p1.piece.curPos = p1.piece.GetPositionFromInput(input);
            p1.piece.DrawPieceAt(p1.piece.GetPositionFromInput(input), p1.piece.PiecesColor, p2.piece);
            p1.piece.positionsOnBoard[p1.piece.curPos.x, p1.piece.curPos.y] = true;

            gameBoard.DrawPlayerUnplacedPieces(p1);
            gameBoard.DrawPlayerUnplacedPieces(p2);

            // Check for "mills"
            if (CheckForMills(p1.piece, playerPositionTemp))
            {
                PlaySound(KoramSound, false, soundON, 3100);
                while (true)
                {
                    try
                    {
                        Console.SetCursorPosition(WindowWidth / 2 - 5, WindowHeight - 2);
                        Console.Write(new string(' ', 15));

                        Console.SetCursorPosition(WindowWidth / 2 - 5, WindowHeight - 2);
                        Console.ForegroundColor = p1.piece.PiecesColor;
                        Console.Write("{0}: ", p1.Name);

                        string remove = String.Empty;
                        if (p1 is Robot)
                        {
                            remove = (p1 as Robot).GenerateInputForRemoving(AllPossibleMills, p2.piece);
                        }
                        else
                        {
                            remove = ReadString(2);
                        }

                        p2.piece.RemovePiece(p2.piece.GetPositionFromInput(remove), p1.piece);
                        PlaySound(TakeOffSound, false, soundON, 1350);
                        break;
                    }
                    catch (Exception)
                    {
                        PlaySound(WrongInputSound, false, soundON, 800);
                        continue;
                    }
                }
            }
            else
            {
                PlaySound(MoveSound, false, soundON, 1350);
            }

            GameOver(p1, p2);

            return input;
        }