⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 drawpoker.java

📁 爬虫程序的实现
💻 JAVA
字号:
/*
 * 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()) {
      h.hand[num].setHeld(false);
    } else {
      h.hand[num].setHeld(true);
    }
    repaint();
  }
  
  /************************************************************************/
  public void dealIt() {

    if (currentGame.equals("Joker Wild"))
      d = new CardDeck(1, true);
    else
      d = new CardDeck(1, false);
    
    h = new Hand(d.draw(), currentGame);
    for (int i=1;i<5;i++)
      h.Insert(d.draw());
    
    newDeal = true;
    paidField.setText("0");
    deal.setLabel("Draw");
    betButton.disable();
    max.disable();
    winningIndex = h.checkHand();
    redraw = true;
    repaint();
  }
  
  /************************************************************************/
  public void draw () {
    for(int i=0;i<5;i++) {
      if (!h.hand[i].isHeld()) {
	h.Delete(i);
	h.hand[i] = d.draw();
      }
    }
    resetIt();
    winningIndex = h.checkHand();
    gameOver = true;
    deal.disable();
    redraw = true;
    repaint();
  }
  
  /************************************************************************/
  public void resetIt() {
    deal.setLabel("Deal");
    betButton.enable();
    max.enable();
    game.enable();
    betField.setText(""+myBet);
  }

  /************************************************************************/
  public void placeBet(int n) {
    int
      thisbet = 0;

    if (n == 5) {
      thisbet = (5 - myBet);
      myBet = 5;
    } else {
      thisbet = 1;
      myBet++;
    }

    newDeal = false;
    betField.setText(""+myBet);
    deal.enable();
    myMoney -= thisbet;
    winningIndex = 11;

    if (myBet == 5) {
      betButton.disable();
      max.disable();
      dealIt();
    }

    game.disable();
    gameOver = false;
    redraw = true;
    repaint();
  }
  
  /************************************************************************/
  public void newGame (String arg) {
    newDeal = false;
    winningIndex = 11;
    currentGame = arg;
    codds[0] = "Royal Flush";
    nodds[0] = 800;
    if (arg.equals("Jacks Or Better")) {
      codds[1] = "Straight Flush";
      codds[2] = "4 of a Kind";
      codds[3] = "Full House";
      codds[4] = "Flush";
      codds[5] = "Straight";
      codds[6] = "3 of a Kind";
      codds[7] = "2 Pair";
      codds[8] = "Jacks or Better";
      codds[9] = null;
      codds[10]= null;
      currentLength = 9;
      nodds[1] = 50;
      nodds[2] = 25;
      nodds[3] = 8;
      nodds[4] = 5;
      nodds[5] = 4;
      nodds[6] = 3;
      nodds[7] = 2;
      nodds[8] = 1;
    } else if (arg.equals("Bonus Poker")) {
      codds[1]  = "Straight Flush";
      codds[2]  = "4 Aces";
      codds[3]  = "4 2's, 3's, 4's";
      codds[4]  = "4 5's - K's";
      codds[5]  = "Full House";
      codds[6]  = "Flush";
      codds[7]  = "Straight";
      codds[8]  = "3 of a Kind";
      codds[9]  = "2 Pair";
      codds[10] = "Jacks or Better";
      currentLength = 11;
      nodds[1]  = 50;
      nodds[2]  = 80;
      nodds[3]  = 40;
      nodds[4]  = 25;
      nodds[5]  = 8;
      nodds[6]  = 5;
      nodds[7]  = 4;
      nodds[8]  = 3;
      nodds[9]  = 2;
      nodds[10] = 1;
    } else if (arg.equals("Double Bonus Poker")) {
      codds[1]  = "Straight Flush";
      codds[2]  = "4 Aces";
      codds[3]  = "4 2's, 3's, 4's";
      codds[4]  = "4 5's - K's";
      codds[5]  = "Full House";
      codds[6]  = "Flush";
      codds[7]  = "Straight";
      codds[8]  = "3 of a Kind";
      codds[9]  = "2 Pair";
      codds[10] = "Jacks or Better";
      currentLength = 11;
      nodds[1]  = 50;
      nodds[2]  = 160;
      nodds[3]  = 80;
      nodds[4]  = 50;
      nodds[5]  = 10;
      nodds[6]  = 7;
      nodds[7]  = 5;
      nodds[8]  = 3;
      nodds[9]  = 1;
      nodds[10] = 1;
    } else if (arg.equals("Deuces Wild")) {
      codds[1]  = "4 Deuces";
      codds[2]  = "Royal Flush w/2's";
      codds[3]  = "5 of a Kind";
      codds[4]  = "Straight Flush";
      codds[5]  = "4 of a Kind";
      codds[6]  = "Full House";
      codds[7]  = "Flush";
      codds[8]  = "Straight";
      codds[9]  = "3 of a Kind";
      codds[10] = null;
      currentLength = 10;
      nodds[1]  = 200;
      nodds[2]  = 50;
      nodds[3]  = 16;
      nodds[4]  = 13;
      nodds[5]  = 4;
      nodds[6]  = 4;
      nodds[7]  = 3;
      nodds[8]  = 2;
      nodds[9]  = 1;
    } else if (arg.equals("Joker Wild")) {
      codds[1]  = "Royal Flush w/Joker";
      codds[2]  = "5 of a Kind";
      codds[3]  = "Straight Flush";
      codds[4]  = "4 of a Kind";
      codds[5]  = "Full House";
      codds[6]  = "Flush";
      codds[7]  = "Straight";
      codds[8]  = "3 of a Kind";
      codds[9]  = "2 Pair";
      codds[10] = "Kings or Better";
      currentLength = 11;
      nodds[1]  = 100;
      nodds[2]  = 200;
      nodds[3]  = 50;
      nodds[4]  = 15;
      nodds[5]  = 6;
      nodds[6]  = 4;
      nodds[7]  = 3;
      nodds[8]  = 2;
      nodds[9]  = 1;
      nodds[10] = 1;
    }
    redraw = true;
    repaint();
  }
  
  // ** Variables **
  Image
    images[][];
  
  int
    myBet        = 0,
    myMoney      = 100,
    winningIndex = 11,
    nodds[],
    currentLength;

  String      
    codds[], 
    currentGame;
  
  static String 
    OSNAME = "";

  CardDeck    
    d;

  Hand        
    h;

  boolean
    newDeal = false,
    gameOver= true,
    redraw=true;
  
  Color 
    backgroundColor = new Color(0,100,0);
  
  //{{DECLARE_CONTROLS
  java.awt.Button deal;
  java.awt.Label label1;
  java.awt.Label betLabel;
  java.awt.Button max;
  java.awt.Button betButton;
  java.awt.Label MoneyField;
  java.awt.Label MoneyLabel;
  java.awt.Label betField;
  java.awt.Label paidLabel;
  java.awt.Label paidField;
  Choice game;
  //}}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -