java游戏代码大全
❶ 几个java小游戏代码
package rece;
import java.applet.Applet;
import java.applet.AudioClip;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioSystem;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Rectangle;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JSlider;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.io.File;
import java.util.Vector;
public class Frame extends JFrame implements Runnable {
JPanel contentPane;
JPanel jPanel1 = new JPanel();
JButton jButton1 = new JButton();
JSlider jSlider1 = new JSlider();
JLabel jLabel1 = new JLabel();
JButton jButton2 = new JButton();
JLabel jLabel2 = new JLabel();
int count = 1, rapidity = 80; // count 当前进行的个数, rapidity 游标的位置
int zhengque = 0, cuowu = 0;
int rush[] = { 10 ,20 ,30 }; //游戏每关的个数 可以自由添加.列 { 10 ,20 ,30 ,40,50}
int rush_count = 0; //记录关数
char list[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y',
'Z', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; //随机出现的数字 可以自由添加
Vector number = new Vector();
String paian = "true";
AudioClip Musci_anjian, Music_shi, Music_chenggong;
public Frame() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
//-----------------声音文件---------------------
Musci_anjian = Applet.newAudioClip(new File("sounds//anjian.wav")
.toURL());
Music_shi = Applet.newAudioClip(new File("sounds//shi.wav")
.toURL());
Music_chenggong = Applet.newAudioClip(new File(
"sounds//chenggong.wav").toURL());
//---------------------------------------
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
/**
* Component initialization.
*
* @throws java.lang.Exception
*/
private void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(null);
setSize(new Dimension(588, 530));
setTitle("Frame Title");
jPanel1.setBorder(BorderFactory.createEtchedBorder());
jPanel1.setBounds(new Rectangle(4, 4, 573, 419));
jPanel1.setLayout(null);
jButton1.setBounds(new Rectangle(277, 442, 89, 31));
jButton1.setText("开始");
jButton1.addActionListener(new Frame1_jButton1_actionAdapter(this));
jSlider1.setBounds(new Rectangle(83, 448, 164, 21));
jSlider1.setMaximum(100);
jSlider1.setMinimum(1);
jSlider1.setValue(50);
jLabel1.setText("速度");
jLabel1.setBounds(new Rectangle(35, 451, 39, 18));
jButton2.setBounds(new Rectangle(408, 442, 89, 31));
jButton2.setText("结束");
jButton2.addActionListener(new Frame1_jButton2_actionAdapter(this));
jLabel2.setText("第一关:100个");
jLabel2.setBounds(new Rectangle(414, 473, 171, 21));
contentPane.add(jPanel1);
contentPane.add(jButton2);
contentPane.add(jButton1);
contentPane.add(jSlider1);
contentPane.add(jLabel1);
contentPane.add(jLabel2);
this.addKeyListener(new MyListener());
jButton1.addKeyListener(new MyListener());
jSlider1.addKeyListener(new MyListener());
jSlider1.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
rapidity = jSlider1.getValue();
}
});
}
public void run() {
number.clear();
zhengque = 0;
cuowu = 0;
paian = "true";
while (count <= rush[rush_count]) {
try {
Thread t = new Thread(new Tthread());
t.start();
count += 1;
Thread.sleep(1000 + (int) (Math.random() * 2000)); // 生产下组停顿时间
// 最快1快.最慢2秒
} catch (InterruptedException e) {
e.printStackTrace();
}
}
while (true) { // 等待最后一个字符消失
if (number.size() == 0) {
break;
}
}
if (zhengque == 0) { // 为了以后相除..如果全部正确或者错误就会出现错误. 所以..
zhengque = 1;
}
if (cuowu == 0) {
cuowu = 1;
}
if (paian.equals("true")) { // 判断是否是自然结束
if (zhengque / cuowu >= 2) {
JOptionPane.showMessageDialog(null, "恭喜你过关了");
rush_count += 1; // 自动加1关
if (rush_count < rush.length) {
if (rapidity > 10) { // 当速度大于10的时候在-5提加速度.怕速度太快
rapidity -= 5; // 速度自动减10毫秒
jSlider1.setValue(rapidity); // 选择位置
}
Thread t = new Thread(this);
t.start();
} else {
JOptionPane.showMessageDialog(null, "牛B...你通关了..");
rush_count = 0;
count = 0;
}
} else {
JOptionPane.showMessageDialog(null, "请再接再励");
rush_count = 0;
count = 0;
}
} else {
rush_count = 0;
count = 0;
}
}
public void jButton1_actionPerformed(ActionEvent e) {
Thread t = new Thread(this);
t.start();
}
public void jButton2_actionPerformed(ActionEvent e) {
count = rush[rush_count] + 1;
paian = "flase";
}
class Tthread implements Runnable {
public void run() {
boolean fo = true;
int Y = 0, X = 0;
JLabel show = new JLabel();
show.setFont(new java.awt.Font("宋体", Font.PLAIN, 33));
jPanel1.add(show);
X = 10 + (int) (Math.random() * 400);
String parameter = list[(int) (Math.random() * list.length)] + "";
Bean bean = new Bean();
bean.setParameter(parameter);
bean.setShow(show);
number.add(bean);
show.setText(parameter);
while (fo) {
// ---------------------数字下移--------------------
show.setBounds(new Rectangle(X, Y += 2, 33, 33));
try {
Thread.sleep(rapidity);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (Y >= 419) {
fo = false;
for (int i = number.size() - 1; i >= 0; i--) {
Bean bn = ((Bean) number.get(i));
if (parameter.equalsIgnoreCase(bn.getParameter())) {
cuowu += 1;
jLabel2.setText("正确:" + zhengque + "个,错误:" + cuowu
+ "个");
number.removeElementAt(i);
Music_shi.play();
break;
}
}
}
}
}
}
class MyListener extends KeyAdapter {
public void keyPressed(KeyEvent e) {
String uu = e.getKeyChar() + "";
for (int i = 0; i < number.size(); i++) {
Bean bean = ((Bean) number.get(i));
if (uu.equalsIgnoreCase(bean.getParameter())) {
zhengque += 1;
number.removeElementAt(i);
bean.getShow().setVisible(false);
jLabel2.setText("正确:" + zhengque + "个,错误:" + cuowu + "个");
Music_chenggong.play();
break;
}
}
Musci_anjian.play();
}
}
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception exception) {
exception.printStackTrace();
}
Frame frame = new Frame();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
frame.setLocation((screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
frame.setVisible(true);
}
}
class Frame1_jButton2_actionAdapter implements ActionListener {
private Frame adaptee;
Frame1_jButton2_actionAdapter(Frame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
class Frame1_jButton1_actionAdapter implements ActionListener {
private Frame adaptee;
Frame1_jButton1_actionAdapter(Frame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
class Bean {
String parameter = null;
JLabel show = null;
public JLabel getShow() {
return show;
}
public void setShow(JLabel show) {
this.show = show;
}
public String getParameter() {
return parameter;
}
public void setParameter(String parameter) {
this.parameter = parameter;
}
}
我只有一个打字母小游戏
❷ 鎴戠殑涓栫晫2021鎸囦护姹囨绘渶鏂版寚浠や唬镰佸ぇ鍏
鎴戠殑涓栫晫娓告垙涓鎸囦护鏄闱炲父閲嶈佺殑鍐呭癸纴链娆″氨涓哄ぇ瀹跺甫𨱒ヤ简鎴戠殑涓栫晫2021鎸囦护姹囨伙纴涔熸槸链鏂版寚浠や唬镰佸ぇ鍏锛岄潪甯稿叏闱㈢殑鍐呭癸纴𨱍充简瑙f垜镄勪笘鐣屾寚浠ょ殑链嫔弸鍙浠ュ弬钥冿纴甯屾湜鑳藉府鍒板ぇ瀹躲
/alwaysday:
阌佸畾鎴栬В阌佹樇澶滀氦镟裤
璇娉曪细/alwaysday
(涓浜烘劅瑙夎繖涓娌′粈涔堢敤锛岀幇鍦ㄥ熀宀╃増鍦ㄨ剧疆閲岃皟鏁村氨琛屼简)
/clear:
浠庣帺瀹剁墿鍝佹爮涓鍒犻櫎鐗╁搧銆
璇娉曪细/clear [鐜╁:鐩镙嘳 [鐗╁搧钖:瀛楃︿覆] [鏁版嵁:鏁存暟] [链澶ф暟閲:鏁存暟]
鍙傛暟锛
鈪犵洰镙
蹇呴’鏄鐜╁跺悕绉版垨鐩镙囬夋嫨鍣ㄣ傝嫢链瀹氢箟鍒欓粯璁や负锻戒护镓ц岃呫傚湪锻戒护鏂瑰潡涓涓哄繀阃夊弬鏁般
鈪$墿鍝
鎸囧畾灏呜娓呴櫎镄勭墿鍝両D銆傝嫢链瀹氢箟鍒欐竻闄ょ墿鍝佹爮涓镓链夌墿鍝併侸ava鐗堜腑鍙浠ユ槸鐗╁搧镙囩俱
鈪㈡暟鎹
鎸囧畾灏呜娓呴櫎镄勭墿鍝佺殑鏁版嵁鍊笺傝嫢链鎸囧畾鎴栧畾涔変负-1锛屽垯镓链夌﹀悎鐗╁搧鍊肩殑鐗╁搧浼氲娓呴櫎钥屼笉钥冭槛鐗╁搧鏁版嵁銆
鈪f渶澶ф暟閲
鎸囧畾鐗╁搧灏呜娓呴櫎镄勬渶澶ф暟閲忋傝嫢链鎸囧畾鎴栧畾涔変负-1锛屽垯镓链夌﹀悎鐗╁搧涓庢暟鎹鍊肩殑鐗╁搧浼氲娓呴櫎銆傝嫢瀹氢箟涓0锛屽垯涓崭细娓呴櫎浠讳綍鐗╁搧锛屼絾浼氭垚锷熸墽琛屽苟杩斿洖鏄钖︽湁鐗╁搧链搴旇ヨ娓呴櫎(阃傜敤浜庢娴嬬墿鍝)銆
渚嫔瓙锛/clear XXX diamond 0 1(鍟嗗簵绯荤粺锘虹璁剧疆)
(璇ユ寚浠ゅ彲浠ョ粡甯哥敤鍦ㄨ嚜鍒跺湴锲句緥濡侾VP銆佹湇锷″櫒銆佺熻祦链嶉噷锛岄槻姝㈢帺瀹朵綔寮娿)
/clone:
灏嗙壒瀹氩尯锘熺殑鏂瑰潡澶嶅埗鍒板彟涓澶勚
璇娉曪细
鈶/clone 寮濮:x y z缁撴潫:x y z浣岖疆:x y z[replace/masked/...] [鏂瑰潡:鏂瑰潡] [鏂瑰潡鏁版嵁:鏁存暟]
鈶/clone 寮濮:x y z缁撴潫:x y z浣岖疆:x y zfiltered[鏂瑰潡钖:瀛楃︿覆] [鏂瑰潡鏁版嵁:鏁存暟]
filtered:浠呭嶅埗鏂瑰潡ID绗﹀悎鏂瑰潡钖嶅畾涔夌殑鏂瑰潡銆
masked:浠呭嶅埗闱炵┖姘旀柟鍧椼备细淇濇寔鐩镄勫尯锘熶腑铡熸湰浼氲镟挎崲涓虹┖姘旂殑鏂瑰潡涓嶅彉銆
replace:澶嶅埗镓链夋柟鍧楋纴鐢ㄥ师鍖哄烟镄勬柟鍧楄嗙洊鐩镙囧尯锘熶腑镄勬墍链夋柟鍧椼
鑻ユ湭瀹氢箟锛屽垯榛樿や负replace銆
force:寮哄埗澶嶅埗锛屽嵆浣垮师鍖哄烟涓庣洰镙囧尯锘熸湁閲嶅彔銆
move:灏嗗师鍖哄烟澶嶅埗鍒扮洰镙囧尯锘燂纴骞跺皢铡熷尯锘熸浛鎹涓虹┖姘斻傚湪filtered阆缃╂ā寮忎笅锛屽彧链夎澶嶅埗镄勬柟鍧楁墠浼氭浛鎹涓虹┖姘斻
normal:涓嶆墽琛宫ove鍙奻orce銆
鑻ユ湭瀹氢箟锛岄粯璁や负normal銆
渚嫔瓙锛/clone 0 7 -6 20 18 58 masked(澶嶅埗涓嶈勫垯寤虹瓒)
(clone鎸囦护鍙浠ュ揩阃熻繘琛屼竴浜涘ぇ宸ョ▼锛屾瘆濡傚仛涓澶嶅埗寤虹瓒绛夌瓑锛岀湅涓婂幓娑夊强鍒板潗镙囩郴锛屼笉杩囧彧瑕佹帉鎻★纴鍏跺疄鍗佸垎绠鍗曘)
/connect:
杩炴帴鍒板彟涓涓链嶅姟鍣ㄣ
璇娉曪细/connect 链嶅姟鍣║RL
/daylock:
阌佸畾鎴栬В阌佹樇澶滀氦镟裤(钖/alwaysday)
璇娉曪细/daylock
(涓浜烘劅瑙夎繖涓娌′粈涔堢敤锛岀幇鍦ㄥ熀宀╃増鍦ㄨ剧疆閲岃皟鏁村氨琛屼简)
/deop:
鎾ら攒鐜╁剁殑绠$悊锻樿韩浠姐
璇娉曪细/deop 鐜╁:鐩镙
/difficulty:
璁剧疆娓告垙闅惧害绯绘暟绛夌骇銆
璇娉曪细/difficulty 闅惧害:瀛楃︿覆
鍙傛暟锛
Peaceful钬斺斿拰骞抽毦搴
Easy钬斺旂亩鍗曢毦搴
Normal钬斺旀櫘阃氶毦搴
Hard钬斺斿汹闅鹃毦搴
/effect:
绠$悊鐜╁跺强鍏朵粬瀹炰綋涓婄殑鐘舵佹晥鏋溿
璇娉曪细
鈶/effect 鐜╁:鐩镙啴lear
鈶/effect 鐜╁:鐩镙囨晥鏋:鏁堟灉[绉掓暟:鏁存暟] [寮哄害:鏁存暟] [t/f]
鍙傛暟(浠呭熀宀╃増)锛
1 - 阃熷害鎻愬崌 锛圫peed锛
2 - 缂撴参 锛圫lowness锛
3 - 鎸栨帢鏁堢巼鎻愬崌 锛圚aste锛
4 - 缂撴参鎸栨帢 锛圡ining_Fatigue锛
5 - 锷涢噺 锛圫trength锛
6 - 鐬闂存仮澶 锛圛nstant_Health锛
7 - 鐬闂翠激瀹 锛圛nstant_Damage锛
8 - 璺宠穬鎻愬崌 锛圝ump_Boost锛
9 - 鍙嶈儍 锛圢ausea锛
10 - 鐢熷懡鎭㈠ 锛圧egeneration锛
11 - 鎶楁ф彁鍗 锛圧esistance锛
12 - 𨱔铹版姉镐 锛团ire Resistance锛
13 - 姘翠笅锻煎惛 锛圵ater Breathing锛
14 - 闅愬舰 锛圛nvisibility锛
15 - 澶辨槑 锛圔lindness锛
16 - 澶滆 锛圢ight_Vision锛
17 - 楗ラタ 锛圚unger锛
18 - 铏氩急 锛圵eakness锛
19 - 涓姣 锛圥oison锛
20 - 鍑嬮浂 锛圵ither锛
21 - 链澶х敓锻 锛圚ealth_Boost锛
22 - 闄勫姞鐢熷懡 锛圆bsorption锛
23 - 阒查ゥ楗 锛圫aturation锛
渚嫔瓙锛/effect @p invisibility 9999 1 true(PVP缁忓吀瑙掕壊钬滃菇𨱔碘濄佲滈奸琼钬濇晥鏋滐纴true琛ㄧず涓崭细鍦ㄤ汉鐗╄韩杈瑰嚭鐜拌嵂姘寸矑瀛)
/enablenpc:
鏄钖﹀厑璁稿湪娓告垙閲岀敓鎴怤PC銆
璇娉曪细/enableenpc [t/f]
/enchant:
涓虹帺瀹舵坠鎸佺墿鍝侀梼榄旓纴鍙楅檺浜庨搧镰ф満鍒(涓嶅彲澶т簬璇ラ瓟鍜掓渶澶х瓑绾)銆
璇娉曪细
鈶/enchant 鐜╁:鐩镙囬瓟鍜扞D:鏁存暟[绛夌骇:鏁存暟]
鈶/enchant 鐜╁:鐩镙囬瓟鍜掑悕:瀛楃︿覆[绛夌骇:鏁存暟]
鈪犵洰镙
鎸囧畾鐩镙囥傚繀椤绘槸涓涓鐜╁跺悕鎴栫洰镙囬夋嫨鍣ㄣ
鈪¢瓟鍜
鎸囧畾娣诲姞镊崇帺瀹舵坠鎸佺墿鍝佺殑榄斿拻銆傚繀椤绘槸涓涓链夋晥镄勯瓟鍜扞D銆傚湪Java鐗堬纴蹇呴’鏄瀹屾暣镄勫瓧姣岻D锛埚俶inecraft:sharpness锛夛纴鍙浠ョ渷鐣ュ懡钖岖┖闂达纸濡俿harpness锛夈傚湪锘哄博鐗堬纴鍙浠ユ槸鏁板瓧锛埚16锛夈
鈪㈢瓑绾
鎸囧畾榄斿拻绛夌骇銆傚繀椤昏呖灏戜负1涓斾笉瓒呰繃鎸囧畾榄斿拻镄勬渶澶х瓑绾с傝嫢链鎸囧畾锛岄粯璁や负1銆
鈪f晥鏋
鑻ュ弬鏁版寚瀹氢笉姝g‘锛屾垨褰撶帺瀹舵湭鑳芥寚瀹氢竴涓鎴栨洿澶氱殑鍦ㄧ嚎鐜╁讹纴鎴栧綋榄斿拻瀵圭墿鍝佹棤鏁堟垨涓庣幇链夐瓟鍜掑啿绐佹椂鍒椤け璐ワ纸渚嫔傦纴钬灭伀铹颁缭鎶も濋瓟鍜掓棤娉旷粰浜埚凡闄勯瓟钬滀缭鎶も濈殑鐩旂敳锛岃屸滈攱鍒㊣II钬濇棤娉旷粰浜埚凡闄勯瓟钬滈攱鍒㊣钬濈殑鍓戯级銆
鑻ユ垚锷燂纴娣诲姞鎸囧畾镄勯瓟鍜掕呖鐩镙囩殑镓嬫寔鐗╁搧銆
鍙傛暟锛
淇濇姢 IV
𨱔铹颁缭鎶 IV
鎽旇惤淇濇姢 IV
鐖嗙偢淇濇姢 IV
寮瑰皠鐗╀缭鎶 IV
姘翠笅锻煎惛 III
姘翠笅阃熸帢 I
阌嫔埄 V
浜$伒𨱒镓 V
鑺傝偄鍏嬫槦 V
鍑婚 II
𨱔铹伴梼锷 II
鎶㈠ず III
鏁堢巼 V
绮惧嗳閲囬泦 I
钥愪箙 III
镞惰繍 III
锷涢噺 V
鍐插嚮 II
𨱔鐭 I
镞犻檺 I
娴蜂箣鐪烽【 鈪
楗甸挀 鈪
鍐伴湝琛岃 鈪
缁忛獙淇琛 鈪
绌垮垭 鈪
婵娴 鈪
蹇犺瘹 鈪
寮曢浄 鈪
澶氶吨绠 鈪
绌块 鈪
蹇阃熻呭~ 鈪
渚嫔瓙锛/enchant @s 1 4(缁欎篑镓嬩笂瑁呭囦缭鎶も叁鏁堟灉)
/execute:
浣跨敤姝ゅ懡浠ゆ墽琛岃呯殑𨱒冮檺锛屼互鍏朵粬鐜╁/瀹炰綋镄勮韩浠芥墽琛屽懡浠ゃ
璇娉曪细
鈶/execute 镓ц屾簮:鐩镙囧潗镙:x y z锻戒护:锻戒护
鈶/execute 镓ц屾簮:鐩镙囧潗镙:x y zdetect 鎺㈡祴鍧愭爣:x y z鏂瑰潡:鏂瑰潡鏁版嵁: 鏁存暟锻戒护:锻戒护
渚嫔瓙锛(寰鐜淇濇寔寮钖锻戒护鏂瑰潡)/execute XXX ~~~ particle XXX minecraft:basic_flame_particle ~~-2~(妫娴嬬帺瀹禭XX骞跺湪鐜╁秠鍧愭爣-2澶勭敓鎴愮伀铹扮矑瀛愶纴绠鍗曟潵璇村氨鏄瑁呴叿锛屽熬闅忕矑瀛愭晥鏋)
/fill:
鐢ㄧ壒瀹氭柟鍧楀~鍏呬竴涓鍖哄烟镄勫叏閮ㄦ垨閮ㄥ垎銆
璇娉曪细/fill 镊:x y z镊:x y z鏂瑰潡:鏂瑰潡[鏁版嵁:鏁存暟] [destroy/keep/outline/replace/...]
鍙傛暟锛
destroy-鐢ㄦ寚瀹氭柟鍧楁浛鎹㈠~鍏呭尯锘熷唴镓链夋柟鍧楋纴铡熸湁鏂瑰潡瑙嗕负琚镞犻瓟鍜掔殑阍荤煶阌规垨闀愰噰鎺樿屾帀钀藉瑰簲镄勫疄浣揿舰寮忋
hollow- 浠呯敤鎸囧畾鏂瑰潡镟挎崲濉鍏呭尯锘熷栧眰镄勬柟鍧椼傚唴閮ㄦ柟鍧楄镟挎崲涓虹┖姘旓纴鎺夎惤琚镟挎崲鏂瑰潡鍙鑳芥嫢链夌殑鍐呭圭墿锛屼絾鏂瑰潡镊韬涓崭细鎺夎惤銆
keep- 浠呯敤鎸囧畾鏂瑰潡镟挎崲濉鍏呭尯锘熷唴镄勭┖姘旀柟鍧椼
outline- 浠呯敤鎸囧畾鏂瑰潡镟挎崲濉鍏呭尯锘熷栧眰镄勬柟鍧椼傚唴閮ㄦ柟鍧椾笉鍙楀奖鍝嶃
replace- 鐢ㄦ寚瀹氭柟鍧楁浛鎹㈠~鍏呭尯锘熷唴镓链夋柟鍧楋纴钥屼笉浠ュ疄浣揿舰寮忔帀钀借镟挎崲镄勬柟鍧楀拰鏂瑰潡鍐呭圭墿銆傚彲阃夊湴锛屼笉鎸囧畾镟挎崲钖庢柟鍧楃殑鏁版嵁镙囩撅纴钥屾槸鎸囧畾鏂瑰潡ID鍜屾暟鎹鍊硷纴鐢ㄤ簬闄愬埗琚镟挎崲镄勬柟鍧楃被鍨嬨
渚嫔瓙锛/fill 0 0 0 20 20 20 ***(濉鍏呬綅浜庝粠0 0 0澶勮呖20 20 20澶***镣稿脊钬斺旂敤镓撶伀鐭崇偣鐕冧竴鏋氩悗锛屼綘灏嗕细鏀跺埌𨱒ヨ嚜鏄惧崱镄勫哜瑙)
/function:
杩愯屼竴涓鍑芥暟銆
璇娉曪细/function 鍑芥暟钖岖О
/gamemode:
璁剧疆鐜╁剁殑娓告垙妯″纺銆
璇娉曪细
鈶/gamemode 妯″纺:瀛楃︿覆[鐜╁:鐩镙嘳
鈶/gamemode 妯″纺:鏁存暟[鐜╁:鐩镙嘳
鍙傛暟锛
survival 鐢熷瓨妯″纺
creative 鍒涢犳ā寮
adventure 鍐挜橹妯″纺
spectator 镞佽傛ā寮
/gamerule:
璁剧疆鎴栨煡璇涓𨱒℃父鎴忚勫垯銆
璇娉曪细
鈶/gamerule 瑙勫垯:瀛楃︿覆鍊:甯冨皵鍊
鈶/gamerule 瑙勫垯:瀛楃︿覆鍊:鏁存暟
渚嫔瓙锛/gamerule commandblockoutput false(镊鍒跺湴锲惧繀澶囨寚浠わ纴阒叉㈠懡浠ゆ柟鍧楁墽琛屽懡浠ゆ樉绀哄湪镵婂ぉ妗)
/give:
灏嗙壒瀹氱墿鍝佺粰浜堜竴浣岖帺瀹躲
璇娉曪细/give 鐜╁:鐩镙囩墿鍝佸悕:瀛楃︿覆[鏁伴噺:鏁存暟] [鏁版嵁:鏁存暟] [鎴愬垎:鎴愬垎]
鍙傛暟锛
鈪犵洰镙
鎸囧畾缁欎篑鐗╁搧镄勭洰镙囥傚繀椤讳负涓涓鐜╁跺悕鎴栫洰镙囬夋嫨鍣ㄣ
鈪$墿鍝
鎸囧畾缁欎篑镄勭墿鍝併傚繀椤讳负涓涓链夋晥镄勭墿鍝両D锛屾垨涓轰竴涓瀛桦湪鐗╁搧褰㈡佺殑链夋晥镄勬柟鍧桰D銆备笉鏀鎸佹暟瀛桰D銆
鈪㈡暟閲
鎸囧畾缁欎篑镄勭墿鍝佹暟閲忋傚繀椤诲湪1鍜64闂达纴浣64瓒呰繃璇ョ墿鍝佷竴缁勭殑鏁伴噺镞朵粛铹舵湁鏁堛傝嫢链鎸囧畾锛岄粯璁や负1銆
镞犺嗙壒瀹氱墿鍝佺殑鍫嗗彔闄愬埗锛屼緥濡傦细/give @s minecraft:iron_sword 5浼氱粰浜1缁5鎶婇搧鍓戯纴浣嗘e父𨱍呭喌涓嬮搧鍓戝簲涓1缁1鎶娿备竴缁勬渶灏1涓鐗╁搧銆佹渶澶64涓鐗╁搧镄勯檺鍒朵粛铹舵湁鏁堛
鈪f暟鎹
鎸囧畾镓缁欎篑鐗╁搧镄勭墿鍝佹暟鎹銆傚繀椤讳负涓涓浠嬩簬-2,147,483,648鍜2,147,483,647涔嬮棿镄勬暣鏁帮纴浣嗘槸褰撴暟鎹鍊煎逛簬鎸囧畾镄勭墿鍝両D镞犳晥镞讹纴浼氲閲岖疆涓0銆傝嫢链鎸囧畾锛岄粯璁や负0銆
鈪ゆ垚鍒
涓庢暟鎹镙囩剧被浼硷纴浣嗕粎鏀鎸丆anPlaceOn鍜孋anDestroy镙囩俱傝濡傦细 give @s iron_shovel 1 0 {"minecraft:can_destroy":{"blocks":["grass"]}}
鈪ユ晥鏋
鑻ュ弬鏁版寚瀹氢笉姝g‘锛屾垨鐜╁舵棤娉曡В鏋愪负涓涓鎴栧氢釜鍦ㄧ嚎鐜╁舵椂鍒椤け璐ャ
鑻ユ垚锷燂纴鍦ㄧ洰镙囨墍澶勭殑浣岖疆涓婄敓鎴愭寚瀹氱殑鎺夎惤镄勭墿鍝併傚傛灉鐜╁舵寚瀹氢简澶氢釜鐩镙囷纴姣忎釜鐩镙囬兘浼氭敹鍒版寚瀹氭暟閲忕殑鐗╁搧銆傜敓鎴愮墿鍝佺殑鐗╁搧瀹炰綋涓镄勬嫢链夎呮爣绛句细琚璁句负鐗╁搧缁欎篑镄勭洰镙囷纴涓旀崱𨰾惧欢镞舵爣绛捐璁句负0锛屼娇寰楃墿鍝佽兘澶熺珛鍗宠繘鍏ョ洰镙囩殑鐗╁搧镙忎腑锛岄櫎闱炵墿鍝佹爮宸叉弧銆
(杩欎釜鎴戝氨涓嶈翠简钖э纴锻戒护鏂瑰潡閮芥槸杩欐牱銮峰缑镄(婊戠ń))
/help:
鎻愪緵甯锷/锻戒护鍒楄〃銆
璇娉曪细
鈶/help 锻戒护:锻戒护钖岖О
鈶/help 椤垫暟:鏁存暟
/kill:
𨱒姝/娓呴櫎浠讳綍瀹炰綋銆
璇娉曪细/kill 鐩镙:鐩镙
/list:
鍒楀嚭链嶅姟鍣ㄤ笂镄勭帺瀹躲
璇娉曪细/list
/locate:
鏄剧ず璺濈绘渶杩戠殑缁椤畾绫诲瀷镄勫缓绛戜綅缃銆
璇娉曪细
鈶/locate 鐗规э细瀛楃︿覆
鈶/locate 缁撴瀯绫诲瀷
鍙傛暟锛
锘嬭棌镄勫疂钘 Buried_Treasure/buriedtreasure
链鍦板煄 EndCity/endcity
涓嬬晫瑕佸 Fortress/fortress
鏋楀湴搴滈偢 Mansion/mansion
搴熷纯鐭夸簳 Mineshaft/mineshaft
娴峰簳阆楄抗 Monument/monument
娴峰簳搴熷 Ocean_Ruin/ruins
娌夎埞 Shipwreck/shipwreck
瑕佸 Stronghold/stronghold
娌欐紶绁炴 Desert_Pyramid/temple
闆灞 Igloo
涓涙滠绁炲簷 Jungle_Pyramid
濂冲帆灏忓眿 Swamp_Hut
𨱒戝箪 Village/village
鎺犲ず钥呭墠鍝ㄧ珯 Pillager_Outpost/pillageroutpost
/me:
鏄剧ず涓𨱒″叧浜庢偍镊宸辩殑娑堟伅銆
璇娉曪细/me 鍐呭
阒茬偢鎸囦护锛
/gamerule ***explodes false
涓嶆樉绀鸿緭鍑哄懡浠わ细
/gamerule commandblockoutput False
阍荤煶瑁呭兊灏告寚浠(鍙鐢ㄤ簬PVE锛屼粎Java)锛
/summon zombie ~~1~ {Equipment:[{id:261,Count:1},{id:313,Count:1},{id:312,Count:1},{id:311,Count:1},{id:310,Count:1}]}
阒茬伀铹拌敁寤(阒叉㈡湪𨱒跨瓑锷╃噧鐗╄𨱔鐑у埌钄揿欢)锛
/gamerule dofiretick false
❸ 求一个简单又有趣的JAVA小游戏代码
具体如下:
连连看的小源码
package Lianliankan;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class lianliankan implements ActionListener
{
JFrame mainFrame; //主面板
Container thisContainer;
JPanel centerPanel,southPanel,northPanel; //子面板
JButton diamondsButton[][] = new JButton[6][5];//游戏按钮数组
JButton exitButton,resetButton,newlyButton; //退出,重列,重新开始按钮
JLabel fractionLable=new JLabel("0"); //分数标签
JButton firstButton,secondButton; //
分别记录两次被选中的按钮
int grid[][] = new int[8][7];//储存游戏按钮位置
static boolean pressInformation=false; //判断是否有按钮被选中
int x0=0,y0=0,x=0,y=0,fristMsg=0,secondMsg=0,validateLV; //游戏按钮的位置坐标
int i,j,k,n;//消除方法控制
代码(code)是程序员用开发工具所支持的语言写出来的源文件,是一组由字符、符号或信号码元以离散形式表示信息的明确的规则体系。
对于字符和Unicode数据的位模式的定义,此模式代表特定字母、数字或符号(例如 0x20 代表一个空格,而 0x74 代表字符“t”)。一些数据类型每个字符使用一个字节;每个字节可以具有 256 个不同的位模式中的一个模式。
在计算机中,字符由不同的位模式(ON 或 OFF)表示。每个字节有 8 位,这 8 位可以有 256 种不同的 ON 和 OFF 组合模式。对于使用 1 个字节存储每个字符的程序,通过给每个位模式指派字符可表示最多 256 个不同的字符。2 个字节有 16 位,这 16 位可以有 65,536 种唯一的 ON 和 OFF 组合模式。使用 2 个字节表示每个字符的程序可表示最多 65,536 个字符。
单字节代码页是字符定义,这些字符映射到每个字节可能有的 256 种位模式中的每一种。代码页定义大小写字符、数字、符号以及 !、@、#、% 等特殊字符的位模式。每种欧洲语言(如德语和西班牙语)都有各自的单字节代码页。
虽然用于表示 A 到 Z 拉丁字母表字符的位模式在所有的代码页中都相同,但用于表示重音字符(如"é"和"á")的位模式在不同的代码页中却不同。如果在运行不同代码页的计算机间交换数据,必须将所有字符数据由发送计算机的代码页转换为接收计算机的代码页。如果源数据中的扩展字符在接收计算机的代码页中未定义,那么数据将丢失。
如果某个数据库为来自许多不同国家的客户端提供服务,则很难为该数据库选择这样一种代码页,使其包括所有客户端计算机所需的全部扩展字符。而且,在代码页间不停地转换需要花费大量的处理时间。
❹ 用JAVA设计游戏:五子棋游戏
下面的源代码分为4个文件;
chessClient.java:客户端主程序。
chessInterface.java:客户端的界面。
chessPad.java:棋盘的绘制。
chessServer.java:服务器端。
可同时容纳50个人同时在线下棋,聊天。
没有加上详细注释,不过绝对可以运行,j2sdk1.4下通过。
/*********************************************************************************************
1.chessClient.java
**********************************************************************************************/
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.util.*;
class clientThread extends Thread
{
chessClient chessclient;
clientThread(chessClient chessclient)
{
this.chessclient=chessclient;
}
public void acceptMessage(String recMessage)
{
if(recMessage.startsWith("/userlist "))
{
StringTokenizer userToken=new StringTokenizer(recMessage," ");
int userNumber=0;
chessclient.userpad.userList.removeAll();
chessclient.inputpad.userChoice.removeAll();
chessclient.inputpad.userChoice.addItem("所有人");
while(userToken.hasMoreTokens())
{
String user=(String)userToken.nextToken(" ");
if(userNumber>0 && !user.startsWith("[inchess]"))
{
chessclient.userpad.userList.add(user);
chessclient.inputpad.userChoice.addItem(user);
}
userNumber++;
}
chessclient.inputpad.userChoice.select("所有人");
}
else if(recMessage.startsWith("/yourname "))
{
chessclient.chessClientName=recMessage.substring(10);
chessclient.setTitle("Java五子棋客户端 "+"用户名:"+chessclient.chessClientName);
}
else if(recMessage.equals("/reject"))
{
try
{
chessclient.chesspad.statusText.setText("不能加入游戏");
chessclient.controlpad.cancelGameButton.setEnabled(false);
chessclient.controlpad.joinGameButton.setEnabled(true);
chessclient.controlpad.creatGameButton.setEnabled(true);
}
catch(Exception ef)
{
chessclient.chatpad.chatLineArea.setText("chessclient.chesspad.chessSocket.close无法关闭");
}
chessclient.controlpad.joinGameButton.setEnabled(true);
}
else if(recMessage.startsWith("/peer "))
{
chessclient.chesspad.chessPeerName=recMessage.substring(6);
if(chessclient.isServer)
{
chessclient.chesspad.chessColor=1;
chessclient.chesspad.isMouseEnabled=true;
chessclient.chesspad.statusText.setText("请黑棋下子");
}
else if(chessclient.isClient)
{
chessclient.chesspad.chessColor=-1;
chessclient.chesspad.statusText.setText("已加入游戏,等待对方下子...");
}
}
else if(recMessage.equals("/youwin"))
{
chessclient.isOnChess=false;
chessclient.chesspad.chessVictory(chessclient.chesspad.chessColor);
chessclient.chesspad.statusText.setText("对方退出,请点放弃游戏退出连接");
chessclient.chesspad.isMouseEnabled=false;
}
else if(recMessage.equals("/OK"))
{
chessclient.chesspad.statusText.setText("创建游戏成功,等待别人加入...");
}
else if(recMessage.equals("/error"))
{
chessclient.chatpad.chatLineArea.append("传输错误:请退出程序,重新加入 \n");
}
else
{
chessclient.chatpad.chatLineArea.append(recMessage+"\n");
chessclient.chatpad.chatLineArea.setCaretPosition(
chessclient.chatpad.chatLineArea.getText().length());
}
}
public void run()
{
String message="";
try
{
while(true)
{
message=chessclient.in.readUTF();
acceptMessage(message);
}
}
catch(IOException es)
{
}
}
}
public class chessClient extends Frame implements ActionListener,KeyListener
{
userPad userpad=new userPad();
chatPad chatpad=new chatPad();
controlPad controlpad=new controlPad();
chessPad chesspad=new chessPad();
inputPad inputpad=new inputPad();
Socket chatSocket;
DataInputStream in;
DataOutputStream out;
String chessClientName=null;
String host=null;
int port=4331;
boolean isOnChat=false; //在聊天?
boolean isOnChess=false; //在下棋?
boolean isGameConnected=false; //下棋的客户端连接?
boolean isServer=false; //如果是下棋的主机
boolean isClient=false; //如果是下棋的客户端
Panel southPanel=new Panel();
Panel northPanel=new Panel();
Panel centerPanel=new Panel();
Panel westPanel=new Panel();
Panel eastPanel=new Panel();
chessClient()
{
super("Java五子棋客户端");
setLayout(new BorderLayout());
host=controlpad.inputIP.getText();
westPanel.setLayout(new BorderLayout());
westPanel.add(userpad,BorderLayout.NORTH);
westPanel.add(chatpad,BorderLayout.CENTER);
westPanel.setBackground(Color.pink);
inputpad.inputWords.addKeyListener(this);
chesspad.host=controlpad.inputIP.getText();
centerPanel.add(chesspad,BorderLayout.CENTER);
centerPanel.add(inputpad,BorderLayout.SOUTH);
centerPanel.setBackground(Color.pink);
controlpad.connectButton.addActionListener(this);
controlpad.creatGameButton.addActionListener(this);
controlpad.joinGameButton.addActionListener(this);
controlpad.cancelGameButton.addActionListener(this);
controlpad.exitGameButton.addActionListener(this);
controlpad.creatGameButton.setEnabled(false);
controlpad.joinGameButton.setEnabled(false);
controlpad.cancelGameButton.setEnabled(false);
southPanel.add(controlpad,BorderLayout.CENTER);
southPanel.setBackground(Color.pink);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
if(isOnChat)
{
try
{
chatSocket.close();
}
catch(Exception ed)
{
}
}
if(isOnChess || isGameConnected)
{
try
{
chesspad.chessSocket.close();
}
catch(Exception ee)
{
}
}
System.exit(0);
}
public void windowActivated(WindowEvent ea)
{
}
});
add(westPanel,BorderLayout.WEST);
add(centerPanel,BorderLayout.CENTER);
add(southPanel,BorderLayout.SOUTH);
pack();
setSize(670,548);
setVisible(true);
setResizable(false);
validate();
}
public boolean connectServer(String serverIP,int serverPort) throws Exception
{
try
{
chatSocket=new Socket(serverIP,serverPort);
in=new DataInputStream(chatSocket.getInputStream());
out=new DataOutputStream(chatSocket.getOutputStream());
clientThread clientthread=new clientThread(this);
clientthread.start();
isOnChat=true;
return true;
}
catch(IOException ex)
{
chatpad.chatLineArea.setText("chessClient:connectServer:无法连接,建议重新启动程序 \n");
}
return false;
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==controlpad.connectButton)
{
host=chesspad.host=controlpad.inputIP.getText();
try
{
if(connectServer(host,port))
{
chatpad.chatLineArea.setText("");
controlpad.connectButton.setEnabled(false);
controlpad.creatGameButton.setEnabled(true);
controlpad.joinGameButton.setEnabled(true);
chesspad.statusText.setText("连接成功,请创建游戏或加入游戏");
}
}
catch(Exception ei)
{
chatpad.chatLineArea.setText("controlpad.connectButton:无法连接,建议重新启动程序 \n");
}
}
if(e.getSource()==controlpad.exitGameButton)
{
if(isOnChat)
{
try
{
chatSocket.close();
}
catch(Exception ed)
{
}
}
if(isOnChess || isGameConnected)
{
try
{
chesspad.chessSocket.close();
}
catch(Exception ee)
{
}
}
System.exit(0);
}
if(e.getSource()==controlpad.joinGameButton)
{
String selectedUser=userpad.userList.getSelectedItem();
if(selectedUser==null || selectedUser.startsWith("[inchess]") ||
selectedUser.equals(chessClientName))
{
chesspad.statusText.setText("必须先选定一个有效用户");
}
else
{
try
{
if(!isGameConnected)
{
if(chesspad.connectServer(chesspad.host,chesspad.port))
{
isGameConnected=true;
isOnChess=true;
isClient=true;
controlpad.creatGameButton.setEnabled(false);
controlpad.joinGameButton.setEnabled(false);
controlpad.cancelGameButton.setEnabled(true);
chesspad.chessthread.sendMessage("/joingame "+userpad.userList.getSelectedItem()+" "+chessClientName);
}
}
else
{
isOnChess=true;
isClient=true;
controlpad.creatGameButton.setEnabled(false);
controlpad.joinGameButton.setEnabled(false);
controlpad.cancelGameButton.setEnabled(true);
chesspad.chessthread.sendMessage("/joingame "+userpad.userList.getSelectedItem()+" "+chessClientName);
}
}
catch(Exception ee)
{
isGameConnected=false;
isOnChess=false;
isClient=false;
controlpad.creatGameButton.setEnabled(true);
controlpad.joinGameButton.setEnabled(true);
controlpad.cancelGameButton.setEnabled(false);
chatpad.chatLineArea.setText("chesspad.connectServer无法连接 \n"+ee);
}
}
}
if(e.getSource()==controlpad.creatGameButton)
{
try
{
if(!isGameConnected)
{
if(chesspad.connectServer(chesspad.host,chesspad.port))
{
isGameConnected=true;
isOnChess=true;
isServer=true;
controlpad.creatGameButton.setEnabled(false);
controlpad.joinGameButton.setEnabled(false);
controlpad.cancelGameButton.setEnabled(true);
chesspad.chessthread.sendMessage("/creatgame "+"[inchess]"+chessClientName);
}
}
else
{
isOnChess=true;
isServer=true;
controlpad.creatGameButton.setEnabled(false);
controlpad.joinGameButton.setEnabled(false);
controlpad.cancelGameButton.setEnabled(true);
chesspad.chessthread.sendMessage("/creatgame "+"[inchess]"+chessClientName);
}
}
catch(Exception ec)
{
isGameConnected=false;
isOnChess=false;
isServer=false;
controlpad.creatGameButton.setEnabled(true);
controlpad.joinGameButton.setEnabled(true);
controlpad.cancelGameButton.setEnabled(false);
ec.printStackTrace();
chatpad.chatLineArea.setText("chesspad.connectServer无法连接 \n"+ec);
}
}
if(e.getSource()==controlpad.cancelGameButton)
{
if(isOnChess)
{
chesspad.chessthread.sendMessage("/giveup "+chessClientName);
chesspad.chessVictory(-1*chesspad.chessColor);
controlpad.creatGameButton.setEnabled(true);
controlpad.joinGameButton.setEnabled(true);
controlpad.cancelGameButton.setEnabled(false);
chesspad.statusText.setText("请建立游戏或者加入游戏");
}
if(!isOnChess)
{
controlpad.creatGameButton.setEnabled(true);
controlpad.joinGameButton.setEnabled(true);
controlpad.cancelGameButton.setEnabled(false);
chesspad.statusText.setText("请建立游戏或者加入游戏");
}
isClient=isServer=false;
}
}
public void keyPressed(KeyEvent e)
{
TextField inputWords=(TextField)e.getSource();
if(e.getKeyCode()==KeyEvent.VK_ENTER)
{
if(inputpad.userChoice.getSelectedItem().equals("所有人"))
{
try
{
out.writeUTF(inputWords.getText());
inputWords.setText("");
}
catch(Exception ea)
{
chatpad.chatLineArea.setText("chessClient:KeyPressed无法连接,建议重新连接 \n");
userpad.userList.removeAll();
inputpad.userChoice.removeAll();
inputWords.setText("");
controlpad.connectButton.setEnabled(true);
}
}
else
{
try
{
out.writeUTF("/"+inputpad.userChoice.getSelectedItem()+" "+inputWords.getText());
inputWords.setText("");
}
catch(Exception ea)
{
chatpad.chatLineArea.setText("chessClient:KeyPressed无法连接,建议重新连接 \n");
userpad.userList.removeAll();
inputpad.userChoice.removeAll();
inputWords.setText("");
controlpad.connectButton.setEnabled(true);
}
}
}
}
public void keyTyped(KeyEvent e)
{
}
public void keyReleased(KeyEvent e)
{
}
public static void main(String args[])
{
chessClient chessClient=new chessClient();
}
}
/******************************************************************************************
下面是:chessInteface.java
******************************************************************************************/
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
class userPad extends Panel
{
List userList=new List(10);
userPad()
{
setLayout(new BorderLayout());
for(int i=0;i<50;i++)
{
userList.add(i+"."+"没有用户");
}
add(userList,BorderLayout.CENTER);
}
}
class chatPad extends Panel
{
TextArea chatLineArea=new TextArea("",18,30,TextArea.SCROLLBARS_VERTICAL_ONLY);
chatPad()
{
setLayout(new BorderLayout());
add(chatLineArea,BorderLayout.CENTER);
}
}
class controlPad extends Panel
{
Label IPlabel=new Label("IP",Label.LEFT);
TextField inputIP=new TextField("localhost",10);
Button connectButton=new Button("连接主机");
Button creatGameButton=new Button("建立游戏");
Button joinGameButton=new Button("加入游戏");
Button cancelGameButton=new Button("放弃游戏");
Button exitGameButton=new Button("关闭程序");
controlPad()
{
setLayout(new FlowLayout(FlowLayout.LEFT));
setBackground(Color.pink);
add(IPlabel);
add(inputIP);
add(connectButton);
add(creatGameButton);
add(joinGameButton);
add(cancelGameButton);
add(exitGameButton);
}
}
class inputPad extends Panel
{
TextField inputWords=new TextField("",40);
Choice userChoice=new Choice();
inputPad()
{
setLayout(new FlowLayout(FlowLayout.LEFT));
for(int i=0;i<50;i++)
{
userChoice.addItem(i+"."+"没有用户");
}
userChoice.setSize(60,24);
add(userChoice);
add(inputWords);
}
}
/**********************************************************************************************
下面是:chessPad.java
**********************************************************************************************/
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.util.*;
class chessThread extends Thread
{
chessPad chesspad;
chessThread(chessPad chesspad)
{
this.chesspad=chesspad;
}
public void sendMessage(String sndMessage)
{
try
{
chesspad.outData.writeUTF(sndMessage);
}
catch(Exception ea)
{
System.out.println("chessThread.sendMessage:"+ea);
}
}
public void acceptMessage(String recMessage)
{
if(recMessage.startsWith("/chess "))
{
StringTokenizer userToken=new StringTokenizer(recMessage," ");
String chessToken;
String[] chessOpt={"-1","-1","0"};
int chessOptNum=0;
while(userToken.hasMoreTokens())
{
chessToken=(String)userToken.nextToken(" ");
if(chessOptNum>=1 && chessOptNum<=3)
{
chessOpt[chessOptNum-1]=chessToken;
}
chessOptNum++;
}
chesspad.netChessPaint(Integer.parseInt(chessOpt[0]),Integer.parseInt(chessOpt[1]),Integer.parseInt(chessOpt[2]));
}
else if(recMessage.startsWith("/yourname "))
{
chesspad.chessSelfName=recMessage.substring(10);
}
else if(recMessage.equals("/error"))
{
chesspad.statusText.setText("错误:没有这个用户,请退出程序,重新加入");
}
else
{
//System.out.println(recMessage);
}
}
public void run()
{
String message="";
try
{
while(true)
{
message=chesspad.inData.readUTF();
acceptMessage(message);
}
}
catch(IOException es)
{
}
}
}
class chessPad extends Panel implements MouseListener,ActionListener
{
int chessPoint_x=-1,chessPoint_y=-1,chessColor=1;
int chessBlack_x[]=new int[200];
int chessBlack_y[]=new int[200];
int chessWhite_x[]=new int[200];
int chessWhite_y[]=new int[200];
int chessBlackCount=0,chessWhiteCount=0;
int chessBlackWin=0,chessWhiteWin=0;
boolean isMouseEnabled=false,isWin=false,isInGame=false;
TextField statusText=new TextField("请先连接服务器");
Socket chessSocket;
DataInputStream inData;
DataOutputStream outData;
String chessSelfName=null;
String chessPeerName=null;
String host=null;
int port=4331;
chessThread chessthread=new chessThread(this);
chessPad()
{
setSize(440,440);
setLayout(null);
setBackground(Color.pink);
addMouseListener(this);
add(statusText);
statusText.setBounds(40,5,360,24);
statusText.setEditable(false);
}
public boolean connectServer(String ServerIP,int ServerPort) throws Exception
{
try
{
chessSocket=new Socket(ServerIP,ServerPort);
inData=new DataInputStream(chessSocket.getInputStream());
outData=new DataOutputStream(chessSocket.getOutputStream());
chessthread.start();
return true;
}
catch(IOException ex)
{
statusText.setText("chessPad:connectServer:无法连接 \n");
}
return false;
}
public void chessVictory(int chessColorWin)
{
this.removeAll();
for(int i=0;i<=chessBlackCount;i++)
{
chessBlack_x[i]=0;
chessBlack_y[i]=0;
}
for(int i=0;i<=chessWhiteCount;i++)
{
chessWhite_x[i]=0;
chessWhite_y[i]=0;
}
chessBlackCount=0;
chessWhiteCount=0;
add(statusText);
statusText.setBounds(40,5,360,24);
if(chessColorWin==1)
{ chessBlackWin++;
statusText.setText("黑棋胜,黑:白为"+chessBlackWin+":"+chessWhiteWin+",重新开局,等待白棋下子...");
}
else if(chessColorWin==-1)
{
chessWhiteWin++;
statusText.setText("白棋胜,黑:白为"+chessBlackWin+":"+chessWhiteWin+",重新开局,等待黑棋下子...");
}
}
public void getLocation(int a,int b,int color)
{
if(color==1)
{
chessBlack_x[chessBlackCount]=a*20;
chessBlack_y[chessBlackCount]=b*20;
chessBlackCount++;
}
else if(color==-1)
{
chessWhite_x[chessWhiteCount]=a*20;
chessWhite_y[chessWhiteCount]=b*20;
chessWhiteCount++;
}
}
public boolean checkWin(int a,int b,int checkColor)
{
int step=1,chessLink=1,chessLinkTest=1,chessCompare=0;
if(checkColor==1)
{
chessLink=1;
for(step=1;step<=4;step++)
{
for(chessCompare=0;chessCompare<=chessBlackCount;chessCompare++)
{
if(((a+step)*20==chessBlack_x[chessCompare]) && ((b*20)==chessBlack_y[chessCompare]))
{
chessLink=chessLink+1;
if(chessLink==5)
{
return(true);
}
}
}
if(chessLink==(chessLinkTest+1))
chessLinkTest++;
else
break;
}
for(step=1;step<=4;step++)
{
for(chessCompare=0;chessCompare<=chessBlackCount;chessCompare++)
{
if(((a-step)*20==chessBlack_x[chessCompare]) && (b*20==chessBlack_y[chessCompare]))
{
chessLink++;
if(chessLink==5)
{
return(true);
}
}
}
if(chessLink==(chessLinkTest+1))
chessLinkTest++;
else
break;
}
chessLink=1;
chessLinkTest=1;
for(step=1;step<=4;step++)
{
for(chessCompare=0;chessCompare<=chessBlackCount;chessCompare++)
{
if((a*20==chessBlack_x[chessCompare]) && ((b+step)*20==chessBlack_y[chessCompare]))
{
❺ 求一个简单又有趣的JAVA小游戏代码
具体如下:
连连看的小源码
package Lianliankan;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class lianliankan implements ActionListener
{
JFrame mainFrame; //主面板
Container thisContainer;
JPanel centerPanel,southPanel,northPanel; //子面板
JButton diamondsButton[][] = new JButton[6][5];//游戏按钮数组
JButton exitButton,resetButton,newlyButton; //退出,重列,重新开始按钮
JLabel fractionLable=new JLabel("0"); //分数标签
JButton firstButton,secondButton; //
分别记录两次被选中的按钮
int grid[][] = new int[8][7];//储存游戏按钮位置
static boolean pressInformation=false; //判断是否有按钮被选中
int x0=0,y0=0,x=0,y=0,fristMsg=0,secondMsg=0,validateLV; //游戏按钮的位置坐标
int i,j,k,n;//消除方法控制
代码(code)是程序员用开发工具所支持的语言写出来的源文件,是一组由字符、符号或信号码元以离散形式表示信息的明确的规则体系。
对于字符和Unicode数据的位模式的定义,此模式代表特定字母、数字或符号(例如 0x20 代表一个空格,而 0x74 代表字符“t”)。一些数据类型每个字符使用一个字节;每个字节可以具有 256 个不同的位模式中的一个模式。
在计算机中,字符由不同的位模式(ON 或 OFF)表示。每个字节有 8 位,这 8 位可以有 256 种不同的 ON 和 OFF 组合模式。对于使用 1 个字节存储每个字符的程序,通过给每个位模式指派字符可表示最多 256 个不同的字符。2 个字节有 16 位,这 16 位可以有 65,536 种唯一的 ON 和 OFF 组合模式。使用 2 个字节表示每个字符的程序可表示最多 65,536 个字符。
单字节代码页是字符定义,这些字符映射到每个字节可能有的 256 种位模式中的每一种。代码页定义大小写字符、数字、符号以及 !、@、#、% 等特殊字符的位模式。每种欧洲语言(如德语和西班牙语)都有各自的单字节代码页。
虽然用于表示 A 到 Z 拉丁字母表字符的位模式在所有的代码页中都相同,但用于表示重音字符(如"é"和"á")的位模式在不同的代码页中却不同。如果在运行不同代码页的计算机间交换数据,必须将所有字符数据由发送计算机的代码页转换为接收计算机的代码页。如果源数据中的扩展字符在接收计算机的代码页中未定义,那么数据将丢失。
如果某个数据库为来自许多不同国家的客户端提供服务,则很难为该数据库选择这样一种代码页,使其包括所有客户端计算机所需的全部扩展字符。而且,在代码页间不停地转换需要花费大量的处理时间。
❻ 求一个简单的JAVA游戏代码,100行左右,谢谢!
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Painter extends JFrame{
/**
*
*/
private static final long serialVersionUID = 8160427604782702376L;
CanvasPanel canvas = new CanvasPanel();;
public Painter() {
super("Star");
this.add(canvas);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.pack();
this.setResizable(false);
this.setLocationRelativeTo(null);
this.setVisible(true);
}
public static void main(String[] args) {
new Painter();
}
}
class CanvasPanel extends JPanel implements ActionListener{
/**
*
*/
private static final long serialVersionUID = -464252885453878L;
private JButton[] btn = new JButton[4];
private String[] btn_name = {"+", "-", "R", "L"};
private int center_x = 200, center_y = 200, radius = 100, degree = 0;
public CanvasPanel() {
this.setPreferredSize(new Dimension(400, 500));
this.setLayout(null);
for(int i = 0; i < 4; i++) {
btn[i] = new JButton(btn_name[i]);
btn[i].setBounds(160 + i * 60, 425, 50, 50);
btn[i].addActionListener(this);
this.add(btn[i]);
}
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
for(int i = 0; i < 5; i++) {
g.drawLine( (int) (center_x + radius * Math.sin(Math.toRadians(degree + 72 * i))),
(int) (center_y - radius * Math.cos(Math.toRadians(degree + 72 * i))),
(int) (center_x + radius * Math.sin(Math.toRadians(degree + 72 * i + 144))),
(int) (center_y - radius * Math.cos(Math.toRadians(degree + 72 * i + 144))));
}
}
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getActionCommand() == "+") {
if(radius < 200)
radius += 2;
repaint();
} else if(e.getActionCommand() == "-") {
if(radius > 0)
radius -= 2;
repaint();
} else if(e.getActionCommand() == "R") {
degree = (degree + 2) % 360;
repaint();
} else if(e.getActionCommand() == "L") {
degree = (degree - 2) % 360;
repaint();
}
}
}
❼ 求java小游戏源代码
[最佳答案] 连连看java源代码 import javax.swing.*; import java.awt.*; import java.awt.event.*; pu... int x0=0,y0=0,x=0,y=0,fristMsg=0,secondMsg=0,validateLV; //游戏按钮的位...
❽ 姹俲ava灏忔父鎴忔簮浠g爜
import java.applet.Applet;
import java.applet.AudioClip;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioSystem;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Rectangle;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JSlider;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.io.File;
import java.util.Vector;
public class Frame extends JFrame implements Runnable {
JPanel contentPane;
JPanel jPanel1 = new JPanel();
JButton jButton1 = new JButton();
JSlider jSlider1 = new JSlider();
JLabel jLabel1 = new JLabel();
JButton jButton2 = new JButton();
JLabel jLabel2 = new JLabel();
int count = 1, rapidity = 80; // count 褰揿墠杩涜岀殑涓鏁, rapidity 娓告爣镄勪綅缃
int zhengque = 0, cuowu = 0;
int rush[] = { 10 ,20 ,30 }; //娓告垙姣忓叧镄勪釜鏁 鍙浠ヨ嚜鐢辨坊锷.鍒 { 10 ,20 ,30 ,40,50}
int rush_count = 0; //璁板綍鍏虫暟
char list[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y',
'Z', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; //闅忔満鍑虹幇镄勬暟瀛 鍙浠ヨ嚜鐢辨坊锷
Vector number = new Vector();
String paian = "true";
AudioClip Musci_anjian, Music_shi, Music_chenggong;
public Frame() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
//-----------------澹伴煶鏂囦欢---------------------
Musci_anjian = Applet.newAudioClip(new File("sounds//anjian.wav")
.toURL());
Music_shi = Applet.newAudioClip(new File("sounds//shi.wav")
.toURL());
Music_chenggong = Applet.newAudioClip(new File(
"sounds//chenggong.wav").toURL());
//---------------------------------------
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
/**
* Component initialization.
*
* @throws java.lang.Exception
*/
private void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(null);
setSize(new Dimension(588, 530));
setTitle("Frame Title");
jPanel1.setBorder(BorderFactory.createEtchedBorder());
jPanel1.setBounds(new Rectangle(4, 4, 573, 419));
jPanel1.setLayout(null);
jButton1.setBounds(new Rectangle(277, 442, 89, 31));
jButton1.setText("寮濮");
jButton1.addActionListener(new Frame1_jButton1_actionAdapter(this));
jSlider1.setBounds(new Rectangle(83, 448, 164, 21));
jSlider1.setMaximum(100);
jSlider1.setMinimum(1);
jSlider1.setValue(50);
jLabel1.setText("阃熷害");
jLabel1.setBounds(new Rectangle(35, 451, 39, 18));
jButton2.setBounds(new Rectangle(408, 442, 89, 31));
jButton2.setText("缁撴潫");
jButton2.addActionListener(new Frame1_jButton2_actionAdapter(this));
jLabel2.setText("绗涓鍏:100涓");
jLabel2.setBounds(new Rectangle(414, 473, 171, 21));
contentPane.add(jPanel1);
contentPane.add(jButton2);
contentPane.add(jButton1);
contentPane.add(jSlider1);
contentPane.add(jLabel1);
contentPane.add(jLabel2);
this.addKeyListener(new MyListener());
jButton1.addKeyListener(new MyListener());
jSlider1.addKeyListener(new MyListener());
jSlider1.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
rapidity = jSlider1.getValue();
}
});
}
public void run() {
number.clear();
zhengque = 0;
cuowu = 0;
paian = "true";
while (count <= rush[rush_count]) {
try {
Thread t = new Thread(new Tthread());
t.start();
count += 1;
Thread.sleep(1000 + (int) (Math.random() * 2000)); // 鐢熶骇涓嬬粍锅滈】镞堕棿
// 链蹇1蹇.链鎱2绉
} catch (InterruptedException e) {
e.printStackTrace();
}
}
while (true) { // 绛夊緟链钖庝竴涓瀛楃︽秷澶
if (number.size() == 0) {
break;
}
}
if (zhengque == 0) { // 涓轰简浠ュ悗鐩搁櫎..濡傛灉鍏ㄩ儴姝g‘鎴栬呴敊璇灏变细鍑虹幇阌栾. 镓浠..
zhengque = 1;
}
if (cuowu == 0) {
cuowu = 1;
}
if (paian.equals("true")) { // 鍒ゆ柇鏄钖︽槸镊铹剁粨𨱒
if (zhengque / cuowu >= 2) {
JOptionPane.showMessageDialog(null, "鎭锽滀綘杩囧叧浜");
rush_count += 1; // 镊锷ㄥ姞1鍏
if (rush_count < rush.length) {
if (rapidity > 10) { // 褰挞熷害澶т簬10镄勬椂鍊椤湪-5鎻愬姞阃熷害.镐曢熷害澶蹇
rapidity -= 5; // 阃熷害镊锷ㄥ噺10姣绉
jSlider1.setValue(rapidity); // 阃夋嫨浣岖疆
}
Thread t = new Thread(this);
t.start();
} else {
JOptionPane.showMessageDialog(null, "鐗汢...浣犻氩叧浜..");
rush_count = 0;
count = 0;
}
} else {
JOptionPane.showMessageDialog(null, "璇峰啀鎺ュ啀锷");
rush_count = 0;
count = 0;
}
} else {
rush_count = 0;
count = 0;
}
}
public void jButton1_actionPerformed(ActionEvent e) {
Thread t = new Thread(this);
t.start();
}
public void jButton2_actionPerformed(ActionEvent e) {
count = rush[rush_count] + 1;
paian = "flase";
}
class Tthread implements Runnable {
public void run() {
boolean fo = true;
int Y = 0, X = 0;
JLabel show = new JLabel();
show.setFont(new java.awt.Font("瀹嬩綋", Font.PLAIN, 33));
jPanel1.add(show);
X = 10 + (int) (Math.random() * 400);
String parameter = list[(int) (Math.random() * list.length)] + "";
Bean bean = new Bean();
bean.setParameter(parameter);
bean.setShow(show);
number.add(bean);
show.setText(parameter);
while (fo) {
// ---------------------鏁板瓧涓嬬Щ--------------------
show.setBounds(new Rectangle(X, Y += 2, 33, 33));
try {
Thread.sleep(rapidity);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (Y >= 419) {
fo = false;
for (int i = number.size() - 1; i >= 0; i--) {
Bean bn = ((Bean) number.get(i));
if (parameter.equalsIgnoreCase(bn.getParameter())) {
cuowu += 1;
jLabel2.setText("姝g‘:" + zhengque + "涓,阌栾:" + cuowu
+ "涓");
number.removeElementAt(i);
Music_shi.play();
break;
}
}
}
}
}
}
class MyListener extends KeyAdapter {
public void keyPressed(KeyEvent e) {
String uu = e.getKeyChar() + "";
for (int i = 0; i < number.size(); i++) {
Bean bean = ((Bean) number.get(i));
if (uu.equalsIgnoreCase(bean.getParameter())) {
zhengque += 1;
number.removeElementAt(i);
bean.getShow().setVisible(false);
jLabel2.setText("姝g‘:" + zhengque + "涓,阌栾:" + cuowu + "涓");
Music_chenggong.play();
break;
}
}
Musci_anjian.play();
}
}
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception exception) {
exception.printStackTrace();
}
Frame frame = new Frame();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
frame.setLocation((screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
frame.setVisible(true);
}
}
class Frame1_jButton2_actionAdapter implements ActionListener {
private Frame adaptee;
Frame1_jButton2_actionAdapter(Frame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
class Frame1_jButton1_actionAdapter implements ActionListener {
private Frame adaptee;
Frame1_jButton1_actionAdapter(Frame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
class Bean {
String parameter = null;
JLabel show = null;
public JLabel getShow() {
return show;
}
public void setShow(JLabel show) {
this.show = show;
}
public String getParameter() {
return parameter;
}
public void setParameter(String parameter) {
this.parameter = parameter;
}
}