예제 #1
0
 /**
  * This method starting the game.
  */
 public static void StartGame()
 {
     //initiating stages of the game
     s_Player1 = new Player(initiatePlayer());
     gameMode();
     if (s_IsHuman)
     {
         s_Player2H = new Player(initiatePlayer());
     }
     else
     {
         s_Player2C = new ComputerPlayer();
     }
     //starts the game
     run();
 }
예제 #2
0
        /// <summary>
        /// Ask the computer for do its moves.
        /// </summary>
        private void letComputerPlayerPlay()
        {
            if (CurrentPlayer is ComputerPlayer)
            {
                ComputerPlayer computerPlayer = CurrentPlayer as ComputerPlayer;

                computerPlayer.SetThisTurn();
                for (int i = 0; i < 2; i++)
                {
                    System.Threading.Thread.Sleep(r_ComputerRevealingIterval);
                    Application.DoEvents();
                    Point selection = computerPlayer.GetCellsToReveal();
                    TryReveal(selection.X, selection.Y);
                }
            }
        }
예제 #3
0
        /**
         * Constructor for a new game
         */
        public Game(string i_FirstPlayerName, string i_SecondPlayerName, bool i_IsHuman, Deck i_GameDeck)
        {
            //initiating stages of the game
            r_Deck    = i_GameDeck;
            r_Player1 = new Player(i_FirstPlayerName, Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(192))))));
            r_IsHuman = i_IsHuman;

            if (r_IsHuman)
            {
                r_Player2H = new Player(i_SecondPlayerName, Color.MediumPurple);
            }
            else
            {
                r_Player2C = new ComputerPlayer();
            }
        }
예제 #4
0
        /// <summary>
        /// GameBoardForm constructor.
        /// </summary>
        /// <param name="i_boardSize">Board size.</param>
        /// <param name="i_firstPlayerName">First player name.</param>
        /// <param name="i_secondPlayerName">Second player name.</param>
        public GameBoardForm(Size i_boardSize, string i_firstPlayerName, string i_secondPlayerName)
        {
            Player[] players = new Player[2];
            Size     clientSize;
            int      additionHeight;

            m_GameBoard               = new GameBoard(i_boardSize, players);
            m_GameBoard.NoMatch      += waitAndHide;
            m_GameBoard.RevealedCell += showCell;
            m_GameBoard.OneTurnEnded += updateLabels;
            m_GameBoard.GameOver     += showWinnerAndClose;
            players[0]       = new Player(i_firstPlayerName);
            players[0].Color = r_FirstPlayerColor;
            if (i_secondPlayerName == null)
            {
                ComputerPlayer computerPlayer = new ComputerPlayer(i_boardSize);

                players[1]               = computerPlayer;
                CellRevealed            += computerPlayer.ShownCell;
                m_GameBoard.CoupleFound += computerPlayer.CoupleFound;
            }
            else
            {
                players[1] = new Player(i_secondPlayerName);
            }

            players[1].Color   = r_SecondPlayerColor;
            MaximizeBox        = false;
            MinimizeBox        = false;
            Text               = "Memory Game";
            SizeGripStyle      = SizeGripStyle.Hide;
            AutoSizeMode       = AutoSizeMode.GrowAndShrink;
            StartPosition      = FormStartPosition.CenterScreen;
            clientSize         = initializeGameBoardButtons(i_boardSize);
            additionHeight     = initializeLabels(clientSize.Height);
            clientSize.Height += additionHeight;
            ClientSize         = clientSize;
            m_GameBoard.Start();
        }