コード例 #1
0
ファイル: Game.cs プロジェクト: LiorBy/Checker_Game
        private void removeChecker(PointOfPosition i_CheckerSquarePoint)
        {
            char   colorOfTheChecker = m_MatrixBoardForTesting[i_CheckerSquarePoint.Y, i_CheckerSquarePoint.X];
            string squareOfThePoint  = Position.ConvertPointToSquare(i_CheckerSquarePoint);

            if (colorOfTheChecker == (char)Checker.e_Symbol.O || colorOfTheChecker == (char)Checker.e_Symbol.U)
            {
                foreach (Checker checker in m_Player1.ListOfCheckers)
                {
                    if (checker.PositintOfTheChecker.SquareInTheBoard.Equals(squareOfThePoint))
                    {
                        m_Player1.ListOfCheckers.Remove(checker);
                        break;
                    }
                }
            }

            if (colorOfTheChecker == (char)Checker.e_Symbol.X || colorOfTheChecker == (char)Checker.e_Symbol.K)
            {
                foreach (Checker checker in m_Player2.ListOfCheckers)
                {
                    if (checker.PositintOfTheChecker.SquareInTheBoard.Equals(squareOfThePoint))
                    {
                        m_Player2.ListOfCheckers.Remove(checker);
                        break;
                    }
                }
            }

            m_MatrixBoardForTesting[i_CheckerSquarePoint.Y, i_CheckerSquarePoint.X] = '\0';
        }
コード例 #2
0
        public static PointOfPosition ConvertSqureToPoint(string i_Square)
        {
            char[]          coords = { i_Square[0], i_Square[1] };
            PointOfPosition point  = new PointOfPosition(coords[0] - 'A', coords[1] - 'a');

            return(point);
        }
コード例 #3
0
ファイル: Game.cs プロジェクト: LiorBy/Checker_Game
        private void updateTestingMatrix(string i_InputMoveFrom, string i_InputMoveTo, bool i_AttackFlag)
        {
            PointOfPosition moveFromPoint = new PointOfPosition();
            PointOfPosition moveToPoint   = new PointOfPosition();

            moveFromPoint = Position.ConvertSqureToPoint(i_InputMoveFrom);
            moveToPoint   = Position.ConvertSqureToPoint(i_InputMoveTo);
            if (m_MatrixBoardForTesting[moveFromPoint.Y, moveFromPoint.X] == (char)Checker.e_Symbol.O && moveToPoint.Y == m_BoardSize - 1)
            {
                m_MatrixBoardForTesting[moveToPoint.Y, moveToPoint.X]     = (char)Checker.e_Symbol.U;
                m_MatrixBoardForTesting[moveFromPoint.Y, moveFromPoint.X] = '\0';
            }
            else if (m_MatrixBoardForTesting[moveFromPoint.Y, moveFromPoint.X] == (char)Checker.e_Symbol.X && moveToPoint.Y == 0)
            {
                m_MatrixBoardForTesting[moveToPoint.Y, moveToPoint.X]     = (char)Checker.e_Symbol.K;
                m_MatrixBoardForTesting[moveFromPoint.Y, moveFromPoint.X] = '\0';
            }
            else
            {
                m_MatrixBoardForTesting[moveToPoint.Y, moveToPoint.X]     = m_MatrixBoardForTesting[moveFromPoint.Y, moveFromPoint.X];
                m_MatrixBoardForTesting[moveFromPoint.Y, moveFromPoint.X] = '\0';
            }

            if (i_AttackFlag)
            {
                updadeAfterAttacking(moveFromPoint, moveToPoint);
            }
        }
コード例 #4
0
        public static string ConvertPointToSquare(PointOfPosition i_Point)
        {
            char[] coords = new char[2];
            coords[0] = (char)(i_Point.X + 'A');
            coords[1] = (char)(i_Point.Y + 'a');
            string square = new string(coords);

            return(square);
        }
コード例 #5
0
ファイル: Game.cs プロジェクト: LiorBy/Checker_Game
        private void check4OptionalMoves(LinkedList <KeyValuePair <string, string> > r_MovesListOfPlayer, int i_XCoordinate, int i_YCoordinate, char i_SymbolOfChecker)
        {
            PointOfPosition checkerPoint    = new PointOfPosition(i_XCoordinate, i_YCoordinate);
            PointOfPosition leftUp          = new PointOfPosition(i_XCoordinate - 1, i_YCoordinate - 1);
            PointOfPosition rightUp         = new PointOfPosition(i_XCoordinate + 1, i_YCoordinate - 1);
            PointOfPosition leftDown        = new PointOfPosition(i_XCoordinate - 1, i_YCoordinate + 1);
            PointOfPosition rightDown       = new PointOfPosition(i_XCoordinate + 1, i_YCoordinate + 1);
            char            SymbolOfChecker = i_SymbolOfChecker;

            if (SymbolOfChecker == (char)Checker.e_Symbol.X || SymbolOfChecker == (char)Checker.e_Symbol.K ||
                SymbolOfChecker == (char)Checker.e_Symbol.U)
            {
                if ((leftUp.X >= 0 && leftUp.Y >= 0) && (leftUp.X < m_BoardSize && leftUp.Y < m_BoardSize))
                {
                    if (m_MatrixBoardForTesting[leftUp.Y, leftUp.X] == '\0')
                    {
                        KeyValuePair <string, string> tempKVP = new KeyValuePair <string, string>(Position.ConvertPointToSquare(checkerPoint), Position.ConvertPointToSquare(leftUp));
                        r_MovesListOfPlayer.AddLast(tempKVP);
                    }
                }

                if ((rightUp.X >= 0 && rightUp.Y >= 0) && (rightUp.X < m_BoardSize && rightUp.Y < m_BoardSize))
                {
                    if (m_MatrixBoardForTesting[rightUp.Y, rightUp.X] == '\0')
                    {
                        KeyValuePair <string, string> tempKVP = new KeyValuePair <string, string>(Position.ConvertPointToSquare(checkerPoint), Position.ConvertPointToSquare(rightUp));
                        r_MovesListOfPlayer.AddLast(tempKVP);
                    }
                }
            }

            if (SymbolOfChecker == (char)Checker.e_Symbol.O || SymbolOfChecker == (char)Checker.e_Symbol.K ||
                SymbolOfChecker == (char)Checker.e_Symbol.U)
            {
                if ((leftDown.X >= 0 && leftDown.Y >= 0) && (leftDown.X < m_BoardSize && leftDown.Y < m_BoardSize))
                {
                    if (m_MatrixBoardForTesting[leftDown.Y, leftDown.X] == '\0')
                    {
                        KeyValuePair <string, string> tempKVP = new KeyValuePair <string, string>(Position.ConvertPointToSquare(checkerPoint), Position.ConvertPointToSquare(leftDown));
                        r_MovesListOfPlayer.AddLast(tempKVP);
                    }
                }

                if ((rightDown.X >= 0 && rightDown.Y >= 0) && (rightDown.X < m_BoardSize && rightDown.Y < m_BoardSize))
                {
                    if (m_MatrixBoardForTesting[rightDown.Y, rightDown.X] == '\0')
                    {
                        KeyValuePair <string, string> tempKVP = new KeyValuePair <string, string>(Position.ConvertPointToSquare(checkerPoint), Position.ConvertPointToSquare(rightDown));
                        r_MovesListOfPlayer.AddLast(tempKVP);
                    }
                }
            }
        }
コード例 #6
0
ファイル: Game.cs プロジェクト: LiorBy/Checker_Game
 private void updadeAfterAttacking(PointOfPosition i_InputMoveFromPoint, PointOfPosition i_InputMoveToPoint)
 {
     if (i_InputMoveFromPoint.X + 2 == i_InputMoveToPoint.X && i_InputMoveFromPoint.Y + 2 == i_InputMoveToPoint.Y)
     { ////Down Right Attack
         removeChecker(new PointOfPosition(i_InputMoveFromPoint.X + 1, i_InputMoveFromPoint.Y + 1));
     }
     else if (i_InputMoveFromPoint.X - 2 == i_InputMoveToPoint.X && i_InputMoveFromPoint.Y + 2 == i_InputMoveToPoint.Y)
     { ////Down Left Attack
         removeChecker(new PointOfPosition(i_InputMoveFromPoint.X - 1, i_InputMoveFromPoint.Y + 1));
     }
     else if (i_InputMoveFromPoint.X - 2 == i_InputMoveToPoint.X && i_InputMoveFromPoint.Y - 2 == i_InputMoveToPoint.Y)
     { ////Up Left Attack
         removeChecker(new PointOfPosition(i_InputMoveFromPoint.X - 1, i_InputMoveFromPoint.Y - 1));
     }
     else if (i_InputMoveFromPoint.X + 2 == i_InputMoveToPoint.X && i_InputMoveFromPoint.Y - 2 == i_InputMoveToPoint.Y)
     { ////Up Right Attack
         removeChecker(new PointOfPosition(i_InputMoveFromPoint.X + 1, i_InputMoveFromPoint.Y - 1));
     }
 }
コード例 #7
0
 public void SetPosition(string i_NewSquare)
 {
     m_Coord            = ConvertSqureToPoint(i_NewSquare);
     m_SquareInTheBoard = i_NewSquare;
 }
コード例 #8
0
 public Position(string i_StartSquarePosition) /// Cto'r of Position
 {
     m_SquareInTheBoard = i_StartSquarePosition;
     m_Coord            = ConvertSqureToPoint(i_StartSquarePosition);
 }
コード例 #9
0
ファイル: Game.cs プロジェクト: LiorBy/Checker_Game
        private void check4OptionalAttacks(
            LinkedList <KeyValuePair <string, string> > r_MovesListOfPlayer,
            LinkedList <KeyValuePair <string, string> > m_AttackListOfPlayer,
            int i_XCoordinate,
            int i_YCoordinate,
            char i_SymbolOfChecker)
        {
            PointOfPosition checkerPoint         = new PointOfPosition(i_XCoordinate, i_YCoordinate);
            PointOfPosition leftUp               = new PointOfPosition(i_XCoordinate - 1, i_YCoordinate - 1);
            PointOfPosition rightUp              = new PointOfPosition(i_XCoordinate + 1, i_YCoordinate - 1);
            PointOfPosition leftDown             = new PointOfPosition(i_XCoordinate - 1, i_YCoordinate + 1);
            PointOfPosition rightDown            = new PointOfPosition(i_XCoordinate + 1, i_YCoordinate + 1);
            PointOfPosition leftUpAfterAttack    = new PointOfPosition(i_XCoordinate - 2, i_YCoordinate - 2);
            PointOfPosition rightUpAfterAttack   = new PointOfPosition(i_XCoordinate + 2, i_YCoordinate - 2);
            PointOfPosition leftDownAfterAttack  = new PointOfPosition(i_XCoordinate - 2, i_YCoordinate + 2);
            PointOfPosition rightDownAfterAttack = new PointOfPosition(i_XCoordinate + 2, i_YCoordinate + 2);
            char            SymbolOfChecker      = i_SymbolOfChecker;

            //// {X OR K} PLAYIN, OR U
            if (SymbolOfChecker == (char)Checker.e_Symbol.X || SymbolOfChecker == (char)Checker.e_Symbol.K || SymbolOfChecker == (char)Checker.e_Symbol.U)
            {
                if ((leftUpAfterAttack.X >= 0 && leftUpAfterAttack.Y >= 0) &&
                    (leftUpAfterAttack.X < m_BoardSize && leftUpAfterAttack.Y < m_BoardSize))
                {
                    castingSymbolForNotEatingFromTheSameGroup(ref SymbolOfChecker, m_MatrixBoardForTesting[leftUp.Y, leftUp.X]);
                    if (m_MatrixBoardForTesting[leftUpAfterAttack.Y, leftUpAfterAttack.X] == '\0' &&
                        m_MatrixBoardForTesting[leftUp.Y, leftUp.X] != SymbolOfChecker &&
                        m_MatrixBoardForTesting[leftUp.Y, leftUp.X] != '\0')
                    {
                        KeyValuePair <string, string> tempKVP = new KeyValuePair <string, string>(Position.ConvertPointToSquare(checkerPoint), Position.ConvertPointToSquare(leftUpAfterAttack));
                        r_MovesListOfPlayer.AddLast(tempKVP);
                        m_AttackListOfPlayer.AddLast(tempKVP);
                    }
                }

                if ((rightUpAfterAttack.X >= 0 && rightUpAfterAttack.Y >= 0) &&
                    (rightUpAfterAttack.X < m_BoardSize && rightUpAfterAttack.Y < m_BoardSize))
                {
                    castingSymbolForNotEatingFromTheSameGroup(ref SymbolOfChecker, m_MatrixBoardForTesting[rightUp.Y, rightUp.X]);
                    if (m_MatrixBoardForTesting[rightUpAfterAttack.Y, rightUpAfterAttack.X] == '\0' &&
                        m_MatrixBoardForTesting[rightUp.Y, rightUp.X] != SymbolOfChecker &&
                        m_MatrixBoardForTesting[rightUp.Y, rightUp.X] != '\0')
                    {
                        KeyValuePair <string, string> tempKVP = new KeyValuePair <string, string>(Position.ConvertPointToSquare(checkerPoint), Position.ConvertPointToSquare(rightUpAfterAttack));
                        r_MovesListOfPlayer.AddLast(tempKVP);
                        m_AttackListOfPlayer.AddLast(tempKVP);
                    }
                }
            }
            ////
            if (SymbolOfChecker == (char)Checker.e_Symbol.O || SymbolOfChecker == (char)Checker.e_Symbol.K || SymbolOfChecker == (char)Checker.e_Symbol.U)
            {
                //// castingSymbolForNotEatingFromTheSameGroup(ref SymbolOfChecker);
                if ((leftDownAfterAttack.X >= 0 && leftDownAfterAttack.Y >= 0) &&
                    (leftDownAfterAttack.X < m_BoardSize && leftDownAfterAttack.Y < m_BoardSize))
                {
                    castingSymbolForNotEatingFromTheSameGroup(ref SymbolOfChecker, m_MatrixBoardForTesting[leftDown.Y, leftDown.X]);
                    if (m_MatrixBoardForTesting[leftDownAfterAttack.Y, leftDownAfterAttack.X] == '\0' &&
                        m_MatrixBoardForTesting[leftDown.Y, leftDown.X] != SymbolOfChecker &&
                        m_MatrixBoardForTesting[leftDown.Y, leftDown.X] != '\0')
                    {
                        KeyValuePair <string, string> tempKVP = new KeyValuePair <string, string>(Position.ConvertPointToSquare(checkerPoint), Position.ConvertPointToSquare(leftDownAfterAttack));
                        r_MovesListOfPlayer.AddLast(tempKVP);
                        m_AttackListOfPlayer.AddLast(tempKVP);
                    }
                }

                if ((rightDownAfterAttack.X >= 0 && rightDownAfterAttack.Y >= 0) &&
                    (rightDownAfterAttack.X < m_BoardSize && rightDownAfterAttack.Y < m_BoardSize))
                {
                    castingSymbolForNotEatingFromTheSameGroup(ref SymbolOfChecker, m_MatrixBoardForTesting[rightDown.Y, rightDown.X]);
                    if (m_MatrixBoardForTesting[rightDownAfterAttack.Y, rightDownAfterAttack.X] == '\0' &&
                        m_MatrixBoardForTesting[rightDown.Y, rightDown.X] != SymbolOfChecker &&
                        m_MatrixBoardForTesting[rightDown.Y, rightDown.X] != '\0')
                    {
                        KeyValuePair <string, string> tempKVP = new KeyValuePair <string, string>(Position.ConvertPointToSquare(checkerPoint), Position.ConvertPointToSquare(rightDownAfterAttack));
                        r_MovesListOfPlayer.AddLast(tempKVP);
                        m_AttackListOfPlayer.AddLast(tempKVP);
                    }
                }
            }
        }