01 /*
02 Copyright (c) 2005 Garrett Smith
03 The MIT License
04
05 Permission is hereby granted, free of charge, to any person obtaining a copy
06 of this software and associated documentation files (the "Software"), to deal
07 in the Software without restriction, including without limitation the rights
08 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
09 copies of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
11
12 The above copyright notice and this permission notice shall be included in all
13 copies or substantial portions of the Software.
14
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 THE SOFTWARE.
22 */
23
24 // $Id: EventHandler.java.html,v 1.1 2005/06/14 06:50:55 gsmith Exp $
25
26 package garrettsmith.blackjack;
27
28 import garrettsmith.playingcards.CardList;
29
30 /**
31 * <p>
32 * Provides a callback interface for playing blackjack. The user implements this interface
33 * with logic that controls how the game should be played, then invokes
34 * {@link Blackjack#playGame(EventHandler, double)} to play a game.
35 * </p><p>
36 * See {@link garrettsmith.blackjack.refimpl.TextPlayer} for an example implementation.
37 * </p>
38 *
39 * @author Garrett Smith, gsmith at northwestern dot edu
40 * @version Blackjack v1.0, RCS $Revision: 1.1 $
41 * @since Blackjack v1.0
42 */
43 public interface EventHandler {
44
45 /**
46 * This method is invoked when an error occurs that prevents the game from
47 * completing.
48 *
49 * @param e the exception that caused the error
50 */
51 public
52 void fatalErrorOccurred( Exception e );
53
54 /**
55 * Method that is invoked when a hand is done being played. Note that if a hand
56 * is split there may be multiple hands for each game played.
57 *
58 * @param hand the hand which has completed the game
59 * @param gain the winnings from the hand; negative if the wager was lost
60 * @param result the result of the hand; see {@link Result}
61 * @param dealerCards the cards that the dealer ended the hand with
62 */
63 public
64 void handFinished( Hand hand,
65 double gain,
66 Result result,
67 CardList dealerCards );
68
69 /**
70 * Method that is optionally invoked if the player has the option of early
71 * surrender.
72 *
73 * @param hand the hand for which early surrender is being offered
74 * @return <code>true</code> if the user wishes to surrender;
75 * <code>false</code> otherwise
76 */
77 public
78 boolean offerEarlySurrender( Hand hand );
79
80 /**
81 * Method invoked when the player is offered a turn. The implementor returns
82 * the appropriate {@link Move} they wish to make.
83 *
84 * @param hand the hand for which a turn is being offered
85 * @return the {@link Move} the player whishes to make
86 */
87 public
88 Move offerRegularTurn( Hand hand );
89
90 } // interface EventHandler
|