예제 #1
0
 public Cards<Card> draw(int count) {
   Cards<Card> drawn = new Cards<Card>();
   for (int i = 0; i < count; i++) {
     drawn.add(drawTop());
   }
   return drawn;
 }
예제 #2
0
 public void shuffle() {
   Cards<Card> shuffled = new Cards<Card>();
   List<Card> cards = deck.getCards();
   while (cards.size() > 0) {
     shuffled.add((Card) cards.remove(rng.nextInt(cards.size())));
   }
   deck = shuffled;
 }
예제 #3
0
 public Card drawTop() {
   if (deck.size() == 0) {
     deck = discardPile;
     discardPile = new Cards<Card>();
     shuffle();
   }
   return deck.removeFirst();
 }
예제 #4
0
파일: set.java 프로젝트: 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());
  }
예제 #5
0
파일: set.java 프로젝트: 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);
    }
  }
예제 #6
0
 Deck() {
   deck = new Cards<Card>();
   discardPile = new Cards<Card>();
   for (int i = 0; i < PRODUCTION.length; i++) {
     for (int j = 0; j < COUNT[i]; j++) {
       deck.add(
           new Card(
               NAMES[i],
               getKey(NAMES[i]),
               VICTORY_POINTS[i],
               COST[i],
               PRODUCTION[i],
               MONUMENT[i] > 0));
     }
   }
 }
예제 #7
0
파일: set.java 프로젝트: 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);
  }
예제 #8
0
 public int size() {
   return deck.size() + discardPile.size();
 }
예제 #9
0
 public void discard(Cards<Card> chosen) {
   if (chosen.contains(null)) throw new IllegalArgumentException(chosen.toString());
   discardPile.add(chosen);
 }
예제 #10
0
 public void discard(Card chosen) {
   if (chosen == null) throw new IllegalArgumentException();
   discardPile.add(chosen);
 }
예제 #11
0
 public Card find(String name) {
   return deck.remove(name);
 }