Exemple #1
0
        /// <summary>
        /// Method used to play any space on the board.
        /// </summary>
        /// <param name="type">SpaceType that is being played.</param>
        /// <param name="playedSpace">The position of the requested play space.</param>
        /// <returns>Returns true if space open and played, otherwise false if space is take</returns>
        public bool PlaySpace(SpaceTypes type, FieldItem playedSpace)
        {
            if (playedSpace.Posion.X == 4 || playedSpace.Posion.Y == 4 ||
                _fieldSpaces[playedSpace.Posion.X, playedSpace.Posion.Y] != SpaceTypes.Open) return false;

            _fieldSpaces[playedSpace.Posion.X, playedSpace.Posion.Y] = type;
            _openFieldPlaces.Remove(_openFieldPlaces.Find(x => x.Posion == new Point(playedSpace.Posion.X, playedSpace.Posion.Y)));
            DrawField();
            return true;
        }
Exemple #2
0
        /// <summary>
        /// This method is called when ever the user clicks on the board.
        /// It will check where the user clicks and assign it to a location on the board,
        /// if the click was on an open playing field and it is the users' turn it will play.
        /// </summary>
        /// <param name="sender">The panel from which the user clicked.</param>
        /// <param name="e">Contains the users click location relative to the Panel coordinate plane.</param>
        private void gamePanel_MouseClick(object sender, MouseEventArgs e)
        {
            int row = 4, column = 4;
            if (e.X < 190)
                row = 0;
            if (e.X > 205 && e.X < 395)
                row = 1;
            if (e.X > 410)
                row = 2;
            if (e.Y < 190)
                column = 0;
            if (e.Y > 205 && e.Y < 395)
                column = 1;
            if (e.Y > 410)
                column = 2;

            if (_twoPlayers)
            {
                var playedSpace = new FieldItem(row, column);
                var playedType = _aiTurn ? _aiType : _playerType;
                if (!_playingBoard.PlaySpace(playedType, playedSpace)) return;
                _aiTurn = !_aiTurn;
                turnLable.Text = _aiTurn ? @"Current Turn: Player 2" : @"Current Turn: Player 1";
            }
            else if (!_aiTurn)
            {
                var playedSpace = new FieldItem(row, column);
                var playedType = _playerType;
                if (!_playingBoard.PlaySpace(playedType, playedSpace)) return;
                _playingBoard.AiMove(_aiType);
                _aiTurn = false;
            }
        }