|
Dice Project
Start with SwingExample and rename it Proj_Dice
You are going to make a gui that looks like

The rules of our game is if they get doubles (like 1,1 or 2,2, etc), or they get a total of 7 (like 6 and 1), then they win, otherwise the lose.
The way the game proceeds:
- Where they will start with 500 and they can bet whatever they want (in the bet field).
- When they hit roll button, the result will show what they rolled.
- After it shows what they got, it says if they lost or won, the money will either go up or down the amount they bet.
EMAIL ME ANY QUESTIONS borlaj@portlandschools.org
Advanced students, have it draw the roll. This is challenging, your code will look a bit like below:
if (source==roll)
{
//all your code about rolling
Graphics g=getGraphics(); //to draw we need the graphics
//lets draw the first die
g.drawRect(45,45,60,60); //draw a square face
if (dice1==1)
g.drawOval(50,50,4,4); //draw one dot for the circle
}
Make some fields uneditable. (bmiTextField.setEditable(false);
More options, use textarea to have a running of the game.
To pause execution (like animation): Put below in your code (all of it)
try{
Thread.currentThread().sleep(1000);
}
catch(InterruptedException ie){}
Or use images for the rolls.
To do images, make sure the image is in the directory lets call it theFileName.jpg. Any where in your code, you say:
Graphics g=getGraphics();
Image img=getImage(getCodeBase(),"theFileName.jpg");
g.drawImage(img,0,0,this); //where 0,0 is the x,y you want it to appear
Sound:
|