Exemple #1
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            HumanPlayer humanPlayer = new HumanPlayer("Moutasem Al-awa", getSelectedSymbol());
            XOSymbol xoSymbolPCPlayer = XOSymbol.EMPTY;

            switch(getSelectedSymbol())
            {
                case XOSymbol.O:
                    xoSymbolPCPlayer = XOSymbol.X;
                    break;
                case XOSymbol.X:
                    xoSymbolPCPlayer = XOSymbol.O;
                    break;
            }
            PCPlayer pcPlayer = new PCPlayer(xoSymbolPCPlayer);

            Player firstPlayer = null;
            firstPlayer = pcPlayer;
            if (isHumanFirst())
                firstPlayer = humanPlayer;

            GameEngine gameEngine = new GameEngine(humanPlayer, pcPlayer, firstPlayer);
            gamePadUC1.GameEngine = gameEngine;

            grbGameSettings.Enabled = false;
            gamePadUC1.Enabled = true;

            if (!isHumanFirst())
            {
                pcPlayer.Play();
                gamePadUC1.AddMove(pcPlayer.GameMove);
            }
        }
Exemple #2
0
        public GameEngine(HumanPlayer humanPlayer, PCPlayer pcPlayer, Player firstPlayerTurn)
        {
            if (humanPlayer.XOSymbol == pcPlayer.XOSymbol)
                throw new Exception("Invalid Players.You can not give the PC and the Human player the same XO symbol");

            HumanPlayer = humanPlayer;
            PCPlayer = pcPlayer;
            this.currentPlayerTurn = firstPlayerTurn;
            gamePad = new XOSymbol[3, 3];
            winnerPlayer = null;
            isGameOver = false;
        }