Advertisement
Gilgamesh858

VideoPoker.pde

Oct 26th, 2015
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.83 KB | None | 0 0
  1.  
  2. class Card {
  3.   private String src;
  4.   private int w;
  5.   private int h;
  6.   private int value;
  7.   private int seed;
  8.   private boolean hold;
  9.  
  10.   public Card(String _src, int _value, int _seed)
  11.   {
  12.     src = _src;
  13.     w = 130;
  14.     h = 200;
  15.     x = 0;
  16.     y = 0;
  17.     value = _value;
  18.     seed = _seed;
  19.     hold = false;
  20.   }
  21.  
  22.   public void setSrc(String _src) { src = _src; }
  23.   public void setValue(int _value){ value = _value; }
  24.   public void setSeed(int _seed){ seed = _seed; }
  25.   public void setHold(boolean _hold){ hold = _hold; }
  26.  
  27.   public String getSrc() { return src; }
  28.   public int getW() { return w; }
  29.   public int getH() { return h; }
  30.   public int getValue() { return value; }
  31.   public int getSeed() { return seed; }
  32.   public boolean getHold() { return hold; }
  33. };
  34.  
  35. class Deck
  36. {
  37.   private Card[] oCards = new Card[52]; //orderedCards
  38.   private int[] sCards = new int[10]; //shuffleCards
  39.   private int top;
  40.  
  41.   public Deck()
  42.   {
  43.     top = 0;
  44.     int count = 0;
  45.     for (int j = 4; j > 0; j--)
  46.       for (int k = 13; k > 0; k--)
  47.       {
  48.         oCards[count++] = new Card("img/"+k+"_"+j+".png", k, j); //Inizializzazione dell'array con le carte in ordine
  49.       }
  50.     for (int i = 0; i < 10; i++)
  51.       sCards[i] = i;
  52.     shuffleDeck();
  53.   }
  54.  
  55.   public void shuffleDeck()
  56.   {
  57.     sCards[0] = int(random(0, 51));
  58.  
  59.     for (int i = 1; i < 10; i++)
  60.     {
  61.       sCards[i] = int(random(0, 51));
  62.       for (int j = 0; j < i; j++)
  63.       {
  64.         if (sCards[i] == sCards[j])
  65.           i--;
  66.       }
  67.     }
  68.   }
  69.  
  70.   public Card drawCard(){ return oCards[sCards[top++]]; }
  71.  
  72.   /*public void printDeck()
  73.   {
  74.     for (int i = 0; i < 5; i++)
  75.     {
  76.       card = loadImage(oCards[sCards[i]].getSrc());
  77.       image(card, x, y, x_x, y_y);
  78.       x+=185;
  79.     }
  80.   }*/
  81. };
  82.  
  83. class Hand {
  84.   private Card[] hCards = new Card[5];
  85.   private Deck deck = new Deck();
  86.  
  87.   public Hand()
  88.   {
  89.     for (int i = 0; i < 5; i++)
  90.     {
  91.       hCards[i] = deck.drawCard();
  92.     }
  93.   }
  94.  
  95.   public void printHand()
  96.   {
  97.     for (int i = 0; i < 5; i++)
  98.     {
  99.       card = loadImage(hCards[i].getSrc());
  100.       image(card, x, y, x_x, y_y);
  101.       x+=185;
  102.     }
  103.   }
  104.  
  105.   public Card getCard(int index){ return hCards[index]; }
  106.  
  107.   public void redrawCard()
  108.   {
  109.     for(int i = 0 ; i < 5 ; i++)
  110.       if(!(hCards[i].getHold()))
  111.       {
  112.         hCards[i] = deck.drawCard();
  113.       }
  114.     redraw();
  115.   }
  116. };
  117.  
  118. class Scoreboard {
  119.   private int budget;
  120.   private int bet;
  121.   private Hand hand;
  122.  
  123.   public Scoreboard()
  124.   {
  125.     bet = 1;
  126.     budget = 50;
  127.   }
  128.  
  129.   public void setBudget(int _budget) { budget = _budget; }
  130.   public int getBet() { return bet; }
  131.   public int getBudget() { return budget; }
  132.  
  133.   public void changeBet(int _bet)
  134.   {
  135.     if( (bet + _bet) > budget )
  136.       return;
  137.    
  138.     if(_bet == 0)
  139.     {
  140.       bet = budget;
  141.       return;
  142.     }
  143.     bet += _bet;
  144.   }
  145. };
  146.  
  147. class Button {
  148.   private int value;
  149.   private int posX, posY, h, w;
  150.   private String src;
  151.  
  152.   public Button(String _src)
  153.   {  
  154.     src = _src;
  155.     h = 90;
  156.     w = 90;
  157.     value = 1;
  158.     posX = 30;
  159.     posY = 590;
  160.   }
  161.  
  162.   public void setValue(int _value) { value = _value; }
  163.   public void setX(int _x) { posX = _x; }
  164.   public void setY(int _y) { posY = _y; }
  165.   public int getValue() { return value; }
  166.   public int getPosX() { return posX; }
  167.   public int getPosY() { return posY; }
  168.   public String getSrc() { return src; }
  169.   public int getH() { return h; }
  170.   public int getW() { return w; }
  171.  
  172.   public void setBet(int v)
  173.   {
  174.     switch(v)
  175.     {
  176.     case 1:
  177.       value = 5;
  178.       src = "img/chips/Chip5.png";
  179.       break;
  180.  
  181.     case 5:
  182.       value = 10;
  183.       src = "img/chips/Chip10.png";
  184.       break;
  185.  
  186.     case 10:
  187.       value = 50;
  188.       src = "img/chips/Chip50.png";
  189.       break;
  190.  
  191.     case 50:
  192.       value = 0;
  193.       src = "img/chips/ChipALL.png";
  194.       break;
  195.  
  196.     case 0:
  197.       value = 1;
  198.       src = "img/chips/Chip1.png";
  199.       break;
  200.     }
  201.   }
  202. };
  203.  
  204. void bezierRect(float x, float y, float w, float h, float xr, float yr) {
  205.   stroke(200);
  206.   fill(50);
  207.   strokeWeight(2);
  208.   float w2=w/2f, h2=h/2f, cx=x+w2, cy=y+h2;
  209.   beginShape();
  210.   vertex(cx, cy-h2);
  211.   bezierVertex(cx+w2-xr, cy-h2, cx+w2, cy-h2+yr, cx+w2, cy);
  212.   bezierVertex(cx+w2, cy+h2-yr, cx+w2-xr, cy+h2, cx, cy+h2);
  213.   bezierVertex(cx-w2+xr, cy+h2, cx-w2, cy+h2-yr, cx-w2, cy);
  214.   bezierVertex(cx-w2, cy-h2+yr, cx-w2+xr, cy-h2, cx, cy-h2);
  215.   endShape();
  216. }
  217.  
  218. void mousePressed() {
  219.   if (clickCircle(75, 635, 90)) //RED BUTTON
  220.   {
  221.     redB.setBet(redB.getValue());
  222.   }
  223.   if (clickCircle(175, 635, 90)) //ADD GREEN BUTTON
  224.   {
  225.    
  226.   }
  227.   if (clickCircle(275, 635, 90)) //RST BLUE BUTTON
  228.   {
  229.    
  230.   }
  231.   if (clickCircle(920, 635, 90)) //DONE BUTTON
  232.   {
  233.    
  234.   }
  235.   if (clickRect(65, height-330, 130, 200)) //FIRST CARD
  236.   {
  237.     print("clickFirstCard ");
  238.     hand.getCard(0).setHold(!(hand.getCard(0).getHold()));
  239.     if(hand.getCard(0).getHold())
  240.     {
  241.       hold = loadImage("img/hold/hold.png");
  242.       image(hold, 65, height-330, 130, 200);
  243.       print("\nhold");
  244.     }
  245.     else
  246.     {
  247.       print("\nDEhold");
  248.     }
  249.   }
  250.  
  251.   redraw();
  252. }
  253.  
  254.  
  255. boolean clickRect(int x, int y, int width, int height) {
  256.   if (mouseX >= x && mouseX <= x+width &&
  257.     mouseY >= y && mouseY <= y+height) {
  258.     return true;
  259.   } else {
  260.     return false;
  261.   }
  262. }
  263.  
  264. boolean clickCircle(int x, int y, int diameter) {
  265.   if (dist(mouseX, mouseY, x, y) < diameter/2) {
  266.     return true;
  267.   } else {
  268.     return false;
  269.   }
  270. }
  271.  
  272. Hand hand = new Hand();
  273. Button redB = new Button("img/chips/Chip1.png");
  274. Button greenB = new Button("img/chips/ChipADD.png");
  275. Button blueB = new Button("img/chips/ChipRST.png");
  276. Button whiteB = new Button("img/chips/ChipDONE.png");
  277. boolean circleOver = false;
  278. PImage card, button, hold;
  279. int x, y, x_x, y_y;
  280.  
  281. void setup()
  282. {
  283.   size(1000, 700);
  284.   background(#189300);
  285.   x=65;
  286.   y=height-330;
  287.   x_x=130;
  288.   y_y=200;
  289.   greenB.setX(greenB.getPosX()+100);
  290.   blueB.setX(blueB.getPosX()+200);
  291.   whiteB.setX(width-125);
  292.   hand.printHand();
  293.   //initTable();
  294. }
  295. void draw()
  296. {
  297.   //image(loadImage("img/table.png"), 0,0,1000,700);
  298.   bezierRect(20, 17, (width/2)+80, (height/2)-30, -15, -15);
  299.   ellipse(75,635,90,90);
  300.   stroke(1);
  301.   strokeWeight(20);
  302.   noFill();
  303.   rect(0, 0, 1000, 700);//Bordo
  304.   button = loadImage(redB.getSrc());
  305.   image(button, redB.getPosX(), redB.getPosY(), redB.getW(), redB.getH());
  306.   button = loadImage(greenB.getSrc());
  307.   image(button, greenB.getPosX(), greenB.getPosY(), greenB.getW(), greenB.getH());
  308.   button = loadImage(blueB.getSrc());
  309.   image(button, blueB.getPosX(), blueB.getPosY(), blueB.getW(), blueB.getH());
  310.   button = loadImage(whiteB.getSrc());
  311.   image(button, whiteB.getPosX(), whiteB.getPosY(), whiteB.getW(), whiteB.getH());
  312.  
  313.   noLoop();
  314. }
  315.  
  316. /*void initTable()
  317.  {
  318.  int count = 0;
  319.  for(int j = 4 ; j > 0 ; j--)
  320.  for(int k = 13 ; k > 0 ; k--)
  321.  cards[count++].setSrc("img/"+k+"_"+j+".png"); //Inizializzazione dell'array con le carte in ordine
  322.  cards[52].setSrc("img/0_0.png"); //Jolly
  323.  cards[53].setSrc("img/0_1.png"); //Jolly
  324.  }
  325.  
  326.  
  327.  void startingHand()
  328.  {
  329.  for(int i = 0 ; i < 5 ; i++){
  330.  card = loadImage(cards[i]);
  331.  image(card,x,y,x_x,y_y);
  332.  x+=185;
  333.  }
  334.  }
  335.  
  336.  */
  337.  
  338.  
  339. /*ESEMPIO DI CARTE RANDOM
  340.  void draw() {
  341.  background(#189300);
  342.  card = loadImage("img/"+int(random(1,13))+"_"+int(random(1,4))+".png");
  343.  image(card,x,y,x_x,y_y);
  344.  card = loadImage("img/"+int(random(1,13))+"_"+int(random(1,4))+".png");
  345.  image(card,x+=170,y,x_x,y_y);
  346.  card = loadImage("img/"+int(random(1,13))+"_"+int(random(1,4))+".png");
  347.  image(card,x+=170,y,x_x,y_y);
  348.  card = loadImage("img/"+int(random(1,13))+"_"+int(random(1,4))+".png");
  349.  image(card,x+=170,y,x_x,y_y);
  350.  card = loadImage("img/"+int(random(1,13))+"_"+int(random(1,4))+".png");
  351.  image(card,x+=170,y,x_x,y_y);
  352.  noLoop();
  353.  }*/
  354.  
  355.  
  356. /*RECT RADIUS
  357.  void setup() {
  358.  size(200,400);
  359.  smooth();
  360.  }
  361.  
  362.  void draw() {
  363.  background(255);
  364.  fill(192);
  365.  stroke(64);
  366.  bezierRect(10, 10,180,80,5,5);
  367.  bezierRect(10,110,180,80,25,25);
  368.  bezierRect(10,210,180,80,-20,-20);QUESTO
  369.  bezierRect(10,310,180,80,50,-30);
  370.  }
  371.  
  372. /**
  373.  @param x  x-coordinate of upper-left
  374.  @param y  y-coordinate of upper-left
  375.  @param w  width of the rectangle
  376.  @param h  height of the rectangle
  377.  @param xr radius to inset x-coordinate corners for bezier controls (may be negative to "outset")
  378.  @param yr radius to inset y-coordinate corners for bezier controls (may be negative to "outset")
  379.  
  380.  void bezierRect(float x, float y, float w, float h, float xr, float yr) {
  381.  float w2=w/2f, h2=h/2f, cx=x+w2, cy=y+h2;
  382.  beginShape();
  383.  vertex(cx,cy-h2);
  384.  bezierVertex(cx+w2-xr, cy-h2, cx+w2, cy-h2+yr, cx+w2, cy);
  385.  bezierVertex(cx+w2, cy+h2-yr, cx+w2-xr, cy+h2, cx, cy+h2);
  386.  bezierVertex(cx-w2+xr, cy+h2, cx-w2, cy+h2-yr, cx-w2, cy);
  387.  bezierVertex(cx-w2, cy-h2+yr, cx-w2+xr, cy-h2, cx, cy-h2);
  388.  endShape();
  389.  }
  390.  */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement