資源簡介
游戲開始后,屏幕上方同時(shí)有四個(gè)數(shù)字分四列下落,每個(gè)數(shù)字由三位組成(隨機(jī)生成,但首位不可相同)。玩家用鍵盤依次輸入數(shù)字,如果輸入的數(shù)字序列與某一列正在下落的數(shù)字三位全部相同,則給玩家加10分,該列數(shù)字消失,該列新產(chǎn)生數(shù)字并下落;如果輸入的數(shù)字某一位不相同,則輸入的數(shù)字序列全部作廢,重新接收輸入。某一列數(shù)字到達(dá)屏幕底部則游戲結(jié)束。
作業(yè)題目,這個(gè)只是粗略寫的,分享一下!希望對(duì)大家有點(diǎn)幫助
代碼片段和文件信息
package?DaZi;
import?java.applet.applet;
import?java.awt.*;
import?java.awt.event.KeyEvent;
import?java.awt.event.KeyListener;
import?java.awt.event.WindowAdapter;
import?java.awt.event.WindowEvent;
import?javax.swing.*;
public?class?DaZi?extends?applet?implements?Runnable?KeyListener?{
/**
?*?
?*/
private?static?final?long?serialVersionUID?=?1L;
Image?img;
Graphics?gra;
static?int?width?=?700;?//?圖寬
static?int?height?=?500;?//?圖高
int?x?=?100;
int?y?=?5;
int?score?=?0;
static?Jframe?jf;
int?X[]?=?{?100?200?300?400?};
int?Y[]?=?{?20?20?20?20?};
static?Thread?thread;
boolean?istrue1[]?=?{?false?false?false?false?};?//?判斷第一個(gè)字母是否被點(diǎn)擊過
boolean?istrue2[]?=?{?false?false?false?false?};?//?判斷第一個(gè)字母是否被點(diǎn)擊過
String?litter[]?=?new?String[4];
public?static?void?main(String?args[])?{
DaZi?mf?=?new?DaZi();
jf?=?new?Jframe(“打字“);
jf.setSize(width?height);
jf.getContentPane().add(mf);
jf.getContentPane().setBackground(Color.black);
mf.setlitter();
jf.addKeyListener(mf);
jf.addWindowListener(new?WindowAdapter()?{
public?void?windowClosing(WindowEvent?e)?{
System.exit(0);
}
});
jf.setLocation(200?50);
jf.setResizable(false);
jf.setVisible(true);
thread?=?new?Thread(mf);
thread.start();
}
public?void?paint(Graphics?g)?{
g.setColor(Color.white);
g.setFont(new?Font(“楷體GB2312“?Font.BOLD?20));
for?(int?i?=?0;?i?4;?i++)
g.drawString(litter[i]?X[i]?Y[i]++);
g.setColor(Color.yellow);
g.drawString(“當(dāng)前積分是:“?+?score?width?-?250?height?-?50);?//?有待修改
}
public?String?litter()?{?//?生成一個(gè)隨機(jī)的有三個(gè)數(shù)字的三位數(shù)
int?num?=?10;
int?Litter[]?=?new?int[3];
for?(int?i?=?0;?i?3;?i++)
Litter[i]?=?(int)?(Math.random()?*?num);
String?litter?=?““?+?Litter[0]?+?Litter[1]?+?Litter[2];
return?litter;
}
pu
評(píng)論
共有 條評(píng)論