當前位置:首頁 » 編程語言 » java游戲代碼大全

java游戲代碼大全

發布時間: 2024-05-15 11:52:29

❶ 幾個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;
}
}

熱點內容
安卓導航怎麼會黑屏 發布:2024-11-27 18:17:19 瀏覽:394
編譯後代碼放在單片機哪個位置 發布:2024-11-27 18:12:01 瀏覽:458
linux紅帽安裝 發布:2024-11-27 18:01:53 瀏覽:827
手機編程藍牙 發布:2024-11-27 17:55:39 瀏覽:385
創維雲電視怎麼升級安卓系統 發布:2024-11-27 17:55:31 瀏覽:354
theisle游戲伺服器搭建 發布:2024-11-27 17:47:43 瀏覽:210
xshell解壓 發布:2024-11-27 17:35:14 瀏覽:359
ftp伺服器管理方法 發布:2024-11-27 17:24:48 瀏覽:975
微信視頻為什麼要緩存 發布:2024-11-27 17:18:18 瀏覽:250
招生宣傳片腳本 發布:2024-11-27 17:18:07 瀏覽:301