private void initializePlayer(int i_From, int i_To, ePlayerId i_PlayerId) { BoardCell.eSigns sign = BoardCell.GetSignFromPlayerId(i_PlayerId); bool needToInitialize = i_From != Board.k_FirstRow; Point currentLocation = new Point(); m_Players[(int)i_PlayerId].ChekersList.Clear(); for (int i = i_From; i < i_To; i++) { for (int j = 0; j < m_Board.BoardSize; j++) { currentLocation.X = j; currentLocation.Y = i; m_Board[currentLocation] = new BoardCell(); if (!isEmptyRow(i) && needToSetChecker(i, j)) { m_Board[currentLocation].InitializeCell(currentLocation, i_PlayerId); m_Players[(int)i_PlayerId].AddChecker(currentLocation); } else { m_Board[currentLocation].InitializeCell(currentLocation, ePlayerId.None); } } } }
public static string GetInstruction(string i_PlayerName, BoardCell.eSigns i_PlayerSign) { string instruction; string message = string.Format("{0}'s Turn ({1}): ", i_PlayerName, (char)i_PlayerSign); Console.Write(message); instruction = Console.ReadLine(); while (!isValidGameInput(instruction)) { PrintMessage(Game.eMessage.InstructionNotValid); Console.Write(message); instruction = Console.ReadLine(); } return(instruction); }
private void initializePlayer(int i_From, int i_To, ePlayerId i_PlayerId) { BoardCell.eSigns sign = BoardCell.GetSignFromPlayerId(i_PlayerId); bool needToInitialize = i_From != Board.k_FirstRow; m_Players[(int)i_PlayerId].ChekersList.Clear(); for (int i = i_From; i < i_To; i++) { for (int j = 0; j < m_Board.BoardSize; j++) { m_Board[i, j] = new BoardCell(); if (!isEmptyRow(i) && needToSetChecker(i, j)) { m_Board[i, j].InitializeCell(i, j, i_PlayerId); m_Players[(int)i_PlayerId].AddChecker(m_Board[i, j].Id); } else { m_Board[i, j].InitializeCell(i, j, ePlayerId.None); } } } }
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); }
public static void PrintInsruction(BoardCell.eSigns i_PlayerSign, string i_PlayerName, string i_Instruction) { string message = string.Format("{0}'s move was ({1}): {2}", i_PlayerName, (char)i_PlayerSign, i_Instruction); Console.WriteLine(message); }