private void performMove(ref SquareButton squareButtonChosen) { string blank, move = string.Empty; move = getMove(squareButtonChosen); if (m_GameLogic.IsValidMove(move, out blank)) { runMove(); m_GameLogic.SwitchPlayersAndCreateNewMoves(); if (m_GameLogic.IsNextPlayerTurn) { if (m_GameLogic.IsPcTurn()) { runPcTurn(ref squareButtonChosen); } else { changeTurnView(); switchSquareButtonVisibility(m_GameLogic.CurrentPlayer.IsComputer()); /*if (m_GameLogic.IsNeededToEat()) * { * MessageBox.Show(string.Format("{0}, You must eat!", m_GameLogic.CurrentPlayer.Name)); * //Todo: blue backColor when needed to eat * }*/ } } else { prepareBoardForNextEat(ref squareButtonChosen); } } checkGameOver(); }
private void SquareButton_Click(object sender, EventArgs e) { SquareButton squareButtonChosen = sender as SquareButton; if (squareButtonChosen.BackgroundImage == null) { if (squareButtonChosen.CanMoveTo(m_ButtonsMovesList)) { performMove(ref squareButtonChosen); } else { if (m_GameLogic.IsNeededToEat()) { MessageBox.Show("You must eat!", "Attention", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { MessageBox.Show("Invalid move!", "Attention", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } } else { if (squareButtonChosen.IsPressed(m_FromSquareButton)) { performWhenSquarePressed(ref squareButtonChosen); } else { performWhenSquareUnpressed(ref squareButtonChosen); } } }
private string getMove(SquareButton i_SquareButtonChosen) { return(string.Format( @"{0}{1}>{2}{3}", (char)(m_FromSquareButton.Row + 'A'), (char)(m_FromSquareButton.Col + 'a'), (char)(i_SquareButtonChosen.Row + 'A'), (char)(i_SquareButtonChosen.Col + 'a'))); }
private SquareButton createSquareButton(int i_Row, int i_Col, int i_BoardSize) { Point point = new Point(i_Row, i_Col); SquareButton squareButton = new SquareButton(point); squareButton.Size = new Size(k_SquareSize, k_SquareSize); squareButton.initializeSquareButtonDetails(i_Row, i_Col, i_BoardSize); return(squareButton); }
private void prepareBoardForNextEat(ref SquareButton i_SquareButtonChosen) { changeButtonsMoveToWhite(); m_FromSquareButton.BackColor = Color.Beige; i_SquareButtonChosen.BackColor = Color.LightBlue; m_ButtonsMovesList.Clear(); createButtonsMovesList(ref i_SquareButtonChosen, m_GameLogic.CurrentPlayer.PlayerSkippingMoves); changeButtonsMoveToBlue(); m_FromSquareButton = i_SquareButtonChosen; }
private void runAndUpdatePcMove(ref SquareButton squareButtonChosen) { squareButtonChosen = ButtonMatrix[m_GameLogic.CurrentMove.To.Col, m_GameLogic.CurrentMove.To.Row]; squareButtonChosen.Enabled = false; m_FromSquareButton.Enabled = true; m_GameLogic.CheckRewardKing(); m_GameLogic.RunMove(m_GameLogic.CurrentMove); m_ButtonsMovesList.Clear(); m_GameLogic.SwitchPlayersAndCreateNewMoves(); }
private void createButtonsMovesList(ref SquareButton i_SquareButtonChosen, List <Move> i_playerMoves) { m_ButtonsMovesList.Clear(); foreach (Move possibleMove in i_playerMoves) { if (i_SquareButtonChosen.Row == possibleMove.From.Col && i_SquareButtonChosen.Col == possibleMove.From.Row) { ButtonMatrix[possibleMove.To.Col, possibleMove.To.Row].BackColor = Color.Blue; m_ButtonsMovesList.Add(ButtonMatrix[possibleMove.To.Col, possibleMove.To.Row]); } } }
private void initializeGame() { Point point; SquareButton squareButtonChosen; Move firstPcMove = m_GameLogic.CurrentPlayer.GetPCMove((int)m_GameLogic.GameBoard.Size); point = new Point(firstPcMove.To.Col, firstPcMove.To.Row); squareButtonChosen = new SquareButton(point); switchSquareButtonVisibility(m_GameLogic.CurrentPlayer.IsComputer()); m_ButtonsMovesList = new List <SquareButton>(); if (m_GameLogic.CurrentPlayer.IsComputer()) { runPcTurn(ref squareButtonChosen); } }
private void runPcTurn(ref SquareButton squareButtonChosen) { if (!m_GameLogic.IDontHaveMoves()) { m_GameLogic.GetAndRunPcMove(); m_FromSquareButton = ButtonMatrix[m_GameLogic.CurrentMove.From.Col, m_GameLogic.CurrentMove.From.Row]; runAndUpdatePcMove(ref squareButtonChosen); while (m_GameLogic.IsPcTurn()) { m_GameLogic.GetAndRunPcMove(); m_FromSquareButton = squareButtonChosen; runAndUpdatePcMove(ref squareButtonChosen); } } }
private void initializeBoard(int i_BoardSize) { m_ButtonsMatrix = new MatrixButtons <SquareButton>(i_BoardSize, i_BoardSize); this.ClientSize = new Size((i_BoardSize * k_SquareSize) + k_MarginWidthSpace, (i_BoardSize * k_SquareSize) + panelBoard.Top + k_MarginHeightSpace); for (int row = 0; row < i_BoardSize; row++) { for (int col = 0; col < i_BoardSize; col++) { SquareButton squareButton = createSquareButton(row, col, i_BoardSize); m_ButtonsMatrix[row, col] = squareButton; squareButton.Click += SquareButton_Click; panelBoard.Controls.Add(squareButton); } } m_FromSquareButton = ButtonMatrix[1, 0]; }
private void UpdateSelectedSquareButton(ref SquareButton i_SquareButtonChosen) { changeButtonsMoveToWhite(); i_SquareButtonChosen.BackColor = Color.LightBlue; if (m_GameLogic.IsNeededToEat()) { m_ButtonsMovesList.Clear(); createButtonsMovesList(ref i_SquareButtonChosen, m_GameLogic.CurrentPlayer.PlayerSkippingMoves); changeButtonsMoveToBlue(); } else if (m_GameLogic.ThereIsRegularMoves()) { createButtonsMovesList(ref i_SquareButtonChosen, m_GameLogic.CurrentPlayer.PlayerRegularMoves); changeButtonsMoveToBlue(); } m_FromSquareButton = i_SquareButtonChosen; }
private void performWhenSquarePressed(ref SquareButton squareButtonChosen) { squareButtonChosen.BackColor = Color.Beige; changeButtonsMoveToWhite(); m_ButtonsMovesList.Clear(); }
private void performWhenSquareUnpressed(ref SquareButton squareButtonChosen) { m_FromSquareButton.BackColor = Color.Beige; UpdateSelectedSquareButton(ref squareButtonChosen); }
public bool IsPressed(SquareButton i_LastSquareButton) { return(this == i_LastSquareButton && this.BackColor == Color.LightBlue); }