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:


Constructor Index

 o LetsMakeADealApplet()

Method Index

 o action(Event, Object)
Deal with all other interface interaction (except doors)
 o autoPlay()
Plays the game automatically
 o chooseFirstDoor(int)
Marks given door as selected.
 o clearEverything()
Clears all counters and resets game
 o gameLogic(int)
Decides what to do when the player selects a door.
 o imageCanvasEvent(ImageCanvas)
This method is a callback that's called when the player clicks a door.
 o init()
Reads parameters from APPLET tag, loads images, lays out components, initializes game.
 o initGame()
Initializes game.
 o paint(Graphics)
 o updateStats()
Updates all statistics
 o updateStayLose()
 o updateStayWin()
 o updateSwitchLose()
 o updateSwitchWin()

Constructors

 o LetsMakeADealApplet
 public LetsMakeADealApplet()

Methods

 o init
 public void init()
Reads parameters from APPLET tag, loads images, lays out components, initializes game.

Overrides:
init in class Applet
 o paint
 public void paint(Graphics g)
Overrides:
paint in class Container
 o initGame
 public void initGame()
Initializes game. Chooses a door to hide prize behind, resets everthing else.

 o updateStayWin
 public void updateStayWin()
 o updateStayLose
 public void updateStayLose()
 o updateSwitchWin
 public void updateSwitchWin()
 o updateSwitchLose
 public void updateSwitchLose()
 o updateStats
 public void updateStats()
Updates all statistics

 o clearEverything
 public void clearEverything()
Clears all counters and resets game

 o 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
 o gameLogic
 public void gameLogic(int door)
Decides what to do when the player selects a door.

Parameters:
door - player's selected door
 o autoPlay
 public void autoPlay()
Plays the game automatically

 o 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
 o action
 public boolean action(Event event,
                       Object arg)
Deal with all other interface interaction (except doors)

Overrides:
action in class Component