Esempio n. 1
0
File: set.java Progetto: wcyuan/Set
  public void CheckSet() {
    int[] s = new int[3];
    s[0] = s[1] = s[2] = 0;
    if (num_selected < 3) return;
    for (int i = 0; i < 3; i++) {
      while (!locs[s[i]].Selected() && (s[i] < num_todraw)) {
        s[i]++;
      }
      if (i < 2) s[i + 1] = s[i] + 1;
    }
    /*
      while (!locs[s[0]].Selected() && (s[0] < num_todraw)) { s[0]++; }
      s[1] = s[0] + 1;
      while (!locs[s[1]].Selected() && (s[1] < num_todraw)) { s[1]++; }
      s[2] = s[1] + 1;
      while (!locs[s[2]].Selected() && (s[2] < num_todraw)) { s[2]++; }
    */
    if ((s[0] == s[1])
        || (s[1] == s[2])
        || (s[0] == s[2])
        || (s[0] >= num_todraw)
        || (s[1] >= num_todraw)
        || (s[2] >= num_todraw)) return;

    if (IsSet(locs[s[0]].GetImage(), locs[s[1]].GetImage(), locs[s[2]].GetImage())) {
      Message("You Found a Set!", 1);
      if ((num_todraw <= INIT_NUM_ROWS * NUM_COLS) && !c.EOD()) {
        for (int i = 0; i < 3; i++) {
          locs[s[i]].SetImage(c.NextCard());
        }
      } else {
        int temp = num_todraw;
        for (int i = 0, j = temp - 1; j > temp - 4; j--) {
          if ((j != s[0]) && (j != s[1]) && (j != s[2])) {
            locs[s[i]].SetImage(locs[j].GetImage());
            i++;
          }
          locs[j].dontdraw();
          // locs[j].draw(getGraphics(), this);
        }
      }
    } else {
      Message(
          "Not a Set!: "
              + locs[s[0]].GetImage()
              + " "
              + locs[s[1]].GetImage()
              + " "
              + locs[s[2]].GetImage(),
          1);
    }
    update(this.getGraphics());
    ClearSelected();
    update(this.getGraphics());
    deal();
    update(this.getGraphics());
  }
Esempio n. 2
0
File: set.java Progetto: wcyuan/Set
  public void deal() {
    if (c.EOD() && !SetExists() && EODtag) {
      EODtag = false;
      Message("Shuffle", 2);
      int temp = num_todraw;
      for (int i = 0; i < temp; i++) {
        locs[i].dontdraw();
      }
      c.shuffle();
    } else if (c.EOD() && !SetExists()) {
      Message("End of Deck: No More Sets", "Click Mouse to Deal Again", 2);
      EODtag = true;
      return;
    }

    while (!c.EOD() && ((num_todraw < INIT_NUM_ROWS * NUM_COLS) || (!SetExists()))) {
      int temp = num_todraw;
      locs[temp].SetImage(c.NextCard());
      locs[temp + 1].SetImage(c.NextCard());
      locs[temp + 2].SetImage(c.NextCard());
      locs[temp].dodraw();
      locs[temp + 1].dodraw();
      locs[temp + 2].dodraw();
    }

    if (c.EOD()) {
      Message("End of Deck", 2);
    }
  }
Esempio n. 3
0
File: set.java Progetto: wcyuan/Set
  public void init() {
    num_todraw = num_selected = 0;
    this.setBackground(bgcolor);
    // image = this.getImage(this.getDocumentBase(),
    // this.getParameter("image"));
    this.addMouseListener(new Listener());
    EODtag = false;

    // t.setLocation(400,0);

    for (int i = 1; i <= NUM_CARDS; i++) {
      image[i - 1] = this.getImage(this.getDocumentBase(), "pics/" + i + ".gif");
    }

    for (int i = 0; i < NUM_ROWS; i++) {
      for (int j = 0; j < NUM_COLS; j++) {
        locs[i * NUM_COLS + j] =
            new Location(
                j * (IMG_W + BORDER_SIZE * 2),
                i * (IMG_H + BORDER_SIZE * 2),
                IMG_W,
                IMG_H,
                BORDER_SIZE,
                0);
      }
    }

    for (int i = 0; i < INIT_NUM_ROWS; i++) {
      for (int j = 0; j < NUM_COLS; j++) {
        locs[i * NUM_COLS + j].SetImage(c.NextCard());
        // locs[i*NUM_COLS + j].SetImage(i*NUM_COLS+j);
        locs[i * NUM_COLS + j].dodraw();
      }
    }

    deal();
    button = new Location(400, 200, 30, 30, 0, 0);
  }