/*
* Class: DrawPoker
* Description: Java Video Poker Applet.
* Author: Frank Maritato
* Last Updated: 10/9/97
**/
import java.applet.Applet;
import java.awt.*;
import java.io.BufferedInputStream;
public class DrawPoker extends Applet {
public void init() {
setLayout(new BorderLayout());
resize(550,325);
setBackground(backgroundColor);
/** Bottom Labels **/
Panel bottom = new Panel();
bottom.setLayout(new FlowLayout(FlowLayout.LEFT));
betLabel = new java.awt.Label("Bet:");
betLabel.setForeground(Color.white);
bottom.add(betLabel);
betField = new java.awt.Label("0",Label.RIGHT);
betField.setForeground(Color.white);
bottom.add(betField);
paidLabel = new java.awt.Label("Player Paid:",Label.RIGHT);
paidLabel.setForeground(Color.white);
bottom.add(paidLabel);
paidField = new java.awt.Label("0",Label.RIGHT);
paidField.setForeground(Color.white);
bottom.add(paidField);
MoneyLabel = new java.awt.Label("Credits: ");
MoneyLabel.setForeground(Color.white);
bottom.add(MoneyLabel);
MoneyField = new java.awt.Label("0",Label.RIGHT);
MoneyField.setForeground(Color.white);
bottom.add(MoneyField);
MoneyField.setText(""+myMoney);
Panel gamepanel = new Panel();
Label gameName = new Label("Game:");
gameName.setForeground(Color.white);
gameName.setBackground(backgroundColor);
gamepanel.add(gameName);
game = new Choice();
game.setBackground(Color.black);
game.setForeground(Color.white);
game.addItem("Jacks Or Better");
game.addItem("Bonus Poker");
game.addItem("Double Bonus Poker");
game.addItem("Deuces Wild");
game.addItem("Joker Wild");
gamepanel.add(game);
bottom.add(gamepanel);
add("South", bottom);
/** East controls **/
Panel right = new Panel();
right.setLayout(new BorderLayout());
Panel east = new Panel();
east.setLayout(new GridLayout(3,1));
betButton = new java.awt.Button("Bet 1");
betButton.setForeground(Color.white);
betButton.setBackground(Color.black);
east.add(betButton);
max = new java.awt.Button("Bet Max");
max.setForeground(Color.white);
max.setBackground(Color.black);
east.add(max);
deal = new java.awt.Button("Deal");
deal.setForeground(Color.white);
deal.setBackground(Color.black);
east.add(deal);
deal.disable();
right.add("South",east);
add("East",right);
loadImages();
// Instantiate some arrays and Objects
nodds = new int[12];
codds = new String[12];
newGame("Jacks Or Better");
}
/************************************************************************/
private void loadImages() {
MediaTracker tracker = new MediaTracker(this);
Toolkit tk=Toolkit.getDefaultToolkit();
images = new Image[5][14];
for(int i=0;i<5;i++) {
for(int j=0;j<14;j++) {
if ((i == 0 && j == 0) ||
(j != 0 && i != 4) ||
(i == 4 && j == 0)) {
try{
BufferedInputStream in = new BufferedInputStream
(getClass().getResourceAsStream("images/"+i+"-"+j+".gif"));
byte[] data = new byte[100000];
in.read(data);
images[i][j] = tk.createImage(data);
tracker.addImage(images[i][j],0);
tracker.waitForAll();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
/************************************************************************/
public void update (Graphics g) {
int x,y,xlen,ylen;
y = 150;
x = 0; xlen = 500; ylen = 15;
g.setColor(backgroundColor);
if (redraw) {
g.fillRect(0,0,500,350);
redraw = false;
} else {
g.fillRect(x,y,xlen,ylen);
}
g.setColor(Color.white);
paint(g);
}
/************************************************************************/
public void paint (Graphics g) {
int
start,
xpos,
ypos,
i = 0;
boolean
done = false;
start = 10;
xpos = 15;
ypos = start;
g.setColor(Color.white);
g.drawString("Frank Maritato's Video Poker Version 2.2",xpos,ypos);
start += 20;
xpos = 15;
ypos = start;
while (codds[i] != null) {
if (i == winningIndex) {
g.setColor(Color.blue);
g.fillRect(xpos-5,ypos-12,165,15);
g.setColor(Color.yellow);
g.drawString(codds[i],xpos,ypos);
g.drawString(""+nodds[i]*myBet,xpos+130,ypos);
g.setColor(Color.white);
if (gameOver) {
myMoney += myBet*nodds[i];
paidField.setText(""+myBet*nodds[i]);
}
} else {
g.drawString(codds[i],xpos,ypos);
g.drawString(""+nodds[i]*myBet,xpos+130,ypos);
}
i++;
ypos += 15;
if (i >= (currentLength/2) && !done) {
xpos += 175;
ypos = start;
done = true;
}
}
start += 140;
xpos = 15;
ypos = start;
for (i=0;i<5;i++) {
if (newDeal) {
int a = h.hand[i].getSuit();
int b = h.hand[i].getValue();
g.drawImage(images[a-1][b],xpos,ypos,this);
if (b == 2 && currentGame.equals("Deuces Wild")) {
g.setColor(Color.blue);
g.setFont(new Font("TimesRoman",Font.BOLD,18));
g.drawString("WILD",xpos+10,ypos+50);
g.setFont(new Font ("TimesRoman",Font.PLAIN,18));
g.setColor(Color.white);
}
//System.out.println("ypos "+ypos);
if (h.hand[i].isHeld()) {
g.setFont(new Font("TimesRoman",Font.BOLD,18));
g.drawString("HELD",xpos+10,ypos-5);
g.setFont(new Font ("TimesRoman",Font.PLAIN,18));
}
} else
g.drawImage(images[0][0],xpos,ypos,this);
xpos += 85;
}
if (gameOver) {
start -= 40;
xpos = 145;
ypos = start;
Font old = g.getFont();
g.setFont(new Font("TimesRoman",Font.BOLD,24));
g.setColor(Color.yellow);
g.drawString("GAME OVER",xpos,ypos);
g.setFont(new Font ("TimesRoman",Font.PLAIN,18));
g.drawString("Play 5 coins",xpos+35,ypos+15);
g.setColor(Color.white);
g.setFont(old);
myBet = 0;
}
MoneyField.setText(""+myMoney);
}
/************************************************************************/
public boolean handleEvent(Event evt) {
if (evt.id == Event.WINDOW_DESTROY)
System.exit(0);
return super.handleEvent(evt);
}
/************************************************************************/
public boolean mouseDown (Event e, int x, int y) {
int card1Start = 15;
int card2Start = card1Start+85;
int card3Start = card2Start+85;
int card4Start = card3Start+85;
int card5Start = card4Start+85;
int
ytop,
ybot;
ytop = 165;
ybot = ytop + images[0][0].getHeight(this);
if (!gameOver) {
redraw = false;
if ( y > ytop && y < ybot) {
if (x > card1Start && x < card1Start+70) {
hold(0);
} else if ( x > card2Start && x < card2Start+70) {
hold(1);
} else if ( x > card3Start && x < card3Start+70) {
hold(2);
} else if ( x > card4Start && x < card4Start+70) {
hold(3);
} else if ( x > card5Start && x < card5Start+70) {
hold(4);
}
}
}
return true;
}
/************************************************************************/
public boolean action (Event e, Object arg) {
if (arg.equals("Bet 1")) {
placeBet(1);
} else if (arg.equals("Bet Max")) {
placeBet(5);
} else if (arg.equals("Deal")) {
dealIt();
} else if (arg.equals("Draw")) {
draw();
} else if (e.target instanceof Choice) {
newGame(""+arg);
}
return true;
}
/************************************************************************/
public void hold (int num) {
if (h.hand[num].isHeld()) {