Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Card {
- private String src;
- private int w;
- private int h;
- private int value;
- private int seed;
- private boolean hold;
- public Card(String _src, int _value, int _seed)
- {
- src = _src;
- w = 130;
- h = 200;
- x = 0;
- y = 0;
- value = _value;
- seed = _seed;
- hold = false;
- }
- public void setSrc(String _src) { src = _src; }
- public void setValue(int _value){ value = _value; }
- public void setSeed(int _seed){ seed = _seed; }
- public void setHold(boolean _hold){ hold = _hold; }
- public String getSrc() { return src; }
- public int getW() { return w; }
- public int getH() { return h; }
- public int getValue() { return value; }
- public int getSeed() { return seed; }
- public boolean getHold() { return hold; }
- };
- class Deck
- {
- private Card[] oCards = new Card[52]; //orderedCards
- private int[] sCards = new int[10]; //shuffleCards
- private int top;
- public Deck()
- {
- top = 0;
- int count = 0;
- for (int j = 4; j > 0; j--)
- for (int k = 13; k > 0; k--)
- {
- oCards[count++] = new Card("img/"+k+"_"+j+".png", k, j); //Inizializzazione dell'array con le carte in ordine
- }
- for (int i = 0; i < 10; i++)
- sCards[i] = i;
- shuffleDeck();
- }
- public void shuffleDeck()
- {
- sCards[0] = int(random(0, 51));
- for (int i = 1; i < 10; i++)
- {
- sCards[i] = int(random(0, 51));
- for (int j = 0; j < i; j++)
- {
- if (sCards[i] == sCards[j])
- i--;
- }
- }
- }
- public Card drawCard(){ return oCards[sCards[top++]]; }
- /*public void printDeck()
- {
- for (int i = 0; i < 5; i++)
- {
- card = loadImage(oCards[sCards[i]].getSrc());
- image(card, x, y, x_x, y_y);
- x+=185;
- }
- }*/
- };
- class Hand {
- private Card[] hCards = new Card[5];
- private Deck deck = new Deck();
- public Hand()
- {
- for (int i = 0; i < 5; i++)
- {
- hCards[i] = deck.drawCard();
- }
- }
- public void printHand()
- {
- for (int i = 0; i < 5; i++)
- {
- card = loadImage(hCards[i].getSrc());
- image(card, x, y, x_x, y_y);
- x+=185;
- }
- }
- public Card getCard(int index){ return hCards[index]; }
- public void redrawCard()
- {
- for(int i = 0 ; i < 5 ; i++)
- if(!(hCards[i].getHold()))
- {
- hCards[i] = deck.drawCard();
- }
- redraw();
- }
- };
- class Scoreboard {
- private int budget;
- private int bet;
- private Hand hand;
- public Scoreboard()
- {
- bet = 1;
- budget = 50;
- }
- public void setBudget(int _budget) { budget = _budget; }
- public int getBet() { return bet; }
- public int getBudget() { return budget; }
- public void changeBet(int _bet)
- {
- if( (bet + _bet) > budget )
- return;
- if(_bet == 0)
- {
- bet = budget;
- return;
- }
- bet += _bet;
- }
- };
- class Button {
- private int value;
- private int posX, posY, h, w;
- private String src;
- public Button(String _src)
- {
- src = _src;
- h = 90;
- w = 90;
- value = 1;
- posX = 30;
- posY = 590;
- }
- public void setValue(int _value) { value = _value; }
- public void setX(int _x) { posX = _x; }
- public void setY(int _y) { posY = _y; }
- public int getValue() { return value; }
- public int getPosX() { return posX; }
- public int getPosY() { return posY; }
- public String getSrc() { return src; }
- public int getH() { return h; }
- public int getW() { return w; }
- public void setBet(int v)
- {
- switch(v)
- {
- case 1:
- value = 5;
- src = "img/chips/Chip5.png";
- break;
- case 5:
- value = 10;
- src = "img/chips/Chip10.png";
- break;
- case 10:
- value = 50;
- src = "img/chips/Chip50.png";
- break;
- case 50:
- value = 0;
- src = "img/chips/ChipALL.png";
- break;
- case 0:
- value = 1;
- src = "img/chips/Chip1.png";
- break;
- }
- }
- };
- void bezierRect(float x, float y, float w, float h, float xr, float yr) {
- stroke(200);
- fill(50);
- strokeWeight(2);
- float w2=w/2f, h2=h/2f, cx=x+w2, cy=y+h2;
- beginShape();
- vertex(cx, cy-h2);
- bezierVertex(cx+w2-xr, cy-h2, cx+w2, cy-h2+yr, cx+w2, cy);
- bezierVertex(cx+w2, cy+h2-yr, cx+w2-xr, cy+h2, cx, cy+h2);
- bezierVertex(cx-w2+xr, cy+h2, cx-w2, cy+h2-yr, cx-w2, cy);
- bezierVertex(cx-w2, cy-h2+yr, cx-w2+xr, cy-h2, cx, cy-h2);
- endShape();
- }
- void mousePressed() {
- if (clickCircle(75, 635, 90)) //RED BUTTON
- {
- redB.setBet(redB.getValue());
- }
- if (clickCircle(175, 635, 90)) //ADD GREEN BUTTON
- {
- }
- if (clickCircle(275, 635, 90)) //RST BLUE BUTTON
- {
- }
- if (clickCircle(920, 635, 90)) //DONE BUTTON
- {
- }
- if (clickRect(65, height-330, 130, 200)) //FIRST CARD
- {
- print("clickFirstCard ");
- hand.getCard(0).setHold(!(hand.getCard(0).getHold()));
- if(hand.getCard(0).getHold())
- {
- hold = loadImage("img/hold/hold.png");
- image(hold, 65, height-330, 130, 200);
- print("\nhold");
- }
- else
- {
- print("\nDEhold");
- }
- }
- redraw();
- }
- boolean clickRect(int x, int y, int width, int height) {
- if (mouseX >= x && mouseX <= x+width &&
- mouseY >= y && mouseY <= y+height) {
- return true;
- } else {
- return false;
- }
- }
- boolean clickCircle(int x, int y, int diameter) {
- if (dist(mouseX, mouseY, x, y) < diameter/2) {
- return true;
- } else {
- return false;
- }
- }
- Hand hand = new Hand();
- Button redB = new Button("img/chips/Chip1.png");
- Button greenB = new Button("img/chips/ChipADD.png");
- Button blueB = new Button("img/chips/ChipRST.png");
- Button whiteB = new Button("img/chips/ChipDONE.png");
- boolean circleOver = false;
- PImage card, button, hold;
- int x, y, x_x, y_y;
- void setup()
- {
- size(1000, 700);
- background(#189300);
- x=65;
- y=height-330;
- x_x=130;
- y_y=200;
- greenB.setX(greenB.getPosX()+100);
- blueB.setX(blueB.getPosX()+200);
- whiteB.setX(width-125);
- hand.printHand();
- //initTable();
- }
- void draw()
- {
- //image(loadImage("img/table.png"), 0,0,1000,700);
- bezierRect(20, 17, (width/2)+80, (height/2)-30, -15, -15);
- ellipse(75,635,90,90);
- stroke(1);
- strokeWeight(20);
- noFill();
- rect(0, 0, 1000, 700);//Bordo
- button = loadImage(redB.getSrc());
- image(button, redB.getPosX(), redB.getPosY(), redB.getW(), redB.getH());
- button = loadImage(greenB.getSrc());
- image(button, greenB.getPosX(), greenB.getPosY(), greenB.getW(), greenB.getH());
- button = loadImage(blueB.getSrc());
- image(button, blueB.getPosX(), blueB.getPosY(), blueB.getW(), blueB.getH());
- button = loadImage(whiteB.getSrc());
- image(button, whiteB.getPosX(), whiteB.getPosY(), whiteB.getW(), whiteB.getH());
- noLoop();
- }
- /*void initTable()
- {
- int count = 0;
- for(int j = 4 ; j > 0 ; j--)
- for(int k = 13 ; k > 0 ; k--)
- cards[count++].setSrc("img/"+k+"_"+j+".png"); //Inizializzazione dell'array con le carte in ordine
- cards[52].setSrc("img/0_0.png"); //Jolly
- cards[53].setSrc("img/0_1.png"); //Jolly
- }
- void startingHand()
- {
- for(int i = 0 ; i < 5 ; i++){
- card = loadImage(cards[i]);
- image(card,x,y,x_x,y_y);
- x+=185;
- }
- }
- */
- /*ESEMPIO DI CARTE RANDOM
- void draw() {
- background(#189300);
- card = loadImage("img/"+int(random(1,13))+"_"+int(random(1,4))+".png");
- image(card,x,y,x_x,y_y);
- card = loadImage("img/"+int(random(1,13))+"_"+int(random(1,4))+".png");
- image(card,x+=170,y,x_x,y_y);
- card = loadImage("img/"+int(random(1,13))+"_"+int(random(1,4))+".png");
- image(card,x+=170,y,x_x,y_y);
- card = loadImage("img/"+int(random(1,13))+"_"+int(random(1,4))+".png");
- image(card,x+=170,y,x_x,y_y);
- card = loadImage("img/"+int(random(1,13))+"_"+int(random(1,4))+".png");
- image(card,x+=170,y,x_x,y_y);
- noLoop();
- }*/
- /*RECT RADIUS
- void setup() {
- size(200,400);
- smooth();
- }
- void draw() {
- background(255);
- fill(192);
- stroke(64);
- bezierRect(10, 10,180,80,5,5);
- bezierRect(10,110,180,80,25,25);
- bezierRect(10,210,180,80,-20,-20);QUESTO
- bezierRect(10,310,180,80,50,-30);
- }
- /**
- @param x x-coordinate of upper-left
- @param y y-coordinate of upper-left
- @param w width of the rectangle
- @param h height of the rectangle
- @param xr radius to inset x-coordinate corners for bezier controls (may be negative to "outset")
- @param yr radius to inset y-coordinate corners for bezier controls (may be negative to "outset")
- void bezierRect(float x, float y, float w, float h, float xr, float yr) {
- float w2=w/2f, h2=h/2f, cx=x+w2, cy=y+h2;
- beginShape();
- vertex(cx,cy-h2);
- bezierVertex(cx+w2-xr, cy-h2, cx+w2, cy-h2+yr, cx+w2, cy);
- bezierVertex(cx+w2, cy+h2-yr, cx+w2-xr, cy+h2, cx, cy+h2);
- bezierVertex(cx-w2+xr, cy+h2, cx-w2, cy+h2-yr, cx-w2, cy);
- bezierVertex(cx-w2, cy-h2+yr, cx-w2+xr, cy-h2, cx, cy-h2);
- endShape();
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement