コード例 #1
0
        private List <CellPoint> checkMove(int i_Row, int i_Col, int i_IndentRow, int i_IndentCol)
        {
            List <CellPoint> currentDiscs = new List <CellPoint>();

            Game.ePlayerId currPlayerId = m_CurrentPlayerTurn;
            int            size         = m_Othelo.GameBoard.BoardSize;

            Game.ePlayerId cellId;
            int            i = i_Row + i_IndentRow;
            int            j = i_Col + i_IndentCol;

            while (i >= 0 && i < size && j >= 0 && j < size)
            {
                cellId = m_Othelo.GameBoard.BoardCells[i, j].Owner;
                if (cellId == currPlayerId)
                {
                    return(currentDiscs);
                }
                else if (cellId == Game.ePlayerId.None)
                {
                    return(null);
                }
                else
                {
                    currentDiscs.Add(new CellPoint(i, j));
                    currentDiscs.Add(new CellPoint(i_Row, i_Col));
                }

                i += i_IndentRow;
                j += i_IndentCol;
            }

            return(null);
        }
コード例 #2
0
        private static void printLastInsruction(Game.ePlayerId i_PlayerId, string i_Instruction)
        {
            string playerName;

            BoardCell.eSigns playerSign;

            if (i_Instruction.Length != UI.k_SingleLetter)
            {
                playerName = s_Game.GetPlayerNameById(i_PlayerId);
                playerSign = BoardCell.GetSignFromPlayerId(i_PlayerId);
                UI.PrintInsruction(playerSign, playerName, i_Instruction);
            }
        }
コード例 #3
0
        public static eSigns GetSignFromPlayerId(Game.ePlayerId i_PlayerId)
        {
            eSigns sign;

            if (i_PlayerId == Game.ePlayerId.None)
            {
                sign = eSigns.Empty;
            }
            else
            {
                sign = i_PlayerId == Game.ePlayerId.Player1 ? eSigns.FirstPlayerSign : eSigns.SecondPlayerSign;
            }

            return(sign);
        }
コード例 #4
0
        public void InitializeCell(Point i_Location, Game.ePlayerId i_OwnerId)
        {
            m_OwnerId  = i_OwnerId;
            m_Sign     = GetSignFromPlayerId(i_OwnerId);
            m_Location = i_Location;
            if (m_Sign != eSigns.Empty)
            {
                if (m_Sign == eSigns.FirstPlayerSign)
                {
                    m_Direction = eDirection.Up;
                }
                else if (m_Sign == eSigns.SecondPlayerSign)
                {
                    m_Direction = eDirection.Down;
                }

                m_MovingOptions = new Dictionary <Point, Game.eMoveType>();
            }
        }
コード例 #5
0
        public void InitializeCell(int i_Row, int i_Col, Game.ePlayerId i_OwnerId)
        {
            m_OwnerId    = i_OwnerId;
            m_Sign       = GetSignFromPlayerId(i_OwnerId);
            m_Identifier = getCellIdByRowCol(i_Row, i_Col);
            if (m_Sign != eSigns.Empty)
            {
                if (m_Sign == eSigns.FirstPlayerSign)
                {
                    m_Direction = eDirection.Up;
                }
                else if (m_Sign == eSigns.SecondPlayerSign)
                {
                    m_Direction = eDirection.Down;
                }

                m_MovingOptions = new Dictionary <string, Game.eMoveType>();
            }
        }
コード例 #6
0
        public void RandInstruction(List <CellPoint> i_Moves)
        {
            Random           rnd           = new Random();
            int              length        = i_Moves.Count;
            int              rndIndex      = rnd.Next(0, length);
            List <CellPoint> cellsToUpdate = new List <CellPoint>();

            if (length > 0)
            {
                TryMove(i_Moves[rndIndex].Row, i_Moves[rndIndex].Col, out cellsToUpdate);
            }

            if (cellsToUpdate.Count > 0)
            {
                UpdateBoard(cellsToUpdate);
            }

            m_CurrentPlayerTurn = m_Othelo.Players[k_FirstPlayer].Id;
        }
コード例 #7
0
        private static Game.eMessage play(Game.ePlayerId i_PlayerId)
        {
            bool   isTurnFinished = false;
            string input          = string.Empty;
            string playerName     = s_Game.GetPlayerNameById(i_PlayerId);

            BoardCell.eSigns playerSign    = BoardCell.GetSignFromPlayerId(i_PlayerId);
            Game.eMessage    outputMessage = Game.eMessage.StartGame;

            while (!isTurnFinished)
            {
                if (i_PlayerId == Game.ePlayerId.Computer)
                {
                    Thread.Sleep(k_SleepTime);
                    input = s_Game.GetComputerInstruction();
                }
                else
                {
                    input = UI.GetInstruction(playerName, playerSign);
                }

                outputMessage  = s_Game.PlayTurn(input, i_PlayerId);
                isTurnFinished = isPlayerTurnFinished(outputMessage);
                if (outputMessage == Game.eMessage.MustJumpOverAgain)
                {
                    printUpdatedBoard();
                    printLastInsruction(i_PlayerId, input);
                    UI.PrintMessage(outputMessage);
                }
            }

            printUpdatedBoard();
            printLastInsruction(i_PlayerId, input);

            return(outputMessage);
        }
コード例 #8
0
 public static eSigns GetKingSignFromPlayerId(Game.ePlayerId i_PlayerId)
 {
     return(i_PlayerId == Game.ePlayerId.Player1 ? eSigns.FirstPlayerKingSign : eSigns.SecondPlayerKingSign);
 }
コード例 #9
0
 public Player(string i_Name, Game.ePlayerId i_PlayerId)
 {
     m_Name          = i_Name;
     m_Id            = i_PlayerId;
     m_OccupiedCells = new List <CellPoint>();
 }
コード例 #10
0
 public OtheloGame(List <Player> i_Players, int i_BoardSize)
 {
     m_Othelo            = new Game(i_Players, i_BoardSize);
     m_CurrentPlayerTurn = Game.ePlayerId.Player1;
 }
コード例 #11
0
 public Player(string i_Name, Game.ePlayerId i_PlayerSerial)
 {
     m_Name           = i_Name;
     m_Id             = i_PlayerSerial;
     m_PlayerCheckers = new List <string>();
 }