private void MainForm_MouseClick(object sender, MouseEventArgs e) { // if the user clicked "Edit Players" icon if (gamevisualizer.PlayersHighlight) { ChangePlayers(); } // if the user clicked "F2 - new game" else if (gamevisualizer.NewGameHighlight) { if (!game.CheckStates()) { MessageBox.Show("Please wait until the end of current game!"); return; } NewGame(); } // otherwise user perhaps clicked on some action button else if (!game.CheckGameFinished()) { try { gamecontroller.UserActions(e.Location); } catch (InvalidOperationException) { MessageBox.Show("You've not enough money to double down!"); } } }
/// <summary> /// Process the actions of a player (mouse click on HIT, STAND or DOUBLE) /// </summary> /// <param name="mousePoint"></param> public void UserActions(Point mousePoint) { // check the mouse location (over HIT, STAND or DOUBLE option) for (int i = 0; i < game.GetPlayersCount(); i++) { if (cardtable.hitrects[i].Contains(mousePoint) && game.GetPlayerState(i) != PlayerState.STAND && game.GetPlayer(i).PlayResult == PlayerResult.UNDEFINED) { MoveCardToPlayer(i); } else if (cardtable.standrects[i].Contains(mousePoint) && game.GetPlayerState(i) != PlayerState.BUST && game.GetPlayer(i).PlayResult == PlayerResult.UNDEFINED) { game.SetPlayerState(i, PlayerState.STAND); cardtable.Invalidate(); } else if (cardtable.doublerects[i].Contains(mousePoint) && game.GetPlayerState(i) != PlayerState.STAND && game.GetPlayer(i).PlayResult == PlayerResult.UNDEFINED) { game.SetPlayerState(i, PlayerState.DOUBLE); MoveCardToPlayer(i); cardtable.Invalidate(); } } // if all players (they have some of the following states: BUST, STAND or BLACKJACK) if (game.CheckStates()) { // dealer gets into play DealerHit(); } }