コード例 #1
0
        public bool UpdateBoardAfterMove(Move i_UserMove, Player i_CurrentPlayer, bool i_NeedToEliminate)
        {
            int  areaCheck = 1;
            bool isUpdate  = false;

            Square.eSquareType squareType = this.GetSquareStatus(i_UserMove.SquareFrom);

            if (i_CurrentPlayer.IsMyKing(squareType))
            {
                squareType = i_CurrentPlayer.PlayerType;
            }

            if (i_NeedToEliminate)
            {
                areaCheck++;
            }

            if (Math.Abs(i_UserMove.SquareFrom.Row - i_UserMove.SquareTo.Row) <= areaCheck &&
                Math.Abs(i_UserMove.SquareFrom.Col - i_UserMove.SquareTo.Col) <= areaCheck)
            {
                if (this.GetSquareStatus(i_UserMove.SquareTo) == Square.eSquareType.none && squareType == i_CurrentPlayer.PlayerType &&
                    this.isDestinationValid(i_UserMove, this.GetSquareStatus(i_UserMove.SquareFrom)))
                {
                    this.UpdateBoard(i_UserMove.SquareTo.Row, i_UserMove.SquareTo.Col, this.GetSquareStatus(i_UserMove.SquareFrom), i_CurrentPlayer);
                    this.UpdateBoard(i_UserMove.SquareFrom.Row, i_UserMove.SquareFrom.Col, Square.eSquareType.none, i_CurrentPlayer);
                    i_CurrentPlayer.UpdateSquare(i_UserMove, this.m_BoardSize);

                    isUpdate = true;
                }
            }

            return(isUpdate);
        }
コード例 #2
0
        public SquareButton(Square.eSquareType i_SquareType, int i_Row, int i_Column)
        {
            this.ClientSize = new Size(k_SquareSize, k_SquareSize);
            m_Type          = i_SquareType;
            m_Row           = i_Row;
            m_Column        = i_Column;

            switch (i_SquareType)
            {
            case (Square.eSquareType.K):
                this.Text = "K";
                break;

            case (Square.eSquareType.U):
                this.Text = "U";
                break;

            case (Square.eSquareType.O):
                this.Text = "O";
                break;

            case (Square.eSquareType.X):
                this.Text = "X";
                break;

            case (Square.eSquareType.None):
                this.Text = " ";
                break;
            }
        }
コード例 #3
0
 private void OnSquareUpdate(int i_Row, int i_Col, Square.eSquareType i_SquareType)
 {
     if (this.SquareUpdate != null)
     {
         this.SquareUpdate.Invoke(i_Row, i_Col, i_SquareType);
     }
 }
コード例 #4
0
        public void AddNewPlayer(string i_PlayerName, Square.eSquareType i_PlayerType)
        {
            if (i_PlayerType == Square.eSquareType.playerOne)
            {
                this.m_PlayerOne            = new Player();
                this.m_CurrentPlayer        = this.m_PlayerOne;
                this.m_PlayerOne.Name       = i_PlayerName;
                this.m_PlayerOne.PlayerType = Square.eSquareType.playerOne;
            }
            else
            {
                this.m_PlayerTwo = new Player();
                if (i_PlayerType == Square.eSquareType.playerTwo)
                {
                    this.m_PlayerTwo.Name = i_PlayerName;
                }
                else
                {
                    this.m_PlayerTwo.IsComputer = true;
                    this.m_PlayerTwo.Name       = k_PcDeafultNameString;
                }

                this.m_PlayerTwo.PlayerType = i_PlayerType;
            }
        }
コード例 #5
0
        public Square.eSquareType GetSquareStatus(int i_Row, int i_Col)
        {
            Square.eSquareType resStatus = Square.eSquareType.invalid;

            if (this.IsPositionValid(i_Row, i_Col))
            {
                resStatus = (Square.eSquareType) this.m_BoardGame[i_Row, i_Col];
            }

            return(resStatus);
        }
コード例 #6
0
        public Square.eSquareType GetSquareStatus(Square i_Square)
        {
            Square.eSquareType resStatus = Square.eSquareType.invalid;

            if (!object.ReferenceEquals(i_Square, null))
            {
                if (this.IsPositionValid(i_Square.Row, i_Square.Col))
                {
                    resStatus = (Square.eSquareType) this.m_BoardGame[i_Square.Row, i_Square.Col];
                }
            }

            return(resStatus);
        }
コード例 #7
0
 public void endRoundScoreUpdate(Square.eSquareType i_LosingpPlayer)
 {
     if (i_LosingpPlayer == Square.eSquareType.playerOne)
     {
         this.m_PlayerTwo.Score     += this.m_PlayerTwo.BonusScore;
         this.m_PlayerTwo.BonusScore = this.m_PlayerTwo.Score;
         this.m_PlayerOne.Score      = this.m_PlayerOne.BonusScore;
     }
     else
     {
         this.m_PlayerOne.Score     += this.m_PlayerOne.BonusScore;
         this.m_PlayerOne.BonusScore = this.m_PlayerOne.Score;
         this.m_PlayerTwo.Score      = this.m_PlayerTwo.BonusScore;
     }
 }
コード例 #8
0
        public bool IsMyKing(Square.eSquareType i_SquareType)
        {
            bool isMyKingRes = false;

            if (i_SquareType == Square.eSquareType.playerOneKing && this.m_PlayerType == Square.eSquareType.playerOne)
            {
                isMyKingRes = true;
            }
            else if (i_SquareType == Square.eSquareType.playerTwoKing && (this.m_PlayerType == Square.eSquareType.playerTwo || this.m_PlayerType == Square.eSquareType.playerPC))
            {
                isMyKingRes = true;
            }

            return(isMyKingRes);
        }
コード例 #9
0
        private void endOfRoundScreen(CheckersGame i_Game, Square.eSquareType i_PlayerType, bool i_WinningPlayer, ref CheckersGame.eRoundOptions io_CurrentRound, ref string io_PreviousMove)
        {
            this.clearScreen();
            this.printEndGame(i_Game, i_PlayerType, i_WinningPlayer);

            if (!this.playerWantsAnotherRound(i_Game, i_PlayerType))
            {
                Console.WriteLine("Goodbye! :)");
                io_CurrentRound = CheckersGame.eRoundOptions.gameOver;
            }
            else
            {
                // player wants to play another game
                i_Game.CreateGameBoard(i_Game.Board.Size);
                io_PreviousMove = string.Empty;
            }
        }
コード例 #10
0
        public Square.eSquareType GetWeakPlayer()
        {
            int weakIndicator = this.m_PlayerOne.Score - this.m_PlayerTwo.Score;

            Square.eSquareType weakRes = Square.eSquareType.none;

            if (weakIndicator < 0)
            {
                weakRes = Square.eSquareType.playerOne;
            }
            else if (weakIndicator > 0)
            {
                weakRes = Square.eSquareType.playerTwo;
            }

            return(weakRes);
        }
コード例 #11
0
        public bool UpdateBoard(int i_Row, int i_Col, Square.eSquareType i_UpdateSquare, Player i_CurrentPlayer)
        {
            bool updateRes = false;

            if (this.IsPositionValid(i_Row, i_Col))
            {
                if (i_UpdateSquare == Square.eSquareType.playerOne)
                {
                    if (i_Row == 0)
                    {
                        i_CurrentPlayer.Score         += 3; // King score addition
                        this.m_BoardGame[i_Row, i_Col] = (int)Square.eSquareType.playerOneKing;
                        updateRes = true;
                    }
                    else
                    {
                        this.m_BoardGame[i_Row, i_Col] = (int)i_UpdateSquare;
                        updateRes = true;
                    }
                }
                else if (i_UpdateSquare == Square.eSquareType.playerTwo || i_UpdateSquare == Square.eSquareType.playerPC)
                {
                    if (i_Row == this.m_BoardSize - 1)
                    {
                        i_CurrentPlayer.Score         += 3; // King score addition
                        this.m_BoardGame[i_Row, i_Col] = (int)Square.eSquareType.playerTwoKing;
                        updateRes = true;
                    }
                    else
                    {
                        this.m_BoardGame[i_Row, i_Col] = (int)i_UpdateSquare;
                        updateRes = true;
                    }
                }
                else
                {
                    this.m_BoardGame[i_Row, i_Col] = (int)i_UpdateSquare;
                    updateRes = true;
                }

                this.OnSquareUpdate(i_Row, i_Col, this.GetSquareStatus(i_Row, i_Col));
            }

            return(updateRes);
        }
コード例 #12
0
        private bool isDestinationValid(Move i_UserMove, Square.eSquareType i_SquareType)
        {
            bool isValid = true;

            if (i_SquareType == Square.eSquareType.playerOne)
            {
                if (i_UserMove.SquareTo.Row - i_UserMove.SquareFrom.Row > 0)
                {
                    isValid = false;
                }
            }
            else if (i_SquareType == Square.eSquareType.playerTwo)
            {
                if (i_UserMove.SquareTo.Row - i_UserMove.SquareFrom.Row < 0)
                {
                    isValid = false;
                }
            }

            return(isValid);
        }
コード例 #13
0
        private void OnSquareUpdate(int i_Row, int i_Col, Square.eSquareType i_SquareType)
        {
            if (this.m_GameWasCreated)
            {
                string ButtonToUpdate = string.Format("{0}{1}", Convert.ToChar(i_Col + (int)'A'), Convert.ToChar(i_Row + (int)'a'));
                Button currentButton  = this.Controls[ButtonToUpdate] as Button;

                if (i_SquareType == Square.eSquareType.invalid)
                {
                    currentButton.BackgroundImage = Resource.darkBackground;
                }
                else
                {
                    currentButton.BackgroundImage = Resource.lightBackground;
                }

                if (i_SquareType == Square.eSquareType.playerOne)
                {
                    currentButton.Image = Resource.PlayerOne;
                }
                else if (i_SquareType == Square.eSquareType.playerTwo || i_SquareType == Square.eSquareType.playerPC)
                {
                    currentButton.Image = Resource.PlayerTwo;
                }
                else if (i_SquareType == Square.eSquareType.playerOneKing)
                {
                    currentButton.Image = Resource.PlayerOneKing;
                }
                else if (i_SquareType == Square.eSquareType.playerTwoKing)
                {
                    currentButton.Image = Resource.PlayerTwoKing;
                }
                else if (i_SquareType == Square.eSquareType.none)
                {
                    currentButton.Image = null;
                }
            }
        }
コード例 #14
0
        public string SquareToString(Square.eSquareType i_CurrentSquare)
        {
            string resString = string.Empty;

            if (i_CurrentSquare == Square.eSquareType.playerOne)
            {
                resString = " X ";
            }
            else if (i_CurrentSquare == Square.eSquareType.playerTwo || i_CurrentSquare == Square.eSquareType.playerPC)
            {
                resString = " O ";
            }
            else if (i_CurrentSquare == Square.eSquareType.playerOneKing)
            {
                resString = " K ";
            }
            else if (i_CurrentSquare == Square.eSquareType.playerTwoKing)
            {
                resString = " U ";
            }

            return(resString);
        }
コード例 #15
0
        public void AddNewPlayer(string i_PlayerName, Square.eSquareType playerType)
        {
            if (playerType == Square.eSquareType.playerOne)
            {
                this.m_PlayerOne            = new Player();
                this.m_PlayerOne.Name       = i_PlayerName;
                this.m_PlayerOne.PlayerType = Square.eSquareType.playerOne;
            }
            else
            {
                this.m_PlayerTwo = new Player();
                if (playerType == Square.eSquareType.playerTwo)
                {
                    this.m_PlayerTwo.Name = i_PlayerName;
                }
                else
                {
                    this.m_PlayerTwo.Name = k_PcDeafultNameString;
                }

                this.m_PlayerTwo.PlayerType = playerType;
            }
        }
コード例 #16
0
        private bool playerWantsAnotherRound(CheckersGame i_Game, Square.eSquareType i_Player)
        {
            string playerChoice;
            bool   anotherRound = false;

            Console.WriteLine("{0}Would you like to play another round? <Y/N>", Environment.NewLine);
            playerChoice = Console.ReadLine().ToUpper();

            while (playerChoice != k_YesChar && playerChoice != k_NoChar)
            {
                Console.WriteLine("Invalid input, try again. . . ");
                playerChoice = Console.ReadLine();
            }

            Console.Write(Environment.NewLine);

            if (playerChoice != k_NoChar)
            {
                anotherRound = true;
            }

            return(anotherRound);
        }
コード例 #17
0
        private void printEndGame(CheckersGame i_Game, Square.eSquareType i_PlayerType, bool i_WinningPlayer)
        {
            if (i_PlayerType != Square.eSquareType.none)
            {
                if (i_WinningPlayer)
                {
                    if (i_PlayerType == Square.eSquareType.playerOne)
                    {
                        Console.Write("{0}{1} won the game!", Environment.NewLine, i_Game.PlayerOne.Name);
                    }
                    else
                    {
                        Console.Write("{0}{1} won the game!", Environment.NewLine, i_Game.PlayerTwo.Name);
                    }
                }
                else
                {
                    if (i_PlayerType == Square.eSquareType.playerOne)
                    {
                        Console.Write("{0}{1} won the game!", Environment.NewLine, i_Game.PlayerTwo.Name);
                    }
                    else
                    {
                        Console.Write("{0}{1} won the game!", Environment.NewLine, i_Game.PlayerOne.Name);
                    }
                }
            }
            else
            {
                Console.WriteLine("Its a tie!");
            }

            Console.Write(Environment.NewLine);
            Console.WriteLine("{0}'s score is: {1}", i_Game.PlayerOne.Name, i_Game.PlayerOne.Score);
            Console.WriteLine("{0}'s score is: {1}", i_Game.PlayerTwo.Name, i_Game.PlayerTwo.Score);
        }