problem in card game

edited January 2016 in Questions about Code

i want to write a card game with processing but i have a problem in distribute cards,cards when distribute may be repeat a card for two players, and I dont know how check it, please help me.

    cards[] player1=new cards[13];
    cards[] player2=new cards[13];
    int[] player1c=new int[13];
    int[] player2c=new int[13];
    int t1;
    int t2;
    int x=20;
    String check;
    void setup() {
      size(860, 650);
      for (int i=0; i<13; i++) {
        t1=(int)random(0, 51);
        player1c[i]=t1;
      }
      for (int i=0; i<13; i++) {
        t2=(int)random(0, 51);
        if(t2!=player1c[i]){
          player2c[i]=t2;
        }
      }
      for (int i=0; i<13; i++) {
        player1[i]=new cards(player1c[i],x,100,0);
        x+=20;
      }
      for (int i=0; i<13; i++) {
       player2[i]=new cards((int)random(0, 51),x,300,0);
       x+=20;
      }
    }

    void draw() {
      background(128,128,128);
       for(int i=0;i<13;i++){
        player1[i].load();
      }
      noLoop();
      for(int i=0;i<13;i++){
        player1[i].display();
      }
      loop();
         for(int i=0;i<13;i++){
        player2[i].load();
      }
      noLoop();
      for(int i=0;i<13;i++){
        player2[i].display();
      }
      loop();
    }
    void mousePressed(){
        for(int i=0;i<13;i++){
          if(mouseX>player1[i].x && mouseX < player1[i].x+20 && mouseY> player1[i].y && mouseY<player1[i].y+150){
            if(player1[i].counter==0){
            player1[i].y-=40;
            player1[i].counter=1;
            }
            else{
              player1[i].y+=40;
              player1[i].counter=0;
            }

          }
        }
      }




    class cards{
      int n;
      int tedad;
      PImage test;
      int x;
      int y;
      int counter;
      String[] cardName={"2d","3d","4d","5d","6d","7d","8d","9d","10d","ad","jd","qd","kd","2p","3p","4p","5p","6p","7p","8p","9p","10p","jp","qp","kp","ap","2kh","3kh","4kh","5kh","6kh","7kh","8kh","9kh","10kh","jkh","qkh","kkh","akh","2g","3g","4g","5g","6g","7g","8g","9g","10g","jg","qg","kg","ag"};

      cards(int n_,int x_,int y_,int counter_){
        n=n_;
        x=x_;
        y=y_;
        counter=counter_;
      }
      void load(){
          test=loadImage(cardName[n]+".png");
      }
      void display(){
        image(test,x,y);
      }

    }
Tagged:

Answers

Sign In or Register to comment.