8. วัตถุสิ่งของ

The Camtasia Studio video content presented here requires JavaScript to be enabled and the latest version of the Macromedia Flash Player. If you are you using a browser with JavaScript disabled please enable it now. Otherwise, please update your version of the free Flash Player by downloading here.

 
รหัสที่ 8-26  คลาส MemoryGame ไว้เล่นเกมจับคู่ทดสอบความจำ (ต่อ)
  private Card waitForCardClicked(Card c0) {
    Card c;
    do {
      window.waitForMouseClicked();     // รอผู้ใช้คลิกบนวินโดว์ 
      int x = window.getMouse().getX(); // อ่านพกัด x ของเมาส์ 
      int y = window.getMouse().getY(); // อ่านพิกัด y ของเมาส์ 
      c = cards[y / Card.HEIGHT][x / Card.WIDTH];
    } while (c == c0 || c.isMatched());
    return c;
  }
  private int random(int a, int b) {
    return a + (int)((b - a + 1) * Math.random());
  }
  private void swap(int[] d, int i, int j) {
    int t = d[i]; d[i] = d[j]; d[j] = t;
  }   
  //-----------------------------------------
  public static void main(String[] args) {
    new MemoryGame(3, 4).begin();
  }
  //-----------------------------------------
}
©2009 S.Prasitjutrakul