网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

简单推箱子java源代码,java课程设计推箱子

推箱子游戏java代码如何判断下一步是墙还是空地

1. 确定的功能:让玩家通过按上下左右键推箱子,当箱子们都推到了目的地后出现过关信息,并显示下一关。推错了玩家还按空格键从新玩过这关。直到过完全部关卡。

10年积累的成都网站建设、做网站经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站设计后付款的网站建设流程,更有贡觉免费网站建设让你可以放心的选择与我们合作。

2. 定义的核心数据结构:我们定义一个二维数组ghouse来记录屏幕上各点的状态。char ghouse[20][20]; 其中:0表示什么都没有,'b'表示箱子,'w'表示墙壁,'m'表示目的地,'i'表示箱子在目的地。

3. 对整个进行功能模块划分。

(1)。初始化:在屏幕上输出欢迎信息,把ghouse数组的元素初始化为0。并根据各关的要求在屏幕上输出墙、箱子、目的地和人。并用ghouse 数组记录各点的状态。

(2)。进入游戏循环:这个游戏主循环是等待按键。当接受到上下左右键时执行相关操作:接受ESC键时退出游戏;接受空格键时返回本关开头;接受无效按键时做忽略处理。重点介绍按上下左右键时如何执行相关操作。

(3)。判断是否过关:用一个链表win由每关的初始化函数传给main函数。Win链表主要记录屏幕上的哪些点是目的地,并记录目的地的位置。Main函数每执行一次操作后就判断屏幕上的目的地是不是都有箱子了。

用JAVA编写一个小程序 比如拼图游戏 推箱子 猜数字 。。。。。。请附详细注释 因为要发表 谢谢大家!

我写的一个猜数字游戏,希望对你有用,代码如下:

import java.awt.BorderLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.util.Random;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

import javax.swing.JScrollPane;

import javax.swing.JTextArea;

import javax.swing.JTextField;

public class GuessNumber {

static int trys, A, B;

static String r, t;

public static int[] MakeGuessNumber(){//随机生成一个无重复数字的四位数

Random r = new Random();

int guess[] = new int[4];

for(int i=0; i4; i++){

guess[i] = r.nextInt(10);

for(int j=i-1; j=0; j--){

if(guess[i]==guess[j]){

i--;

break;}

}

}

return guess;

}

public static String getRundom(){//将此四位数转化为字符串

int guess[]=MakeGuessNumber();

return ""+guess[0]+guess[1]+guess[2]+guess[3];

}

public static void messageDialog(Object o){

JOptionPane.showMessageDialog(null, o);

}

public static void guessNumber(){//主要算法实现部分

r=getRundom();

//System.out.println(r);

JFrame jf=new JFrame();

JButton b1=new JButton("新游戏");

JLabel l1=new JLabel("输入:");

final JTextField jtf=new JTextField(10);

JButton b2=new JButton("提交");

final JTextArea jta=new JTextArea(10,10);

jta.append(" "+"Guess"+" "+"Result"+"\n");

JScrollPane scrollPane=new JScrollPane(jta);

JPanel jp1=new JPanel();

jp1.add(l1);

jp1.add(jtf);

jp1.add(b2);

jf.add(b1,BorderLayout.NORTH);

jf.add(jp1,BorderLayout.CENTER);

jf.add(scrollPane,BorderLayout.SOUTH);

b1.addActionListener(new ActionListener(){

@Override

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

trys=0;

A=0;

B=0;

jta.setText(" "+"Guess"+" "+"Result"+"\n");

jtf.setText("");

r=getRundom();

//System.out.println(r);

}

});

b2.addActionListener(new ActionListener(){

@Override

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

t=jtf.getText();

A=0;

B=0;

if(t.length()!=4||t.substring(0, 1).equals(t.substring(1, 2))

||t.substring(0, 1).equals(t.substring(2, 3))

||t.substring(0, 1).equals(t.substring(3, 4))

||t.substring(1, 2).equals(t.substring(2, 3))

||t.substring(1, 2).equals(t.substring(3, 4))

||t.substring(2, 3).equals(t.substring(3, 4))

||!t.matches("[0-9]*"))

messageDialog("Wrong Input!");

else{

jtf.setText("");

trys++;

if(t.substring(0, 1).equals(r.substring(0, 1)))

A++;

if(t.substring(0, 1).equals(r.substring(1, 2)))

B++;

if(t.substring(0, 1).equals(r.substring(2, 3)))

B++;

if(t.substring(0, 1).equals(r.substring(3, 4)))

B++;

if(t.substring(1, 2).equals(r.substring(1, 2)))

A++;

if(t.substring(1, 2).equals(r.substring(0, 1)))

B++;

if(t.substring(1, 2).equals(r.substring(2, 3)))

B++;

if(t.substring(1, 2).equals(r.substring(3, 4)))

B++;

if(t.substring(2, 3).equals(r.substring(2, 3)))

A++;

if(t.substring(2, 3).equals(r.substring(0, 1)))

B++;

if(t.substring(2, 3).equals(r.substring(1, 2)))

B++;

if(t.substring(2, 3).equals(r.substring(3, 4)))

B++;

if(t.substring(3, 4).equals(r.substring(3, 4)))

A++;

if(t.substring(3, 4).equals(r.substring(0, 1)))

B++;

if(t.substring(3, 4).equals(r.substring(1, 2)))

B++;

if(t.substring(3, 4).equals(r.substring(2, 3)))

B++;

jta.append(trys+" "+t+" "+A+"A"+B+"B"+"\n");

if(A==4){

if(trys=4)

messageDialog("You win after "+trys+" trys!");

else if(trys=3)

messageDialog("You win after only "+trys+" trys!");

}

}

}

});

jf.setSize(300, 300);

jf.setVisible(true);

jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

public static void main(String args[]){

guessNumber();

}

}

我没有进行详细注释,这个程序挺好理解的,你可以自己再看一下

急需Java推箱子游戏代码

Newload()

{

jf1=new JFrame("猜数游戏");

jf2=new JFrame("猜数游戏");

jf3=new JFrame("猜数游戏");

jf1_title=new JLabel("猜数游戏-欢迎进入");

jf1_title.setFont(new Font("仿宋体",Font.BOLD,40));//设置字体大小,及文字字体

jf1_title.setHorizontalAlignment(JLabel.CENTER);

JLabel jf2title=new JLabel("猜数游戏");

jf2title.setFont(new Font("仿宋体",Font.BOLD,40));//设置字体大小,及文字字体

jf2title.setHorizontalAlignment(JLabel.CENTER);

jf1_username=new JLabel("用户名");

jf1_userpass=new JLabel("密码");

jf2_question=new JLabel("There is question which needs you to guess!");

jf2_question.setFont(new Font("仿宋体",Font.BOLD,20));//设置字体大小,及文字字体

jf2_question.setHorizontalAlignment(JLabel.CENTER);

jf2_rightface=new JLabel(iron1);

jf2_wrongface=new JLabel(iron2);

jf2_rightface.setVisible(false);

jf2_wrongface.setVisible(false);

jf2_reelresult=new JLabel();

jf3_pinyu=new JLabel("your result is");

jf1_usernameT=new JTextField(6);

jf2_anwser=new JTextField(6);

jf2_anwser.addActionListener(this);

jf1_password=new JPasswordField(6);

jf1_password.addActionListener(this);

jf1_ok=new JButton("确定");

jf1_ok.addActionListener(this);

jf1_quit=new JButton("退出");

jf1_quit.addActionListener(this);

jf2_newgame=new JButton("新游戏(k)");

jf2_newgame.setMnemonic(KeyEvent.VK_K);

jf2_newgame.addActionListener(this);

jf2_ok=new JButton("确定");

jf2_ok.addActionListener(this);

jf1.setLayout(new BorderLayout());

jf2.setLayout(new BorderLayout());

JPanel jf1p1=new JPanel(),jf2p1=new JPanel(),jf2p2=new JPanel(),jf2p3=new JPanel();

jf2p1.setLayout(new BorderLayout());

jf1p1.setLayout(new FlowLayout());

jf2p2.setLayout(new FlowLayout());

jf2p3.setLayout(new FlowLayout());

jf1.add(jf1_title,"Center");

jf1p1.add(jf1_username);jf1p1.add(jf1_usernameT);

jf1p1.add(jf1_userpass);jf1p1.add(jf1_password);

jf1p1.add(jf1_ok);jf1p1.add(jf1_quit);

jf1.add(jf1p1,"South");

jf2p2.add(jf2_rightface);

jf2p2.add(jf2_wrongface);

jf2p2.add(jf2_reelresult);

jf2p1.add(jf2p2,"South");

jf2p1.add(jf2_question);

jf2.add(jf2title,"North");

jf2.add(jf2p1,"Center");

jf2p3.add(jf2_ans);jf2p3.add(jf2_anwser);jf2p3.add(jf2_ok);jf2p3.add(jf2_newgame);

jf2.add(jf2p3,"South");

jf3.add(jf3_pinyu);

jf1.setSize(700,400);

jf2.setSize(700,400);

jf3.setSize(700,400);

jf1.setLocation(300,150);

jf2.setLocation(300,150);

jf3.setLocation(300,150);

jf1.setVisible(true);

jf2.setVisible(false);

jf3.setVisible(false);

jf1.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e) {

System.exit(0);

}

});

jf2.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e) {

System.exit(0);

}

});

}

public void actionPerformed(ActionEvent e) {

if(e.getSource()==jf1_ok||e.getSource()==jf1_password)

{char[] a=jf1_password.getPassword();String paas="";

for(int i=0;ia.length;i++)//JPasswordField是一种特殊的类只能得到char数组,将其转成String

paas=paas+a[i];

if(jf1_usernameT.getText().equals("user")paas.equals("pass"))

{jf2.setVisible(true);jf1.setVisible(false);

number=returnquestion();

jf2_anwser.requestFocus();

}

else

JOptionPane.showMessageDialog(null,"用户名不正确或密码错误!");

}

if(e.getSource()==jf1_quit)

{

System.exit(0);

}

if(e.getSource()==jf2_ok||e.getSource()==jf2_anwser)

{

if(times=5){

if(Integer.parseInt(jf2_anwser.getText())==number)

{

jf2_rightface.setVisible(true);

jf2_wrongface.setVisible(false);

jf2_reelresult.setText("you are right! and your have used "+times+" times!"

+((times=3)?"very good!":"pleas do more work for it"));

}

else

if(Integer.parseInt(jf2_anwser.getText())number)

{times++;

jf2_wrongface.setVisible(true);

jf2_rightface.setVisible(false);

jf2_reelresult.setText("your answer is bigger than the one produced by computer!"

+"and your have used "+times+" times!");

}

else

if(Integer.parseInt(jf2_anwser.getText())number)

{times++;

jf2_wrongface.setVisible(true);

jf2_rightface.setVisible(false);

jf2_reelresult.setText("your answer is smaller than the one produced by computer!"

+"and your have used "+times+" times!");

}

}

else

{JOptionPane.showMessageDialog(null,"你已经超过六次了,请重新开始吧!");}

jf2_anwser.requestFocus();

jf2_anwser.setText("");

}

if(e.getSource()==jf2_newgame)

{

number=returnquestion();

times=0;

jf2_rightface.setVisible(false);

jf2_wrongface.setVisible(false);

jf2_anwser.setText("");

jf2_reelresult.setText("");

jf2_anwser.requestFocus();

}

}

public static void main(String args[])

{

new Newload();

}

int returnquestion()

{

double db=Math.random()*100;

return (int)db;

}

}


网站标题:简单推箱子java源代码,java课程设计推箱子
标题路径:http://bjjierui.cn/article/hooipp.html

其他资讯