Class LetsMakeADealApplet
java.lang.Object
|
+----java.awt.Component
|
+----java.awt.Container
|
+----java.awt.Panel
|
+----java.applet.Applet
|
+----LetsMakeADealApplet
- public class LetsMakeADealApplet
- extends Applet
- implements ImageCanvasEventHandler
This is a simple applet that lets someone play the classic three door
game from Let's Make a Deal. A prize is hidden behind one door. The
player chooses one by clicking on it. Another door is then revealed
to hold a booby prize. The player can then choose to keep either what's
behind the door she selected or the other unopened door.
This applet keeps track of the win & loss statistics for the two
strategies of play (stay with selected door/switch to other door). It
also has autoplay capability, so you can quickly see how the resulting
statistics.
There are three parameters that can be set in the APPLET tag:
- doors - number of doors (at least 3)
- autoplayGames - number of games played when player
clicks the autoplay button
- resetValue - maximum number of games played before
statistics are reset
-
LetsMakeADealApplet()
-
-
action(Event, Object)
- Deal with all other interface interaction (except doors)
-
autoPlay()
- Plays the game automatically
-
chooseFirstDoor(int)
- Marks given door as selected.
-
clearEverything()
- Clears all counters and resets game
-
gameLogic(int)
- Decides what to do when the player selects a door.
-
imageCanvasEvent(ImageCanvas)
- This method is a callback that's called when the player
clicks a door.
-
init()
- Reads parameters from APPLET tag, loads images, lays out components,
initializes game.
-
initGame()
- Initializes game.
-
paint(Graphics)
-
-
updateStats()
- Updates all statistics
-
updateStayLose()
-
-
updateStayWin()
-
-
updateSwitchLose()
-
-
updateSwitchWin()
-
LetsMakeADealApplet
public LetsMakeADealApplet()
init
public void init()
- Reads parameters from APPLET tag, loads images, lays out components,
initializes game.
- Overrides:
- init in class Applet
paint
public void paint(Graphics g)
- Overrides:
- paint in class Container
initGame
public void initGame()
- Initializes game. Chooses a door to hide prize behind, resets
everthing else.
updateStayWin
public void updateStayWin()
updateStayLose
public void updateStayLose()
updateSwitchWin
public void updateSwitchWin()
updateSwitchLose
public void updateSwitchLose()
updateStats
public void updateStats()
- Updates all statistics
clearEverything
public void clearEverything()
- Clears all counters and resets game
chooseFirstDoor
public void chooseFirstDoor(int door)
- Marks given door as selected. Reveals what's behind bad door(s).
- Parameters:
- door - player's intially selected door
gameLogic
public void gameLogic(int door)
- Decides what to do when the player selects a door.
- Parameters:
- door - player's selected door
autoPlay
public void autoPlay()
- Plays the game automatically
imageCanvasEvent
public void imageCanvasEvent(ImageCanvas source)
- This method is a callback that's called when the player
clicks a door. It determines which door was clicked,
then passes that information to
gameLogic
.
I know, it breaks encapsulation. So sue me.
- Parameters:
- source - door that was clicked
action
public boolean action(Event event,
Object arg)
- Deal with all other interface interaction (except doors)
- Overrides:
- action in class Component