public void configureGameSettings(Board.eBoardSize i_BoardSize, eGameMode i_GameMode) { // this method is configuring the game settings m_GameBoard = new Board(i_BoardSize); m_GameMode = i_GameMode; setGameParticipants(); }
private static bool isPlayerStringValid(string i_PlayerMoveInput, Board.eBoardSize i_CurrentBoardSize) { // this method is checking if the player string is valid and return true if it is. bool isFirstCharValid, isSecondCharValid, isValidLength, result; if (i_PlayerMoveInput == "Q") { result = true; } else { isValidLength = i_PlayerMoveInput.Length == 2; if (isValidLength) { isFirstCharValid = isFirstCharIsAValidLetter(i_PlayerMoveInput[0], i_CurrentBoardSize); // first char need to be letter and in board range isSecondCharValid = isSecondCharIsAValidNumber(i_PlayerMoveInput[1], i_CurrentBoardSize); // second char need to be number and in board range result = isFirstCharValid && isSecondCharValid; } else { result = false; } } return(result); }
public FormOthello(GameLogic i_GameLogic, Board.eBoardSize i_BoardSize, GameLogic.eGameMode i_GameMode) { // formOthello c'tor m_GameLogic = i_GameLogic; InitializeComponent(); configureGameSettings(i_BoardSize, i_GameMode); createGameBoard(); Initialize(); adjustWindowSize(i_BoardSize); this.Icon = Ex05_Othello.UI.Resource1.icon; }
private static void printFirstLine(Board.eBoardSize boardSize) { // this method prints the first line if (boardSize == Board.eBoardSize.bigBoard) { Console.WriteLine(" A B C D E F G H "); } else { Console.WriteLine(" A B C D E F "); } }
private static void printLineOfEqualSign(Board.eBoardSize boardSize) { // this method prints a line of equal signs according to the board size if (boardSize == Board.eBoardSize.bigBoard) { Console.WriteLine(" ================================="); } else { Console.WriteLine(" ======================== "); } }
private void changeBoardSize() { // this method is changing the game board size in game settings. string incOrDec; int maxBoardSize, minBoardSize; maxBoardSize = (int)Board.eBoardSize.size12x12; minBoardSize = (int)Board.eBoardSize.size6x6; m_BoardSize += (int)m_BoardSize == maxBoardSize ? -(maxBoardSize - minBoardSize) : 2; incOrDec = (int)m_BoardSize == maxBoardSize ? "decrease" : "increase"; buttonBoardSize.Text = string.Format("Board size: {0}x{0} (click to {1})", (int)m_BoardSize, incOrDec); }
private void adjustWindowSize(Board.eBoardSize i_BoardSize) { // this method is adjusting the window size according to the chosen game board size int windowLength, picBoxSize, windowMargin, picBoxMargin; flowLayoutPanelBoard.Top = 10; flowLayoutPanelBoard.Left = 10; picBoxMargin = 5; picBoxSize = flowLayoutPanelBoard.Controls[0].Width; windowMargin = flowLayoutPanelBoard.Top; windowLength = (windowMargin * 2) + (picBoxSize * (int)i_BoardSize) + (((int)i_BoardSize - 1) * picBoxMargin) + ((int)i_BoardSize / 2); flowLayoutPanelBoard.Size = new Size(windowLength, windowLength); }
private static bool isFirstCharIsAValidLetter(char i_CharToValidate, Board.eBoardSize i_CurrentBoardSize) { // this method checks if the first char of the input is valid and return true if it is. bool result; if (i_CurrentBoardSize == Board.eBoardSize.bigBoard) { result = i_CharToValidate >= 'A' && i_CharToValidate <= 'H'; } else { result = i_CharToValidate >= 'A' && i_CharToValidate <= 'F'; } return(result); }
private static bool isSecondCharIsAValidNumber(char i_CharToValidate, Board.eBoardSize i_CurrentBoardSize) { // this method checks if the second char of the input is valid and return true if it is. bool result; if (i_CurrentBoardSize == Board.eBoardSize.bigBoard) { result = i_CharToValidate >= '1' && i_CharToValidate <= '8'; } else { result = i_CharToValidate >= '1' && i_CharToValidate <= '6'; } return(result); }
public void Play(Board.eBoardSize i_BoardSize, out int io_CurrentPlayerRowMove, out int io_CurrentPlayerColumnMove) { // This method ask from the player to play till his input is valid, then it return his move by ref // Example for valid move - "E3", then io_CurrentPlayerColumnMove will hold 4 and io_CurrentPlayerRowMove will hold 2 string playerMoveString; bool isUserRequsetToExit; playerMoveString = UI.RequestPlayerToPlay(m_PlayerName, m_PlayerColor, i_BoardSize); isUserRequsetToExit = playerMoveString.Length == 1; if (isUserRequsetToExit) { io_CurrentPlayerColumnMove = (int)eUserRequest.Exit; io_CurrentPlayerRowMove = (int)eUserRequest.Exit; } else { io_CurrentPlayerColumnMove = playerMoveString[0] - 'A'; io_CurrentPlayerRowMove = playerMoveString[1] - '1'; } }
public static string RequestPlayerToPlay(string i_PlayerName, GameUtilities.ePlayerColor i_PlayerTurn, Board.eBoardSize i_CurrentBoardSize) { // this method is recieving the player that should play now and asking the player to play bool isMoveValidate; string playerMoveInput, currentPlayerName, currentPlayerColor; char currentPlayerSign; currentPlayerName = i_PlayerName; if (i_PlayerTurn == GameUtilities.ePlayerColor.BlackPlayer) { currentPlayerColor = "Black"; currentPlayerSign = (char)GameUtilities.ePlayerColor.BlackPlayer; } else { currentPlayerColor = "White"; currentPlayerSign = (char)GameUtilities.ePlayerColor.WhitePlayer; } Console.WriteLine(string.Format("{0} player {1}, please play your turn => {2}.", currentPlayerColor, currentPlayerName, currentPlayerSign)); playerMoveInput = Console.ReadLine(); playerMoveInput = playerMoveInput.ToUpper(); isMoveValidate = isPlayerStringValid(playerMoveInput, i_CurrentBoardSize); while (!isMoveValidate) { ClearLines(2); SyntaxIsntValid(); playerMoveInput = Console.ReadLine(); playerMoveInput = playerMoveInput.ToUpper(); isMoveValidate = isPlayerStringValid(playerMoveInput, i_CurrentBoardSize); } return(playerMoveInput); }
private void configureGameSettings(Board.eBoardSize i_BoardSize, GameLogic.eGameMode i_GameMode) { // this method is configuring the game settings m_GameLogic.configureGameSettings(i_BoardSize, i_GameMode); m_GameLogic.Initialize(); }
private void radioButtonLargeBoard_CheckedChanged(object sender, EventArgs e) { this.m_BoardSize = Board.eBoardSize.Large; }
private void radioButtonMediumBoard_CheckedChanged(object sender, EventArgs e) { this.m_BoardSize = Board.eBoardSize.Medium; }