Java实现汉诺塔游戏.doc
文本预览下载声明
//盘类 Disk.java
package towers;
import java.awt.*;
public class Disk extends Button {
/**
* 当前Disk对象编号
*/
int number;
/**
* 当前盘上是否有盘
*/
boolean hasDiskUpstairs = false;
/**
* 初始化一个Disk对象
* @param number
* @param tower
*/
public Disk(int number, Tower tower) {
this.number = number;
setBackground(Color.BLUE);
addMouseMotionListener(tower);
addMouseListener(tower);
}
/**
* 获取是否当前盘的上方有盘属性
* @return
*/
public boolean getHasDiskUpstairs() {
return hasDiskUpstairs;
}
/**
* 设置当前盘上是否还有盘属性
* @param b
*/
public void setHasDiskUpstairs(boolean b) {
hasDiskUpstairs = b;
}
/**
* 获取当前盘的编号
* @return
*/
public int getNumber() {
return number;
}
}
//游戏配置类 GameConfig.java
package towers;
public class GameConfig {
/**
* 盘子总数
*/
private int totalDisk;
/**
* 最大盘的宽度
*/
private int diskWidth;
/**
* 最大盘的高度
*/
private int diskHeight;
/**
* 游戏主窗口高度
*/
private int mainFrameHeight;
/**
* 游戏主窗口宽度
*/
private int mainFrameWidth;
/**
* 游戏面板宽度
*/
private int gamePanelWidth;
/**
* 游戏面板高度
*/
private int gamePanelHeight;
/**
* @return the diskHeight
*/
public int getDiskHeight() {
return diskHeight;
}
/**
* @return the diskWidth
*/
public int getDiskWidth() {
return diskWidth;
}
/**
* @return the gamePanelHeight
*/
public int getGamePanelHeight() {
return gamePanelHeight;
}
/**
* @return the gamePanelWidth
*/
public int getGamePanelWidth() {
return gamePanelWidth;
}
/**
* @return the mainFrameHeight
*/
public int getMainFrameHeight() {
return mainFrameHeight;
}
/**
* @return the mainFrameWidth
*/
public int getMainFrameWidth() {
return mainFrameWidth;
}
/**
* @return the totalDisk
*/
public int getTotalDisk() {
return totalDisk;
}
/**
* @param diskHeight the diskHeight to set
*/
public void setDiskHeight(int diskHeight) {
this.diskHeight = diskHeight;
}
/**
* @param diskWidth the diskWidth to set
显示全部