📄 llkjm.java
字号:
}
array[x2][j-1] = -1;
buttonArray[x2][j-1].setVisible(false);
buttonArray[x2][j-1].setSelected(false);
buttonArray[x2][j-1].setIcon(null);
}
}
//第三关向上
public void up(int x1,int y1,int x2,int y2,int[][] array,JButton[][] buttonArray){
buttonArray[x1][y1].setBorderPainted(false);
buttonArray[x1][y1].setBorder(null);
buttonArray[x2][y2].setBorderPainted(false);
buttonArray[x2][y2].setBorder(null);
int j,i;
if (y1 == y2) {
for (i = Math.min(x1,x2); i < Math.max(x1,x2) - 1; i++){
array[i][y1] = array[i+1][y1];
buttonArray[i][y1].setIcon(buttonArray[i+1][y1].getIcon());
}
j = Math.max(x1,x2)+1;
while(array[j][y1] >= 0){
array[j-2][y1] = array[j][y1];
buttonArray[j-2][y1].setIcon(buttonArray[j][y1].getIcon());
j++;
}
array[j-2][y1] = -1;
array[j-1][y1] = -1;
buttonArray[j-2][y1].setVisible(false);
buttonArray[j-2][y1].setSelected(false);
buttonArray[j-2][y1].setIcon(null);
buttonArray[j-1][y1].setVisible(false);
buttonArray[j-1][y1].setSelected(false);
buttonArray[j-1][y1].setIcon(null);
}
else {
j = x1;
while (array[j][y1] >= 0){
array[j][y1] = array[++j][y1];
buttonArray[j-1][y1].setIcon(buttonArray[j][y1].getIcon());
}
array[j-1][y1] = -1;
buttonArray[j-1][y1].setVisible(false);
buttonArray[j-1][y1].setSelected(false);
buttonArray[j-1][y1].setIcon(null);
j = x2;
while (array[j][y2] >= 0){
array[j][y2] = array[++j][y2];
buttonArray[j-1][y2].setIcon(buttonArray[j][y2].getIcon());
}
array[j-1][y2] = -1;
buttonArray[j-1][y2].setVisible(false);
buttonArray[j-1][y2].setSelected(false);
buttonArray[j-1][y2].setIcon(null);
}
}
//判断是否消完
public boolean isNull(int[][] array){
for (int i = 1; i <= lengthOfx; i++)
for (int j = 1; j <= lengthOfy; j++)
if (array[i][j] > 0)
return false;
return true;
}
}
// 建立放标签的东西
class DrawLabelPanel extends JPanel implements ActionListener{
/**
*
*/
private static final long serialVersionUID = 1L;
private int delay = 200;
protected Timer timer = new Timer(delay,this);
private String message;
private int xCoordinate;
private int yCoordinate;
String jlWay = "不动";
public DrawLabelPanel(){
}
public DrawLabelPanel(int hintCount,int resetCount){
if (DrawPicturesPanel.getCount() == 2) {
jlWay = "向左动";
}
if (DrawPicturesPanel.getCount() == 3) {
jlWay = "向上动";
}
message = "第 " + DrawPicturesPanel.getCount() + " 关:" +
jlWay + " 提示还剩: " + Llkjm.hintCount + "次 " +
" 重排还剩: " + Llkjm.resetCount + "次 " +
"分数: " + DrawPicturesPanel.getScore();
setVisible(true);
setSize(360,20);
timer.start();
}
public void actionPerformed(ActionEvent e) {
repaint();
}
public void suspend(){
timer.stop();
}
protected void paintComponent(Graphics g){
super.paintComponent(g);
if (DrawPicturesPanel.getCount() == 2) jlWay = "向左动";
if (DrawPicturesPanel.getCount() == 3) jlWay = "向上动";
message = "第 " + DrawPicturesPanel.getCount() + " 关:" +
jlWay + " 提示还剩: " + Llkjm.hintCount + "次 " +
" 重排还剩: " + Llkjm.resetCount + "次 " +
"分数: " + DrawPicturesPanel.getScore();
FontMetrics fm = g.getFontMetrics();
xCoordinate = getWidth() / 2 - fm.stringWidth(message) / 2;
yCoordinate = getHeight() / 2 + fm.getAscent() / 2;
g.drawString(message,xCoordinate,yCoordinate);
}
}
class PaiHang {
private static String[] name = {"a","b","c","d","e"};
private static int[] storeScore = {100000,50000,20000,10000,5000};
private static int newPlace = -1;
private static String[] line = new String[5];
private static BufferedWriter output;
private static File file = new File("D:/score.dat");
public static void showPaiHang() throws IOException{
if (!file.exists()){
output = new BufferedWriter(new FileWriter(file));
for (int i = 0; i < name.length; i++){
String testLength = (i+1) + " " + name[i];
for (int l = testLength.length(); l < 16; l++) testLength += " ";
output.write(testLength + storeScore[i]);
output.newLine();
}
output.close();
}
BufferedReader input = new BufferedReader(new FileReader(file));
if (input.readLine() == null){
output = new BufferedWriter(new FileWriter(file));
for (int i = 0; i < name.length; i++){
String testLength = (i+1) + " " + name[i];
for (int l = testLength.length(); l < 16; l++) testLength += " ";
output.write(testLength + storeScore[i]);
output.newLine();
}
output.close();
}
input = new BufferedReader(new FileReader(file));
int k = 0;
String message = "";
while (k < 5 && (line[k] = input.readLine()) != null){
message += line[k] + "\n";
k++;
}
JOptionPane.showMessageDialog(null,message,
"连连看--排行榜",JOptionPane.INFORMATION_MESSAGE);
input.close();
}
public static void newScore(){
try{
if (!file.exists()){
output = new BufferedWriter(new FileWriter(file));
for (int i = 0; i < name.length; i++){
String testLength = (i+1) + " " + name[i];
for (int l = testLength.length(); l < 16; l++) testLength += " ";
output.write(testLength + storeScore[i]);
output.newLine();
}
output.close();
}
BufferedReader input = new BufferedReader(new FileReader(file));
if (input.readLine() == null){
output = new BufferedWriter(new FileWriter(file));
for (int i = 0; i < name.length; i++){
String testLength = (i+1) + " " + name[i];
for (int l = testLength.length(); l < 16; l++) testLength += " ";
output.write(testLength + storeScore[i]);
output.newLine();
}
output.close();
}
input = new BufferedReader(new FileReader(file));
int k = 0;
StringTokenizer tokenizer;
while (k < 5 && (line[k] = input.readLine()) != null){
tokenizer = new StringTokenizer(line[k]);
tokenizer.nextToken();
name[k] = tokenizer.nextToken();
String scoreString = tokenizer.nextToken();
storeScore[k] = Integer.parseInt(scoreString);
if (storeScore[k] < DrawPicturesPanel.getScore()){
newPlace = k;
break;
}
k++;
}
k++;
while (k < 5 && (line[k] = input.readLine()) != null) k++;
if (newPlace < 0) return;
String s = JOptionPane.showInputDialog(null,"请输入你的英文姓名",
"连连看--排行榜",JOptionPane.QUESTION_MESSAGE);
if (s == null) return;
k = 4;
while (k > newPlace){
line[k] = line[k-1];
k--;
}
line[newPlace] = (newPlace+1) + " " + s + " " + DrawPicturesPanel.getScore();
newPlace = -1;
output = new BufferedWriter(new FileWriter(file));
for (int i = 0; i < 5; i++){
tokenizer = new StringTokenizer(line[i]);
tokenizer.nextToken();
String test = tokenizer.nextToken();
String scoreString = "";
if (!tokenizer.hasMoreTokens()) {
name[i] = "anonymity";scoreString = test;
}
else {
name[i] = test;
scoreString = tokenizer.nextToken();
}
String testLength = (i+1) + " " + name[i];
for (int l = testLength.length(); l < 16; l++) testLength += " ";
output.write(testLength + scoreString);
output.newLine();
}
input.close();
output.close();
}catch(IOException ioe){
}
}
/* static{
Font fnt = new Font("宋体" , 0 ,14);
UIManager.put("OptionPane.font",fnt);
UIManager.put("OptionPane.messageFont",fnt);
UIManager.put("OptionPane.buttonFont",fnt);
}*/
}
class TimeRestrict extends JPanel implements ActionListener {
/**
*
*/
private static final long serialVersionUID = 1L;
private static int delay = 200;
protected Timer timer = new Timer(delay,this);
private int x = 0;
private int y = 0;
private int height = 20;
public static final int WIDTH = 394;
private int width = WIDTH;
private int decrease = 2;
public int getWidth(){
return width;
}
public void setWidth(int width){
this.width = width;
}
public TimeRestrict(){
}
public TimeRestrict(boolean isStart){
timer.start();
}
//时间事件处理
public void actionPerformed(ActionEvent e) {
if (width <= 0) {
timer.stop();
JOptionPane.showMessageDialog(null,"很遗憾!时间已到!",
"连连看--温馨提示",JOptionPane.INFORMATION_MESSAGE);
PaiHang.newScore();
Llkjm.jmiEnd.doClick();
}
repaint();
}
//重写方法画进度条
protected void paintComponent(Graphics g){
super.paintComponent(g);
width -= decrease;
if (width > WIDTH) width = WIDTH;
if ((double)width / WIDTH > 0.4) g.setColor(Color.green);
else if ((double)width / WIDTH > 0.2) g.setColor(Color.yellow);
else g.setColor(Color.red);
g.fillRect(x,y,width,height);
g.setColor(Color.BLACK);
g.fillRect(x+width,y,WIDTH-width,height);
}
/**暂停*/
public void suspend(){
timer.stop();
}
//开始
public void resume(){
timer.start();
}
//重新开始
public void restart(){
delay -= 50;
width = WIDTH;
timer.start();
}
public void setDelay(int delay){
TimeRestrict.delay = delay;
timer.setDelay(delay);
}
}
class Explain{
public Explain(){
JOptionPane.showMessageDialog(null,
" 游戏规则玩法说明\n" +
"\n"+
"1、玩法说明:\n"+
" 游戏规则是需选择一对相同的牌连线,但此连线是在避开其他牌子后,\n" +
"呈现的路径以不超过二转弯为主,如符合规定则消除此一对牌而得分。每一\n" +
"局里玩家需要在规定的时间内消除所有的牌子,当完成任务后,方能进行下\n" +
"一关,当出现残局时,游戏会自动重新洗牌,游戏结束后会以玩家的得分多\n" +
"寡来决定是否登录排行榜。\n" +
"\n"+
"2、提示说明:\n" +
"\n"+
" 使用“提示”功能,游戏会自动显示一组可以消除的牌组。游戏一开始\n" +
"会给玩家一些提示值,这些提示值不会再增加。\n" +
"\n"+
"3、分数说明: \n" +
"\n"+
" 分数上的设计,每过一关,则会依照比例加重给分。\n"+
" 时间、重排点数、提示点数都依照关数,以某种比例给分。\n" +
"\n"+
"5、菜单说明:\n" +
"\n"+
" 【提示】:自动显示一组可以消除的牌组,有次数限制。\n"+
" 【重排】:把牌互换。\n"+
" 【排行榜】:观看本机上的排行榜(想清空排行榜只需删掉score.dat文件)。\n"+
" 【关于】:作者 \n" +
"\n"+
"6、关卡說明(每种难度均有3关):\n" +
"\n"+
" 第1关 不变化 \n"+
" 第2关 向左 \n"+
" 第3关 向上 ",
"连连看--温馨帮助",JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null,"运行本程序会在D盘根目录下创建score.dat文件," +
"用于存储游戏成绩。\n" +
"可删除!技术不过关,请见谅!","补充说明",JOptionPane.INFORMATION_MESSAGE);
}
/* static{
Font fnt = new Font("宋体" , 0 ,14);
UIManager.put("OptionPane.font",fnt);
UIManager.put("OptionPane.messageFont",fnt);
UIManager.put("OptionPane.buttonFont",fnt);
}*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -