⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 card.java

📁 一些JAVA的小程序
💻 JAVA
字号:
// CS 582 - Fall 1996 - OSU// Jean-Guy Spetonimport java.awt.*;public class Card{  // Number of cards in a complete deck.  Specifically, one for each  // country plus 2 wild cards.  public static int NUM_CARDS;  // Designs and countries of each card.  private static int designs[];  private static int countries[];    public final static int ARTILLERY = 0;  public final static int CAVALRY   = 1;  public final static int INFANTY   = 2;  public final static int WILD      = 3;  private static String designNames[] = {    "Artillery", "Cavalry", "Infantry", "*Wild*"  };  private static String countryNames[];    // Static initializer.  static  {    NUM_CARDS = Country.NUM_COUNTRIES + 2;    designs = new int[NUM_CARDS];    countries = new int[NUM_CARDS];    countryNames = new String[NUM_CARDS];    for (int i = 0; i < Country.NUM_COUNTRIES; i++) {      designs[i] = i % 3;      countries[i] = i;      countryNames[i] = Country.getName(i);    }    // Wild cards won't have country names.    designs[NUM_CARDS - 2] = designs[NUM_CARDS - 1] = WILD;    countries[NUM_CARDS - 2] = NUM_CARDS - 2;    countries[NUM_CARDS - 1] = NUM_CARDS - 1;    countryNames[NUM_CARDS - 2] = countryNames[NUM_CARDS - 1] = "";  }  // Determines if a card set is a tradeable set.  public static boolean isSet(Card c1, Card c2, Card c3)  {    int numWilds = 0, numMissing = 3;    // Count number of wild cards.    if (c1.design == WILD) { numWilds++; }    if (c2.design == WILD) { numWilds++; }    if (c3.design == WILD) { numWilds++; }    // Trivial case first -- all designs the same.    if ((c1.design == c2.design) && (c2.design == c3.design)) {      return true;    }    // Another trivial case -- 2 wild cards.    if (numWilds == 2) {      return true;    }    // Determine which designs there are.    for (int i = 0; i < 3; i++) {      if ((c1.design == i) || (c2.design == i) || (c3.design == i)) {	numMissing--;      }    }    if (((numMissing - numWilds) == 0) ||          // 3 different designs	((numMissing == 2) && (numWilds == 1))) {  // same design w/ wild      return true;    }    return false;  }      private int design;  private int country;  private boolean selected;  public Card(int i)  {    this(designs[i], countries[i]);  }    public Card(int design, int country)  {    this.design = design;    this.country = country;    selected = false;  }  public int getDesign()  {    return design;  }  public int getCountry()  {    return country;  }  public boolean isSelected()  {    return selected;  }    public void toggleSelected()  {    selected = !selected;  }  public void paint(Graphics g, int x, int y, int w, int h)  {    FontMetrics fm = g.getFontMetrics();    int designWidth = fm.stringWidth(designNames[design]);    int countryWidth = fm.stringWidth(countryNames[country]);    int stringHeight = fm.getHeight();        if (selected) {      g.setColor(Color.black);      g.fillRect(x+2, y, w-4, h);      g.setColor(Color.white);      g.drawLine(x+2, y+(h/2), x+w-2, y+(h/2));            g.setColor(Color.white);      g.drawString(designNames[design],		   x+((w - designWidth)/2),		   ((h/2) - (stringHeight/2)) );      g.setColor(Color.pink);      g.drawString(countryNames[country],		   x+((w - countryWidth)/2),		   ((h/2) - (stringHeight/2)) + h/2 );    }    else {      g.setColor(Color.black);      g.drawRect(x+2, y, w-4, h);      g.drawLine(x+2, y+(h/2), x+w-2, y+(h/2));      g.setColor(Color.blue);      g.drawString(designNames[design],		   x+((w - designWidth)/2),		   ((h/2) - (stringHeight/2)) );      g.setColor(Color.red);      g.drawString(countryNames[country],		   x+((w - countryWidth)/2),		   ((h/2) - (stringHeight/2)) + h/2 );    }  }  public String toString()  {    return "[design=" + designNames[design] +      ",country=" + countryNames[country] + "]";  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -