Exemplo n.º 1
0
 public FormOtheloGame(bool i_IsTwoPlayers, int i_BoardSize, OtheloGame i_Game)
 {
     m_Game              = i_Game;
     m_BoardSize         = i_BoardSize;
     m_IsTwoPlayers      = i_IsTwoPlayers;
     m_PictureBoxesBoard = new PictureBoxCell[m_BoardSize, m_BoardSize];
     initializePictureBoxBoard(m_Game.CurrentGame);
     InitializeComponent();
 }
Exemplo n.º 2
0
        private void printGameBoard(OtheloGame i_Game)
        {
            int    size              = i_Game.OtheloBoard.GetLength(0);
            char   c                 = 'A';
            string line              = new string('=', (4 * size) + 1);
            string firstPlayerName   = i_Game.Players[0].Name;
            string secondPlayerName  = i_Game.Players[1].Name;
            int    firstPlayerScore  = i_Game.Players[0].Score;
            int    secondPlayerScore = i_Game.Players[1].Score;

            Console.Write(" ");
            for (int j = 0; j < size; j++)
            {
                Console.Write("   {0}", char.ConvertFromUtf32(c + j));
            }

            Console.WriteLine("{0} {1}", Environment.NewLine, line);
            for (int i = 1; i <= size; i++)
            {
                Console.Write("{0} |", i);
                for (int j = 1; j <= size; j++)
                {
                    Console.Write(" {0} |", (char)i_Game.GetSquareType(i - 1, j - 1));
                }

                if (i == size / 2)
                {
                    if (i_Game.Turn == 0)
                    {
                        Console.Write("-->");
                    }
                    else
                    {
                        Console.Write("   ");
                    }

                    Console.Write("{0} Score: {1} Soldier X", firstPlayerName, firstPlayerScore);
                }
                else if (i == (size / 2) + 1)
                {
                    if (i_Game.Turn == 1)
                    {
                        Console.Write("-->");
                    }
                    else
                    {
                        Console.Write("   ");
                    }

                    Console.Write("{0} Score: {1} Soldier O", secondPlayerName, secondPlayerScore);
                }

                Console.WriteLine("{0} {1}", Environment.NewLine, line);
            }
        }
Exemplo n.º 3
0
        private void printTheScoreAndTheWinner(OtheloGame i_Game)
        {
            Console.WriteLine("The game is over! The scores are:");
            Console.WriteLine("{0} your score is: {1}", i_Game.Players[0].Name, i_Game.Players[0].Score);
            Console.WriteLine("{0} your score is: {1}", i_Game.Players[1].Name, i_Game.Players[1].Score);
            string theWinner = i_Game.GetWinnerName();

            if (theWinner == null)
            {
                Console.WriteLine("It's a tie!");
            }
            else
            {
                Console.WriteLine("The winner is {0} !!", theWinner);
            }
        }
Exemplo n.º 4
0
        private void initializeLogicGame()
        {
            int           boardSize = m_FormSettings.SelectedBoardSize;
            List <Player> players   = new List <Player>();

            players.Add(new Player("Player 1", Game.ePlayerId.Player1));
            if (m_FormSettings.IsTwoPlayer)
            {
                players.Add(new Player("Player 2", Game.ePlayerId.Player2));
            }
            else
            {
                players.Add(new Player("Computer", Game.ePlayerId.Computer));
            }

            m_Game = new OtheloGame(players, boardSize);
        }
Exemplo n.º 5
0
        private void runGame(string i_FirstName, string i_SecondName, int i_BoardSize, eNumGameType i_GameType)
        {
            OtheloGame game = new OtheloGame(i_FirstName, i_SecondName, i_BoardSize, i_GameType);

            printIntroduction(i_FirstName, i_SecondName);
            string selectedMove = null;

            while (game.IsStillPlayable())
            {
                Ex02.ConsoleUtils.Screen.Clear();
                printGameBoard(game);
                if (!game.IsPlayerHasMove())
                {
                    game.SwitchTurn();
                    Console.WriteLine("There are no possible legal moves, The turn pass to : {0}!", game.PlayerNameTurn);
                    System.Threading.Thread.Sleep(4500);
                }
                else
                {
                    if (i_GameType == eNumGameType.PlayerVSPlayer || game.Turn == 0)
                    {
                        selectedMove = chooseMove(game.PlayerNameTurn);
                        if (selectedMove != "Q")
                        {
                            if (isValidString(selectedMove))
                            {
                                if (game.IsPlayerMoveExceedBoard(selectedMove))
                                {
                                    Console.WriteLine("Your input move is exceed the board size!");
                                    System.Threading.Thread.Sleep(4000);
                                }
                                else
                                {
                                    Coords newCoord = new Coords(selectedMove[1] - '1', selectedMove[0] - 'A');
                                    if (!game.IsLegalMoveTurn(newCoord))
                                    {
                                        Console.WriteLine("Your input move is illigal! {0}You must choose a move which blocks an opponent's  sequence", Environment.NewLine);
                                        System.Threading.Thread.Sleep(5000);
                                    }
                                    else
                                    {
                                        game.MakeMove(newCoord);
                                    }
                                }
                            }
                            else
                            {
                                Console.WriteLine("InValid input!");
                                System.Threading.Thread.Sleep(2000);
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                    else
                    {
                        Console.WriteLine("Comupter playing..");
                        System.Threading.Thread.Sleep(1500);
                        game.MakeCpuMove();
                    }
                }
            }

            if (selectedMove != null)
            {
                Ex02.ConsoleUtils.Screen.Clear();
                printGameBoard(game);
                printTheScoreAndTheWinner(game);
            }
        }