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

定制建站费用3500元

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

成都品牌网站建设

品牌网站建设费用6000元

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

成都商城网站建设

商城网站建设费用8000元

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

成都微信网站建设

手机微信网站建站3000元

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

建站知识

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

java打地鼠简易代码 java打地鼠简易代码是什么

Java 打地鼠游戏如何实现多个老鼠同时出现

public class Game extends Thread{

站在用户的角度思考问题,与客户深入沟通,找到井冈山网站设计与井冈山网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:成都做网站、网站设计、企业官网、英文网站、手机端网站、网站推广、空间域名、网站空间、企业邮箱。业务覆盖井冈山地区。

/**

* @param args

*/

String [][] gameMap = new String[3][3];

public static void main(String[] args) {

// TODO Auto-generated method stub

new Game().start();

}

public void initMap()

{

for (int i = 0; i gameMap.length; i++) {

for (int j = 0; j gameMap[0].length; j++) {

gameMap[i][j] = new String();

gameMap[i][j] = "O" ; //洞,表示没有老鼠出来

}

}

}

public void printMap()

{

for (int i = 0; i gameMap.length; i++) {

for (int j = 0; j gameMap[0].length; j++) {

System.out.print(gameMap[i][j]);

}

System.out.println();

}

}

public void run()

{

int temp = 0 ;

while(true)

{

initMap();

for (int i = 0; i gameMap.length; i++) {

for (int j = 0; j gameMap[0].length; j++) {

temp = (int)(100 * Math.random());

if(temp=20) //可以调整,让老鼠出现的概率降低一些

gameMap[i][j] = "@"; //有老鼠出现

}

}

printMap();

try {

Thread.sleep(1000);

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

System.out.println();

}

}

}

呵呵,线程加数组就可以了,但是不知道能不能满足你的要求。截图如下:

java入门程序,简易打地鼠。

增加一个count计数,用来统计打中的次数。

点击一个button的时候,判断当前点击的button的颜色是不是红色,如果是,count++

基于Java语言的打地鼠的小游戏源代码是什么?

 public void mouseClicked(MouseEvent e){\x0d\x0aObject source=e.getSource(); //获取事件源,即地鼠标签\x0d\x0aif(source instanceof JLabel){ //如果事件是标签组件\x0d\x0aJLabel mouse=(JLabel)source; //强制转换为JLabel标签\x0d\x0amouse.setIcon(null); //取消标签图标\x0d\x0a}\x0d\x0a}\x0d\x0a});\x0d\x0athis.getContentPane().add(mouses[i]); //添加显示地鼠的标签到窗体\x0d\x0a}\x0d\x0a\x0d\x0amouses[0].setLocation(253, 300); //设置每个标签的位置\x0d\x0amouses[1].setLocation(333, 250);\x0d\x0amouses[2].setLocation(388, 296);\x0d\x0amouses[3].setLocation(362, 364);\x0d\x0amouses[4].setLocation(189, 353);\x0d\x0amouses[5].setLocation(240, 409);\x0d\x0a\x0d\x0afinal JLabel backLabel=new JLabel(); //创建显示背景的标签\x0d\x0abackLabel.setBounds(0, 0, img.getIconWidth(), img.getIconHeight());\x0d\x0athis.setBounds(100,100,img.getIconWidth(),img.getIconHeight());\x0d\x0abackLabel.setIcon(img); //添加背景到标签\x0d\x0athis.getContentPane().add(backLabel); //添加背景标签到窗体\x0d\x0a}\x0d\x0a/**\x0d\x0a* 线程的核心方法\x0d\x0a*/\x0d\x0a\x0d\x0apublic void run(){\x0d\x0awhile(true){ //使用无限循环\x0d\x0atry{\x0d\x0aThread.sleep(3000); //使线程休眠3秒\x0d\x0aint index=(int)(Math.random()*6); //生成随机的地鼠索引\x0d\x0aif(mouses[index].getIcon()==null){ //如果地鼠标签没有设置图片\x0d\x0amouses[index].setIcon(imgMouse); //为该标签添加地鼠图片\x0d\x0a}\x0d\x0a}catch(InterruptedException e){\x0d\x0ae.printStackTrace();\x0d\x0a}\x0d\x0a}\x0d\x0a}\x0d\x0a\x0d\x0a}

求java 比较简单的程序设计!要有注释的。

给个打地鼠游戏给你吧,图片路径自己改下:

import javax.swing.*;

import javax.swing.text.Position;

import javax.swing.text.AbstractDocument.Content;

import com.briup.gui1.GridLayoutTest;

import java.awt.*;

import java.awt.event.*;

public class MousePlay extends JFrame implements ActionListener {

private Container contentPane;

private JComboBox level;

private JLabel centLb1, timeLb1;

private JButton startBtn;

// 九个老鼠洞

private JButton[] btns;

// 两个计时器,一个计时,一个老鼠移动的位置

private Timer timer, postion;

//

private ImageIcon image;

//

private int index;

private boolean flag;

public MousePlay(){

this.setTitle("打地鼠");

this.setBounds(200, 200, 350, 400);

contentPane = this.getContentPane();

this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);

//计时器在初始化的时候,需要指定触发的事件间隔(单位ms),并且添加AtionListener

timer = new Timer(1000, this);

postion = new Timer(700, this);

//导入图片的路径

image = new ImageIcon("src/com/briup/gui2/mouse.jpg");

//image = new ImageIcon("/home/briup/mouse.jpg");

initGui();

}

public  void initGui() {

contentPane.setLayout(new BorderLayout());

JPanel north = new JPanel();

level = new JComboBox(new String[]{"easy", "so-so", "hard"});

level.addItemListener(new ItemListener(){

public void itemStateChanged(ItemEvent e) {

Object obj = e.getItem();

int time = 0;

if("easy".equals(obj)){

time = 700;

}else if("so-so".equals(obj)){

time = 400;

}else if("hard".equals(obj)){

time = 100;

}

postion = new Timer(time, MousePlay.this);

}});

timeLb1 = new JLabel("10");

centLb1 = new JLabel("0");

startBtn = new JButton("start");

startBtn.addActionListener(this);

north.add(level);

north.add(new JLabel("time:"));

north.add(timeLb1);

north.add(new JLabel("center:"));

north.add(centLb1);

north.add(startBtn);

contentPane.add(north,BorderLayout.NORTH);

JPanel center = new JPanel();

center.setLayout(new GridLayout(3, 3));

btns = new JButton[9];

for(int i=0; ibtns.length;i++){

btns[i] = new JButton("");

btns[i].setEnabled(false);

btns[i].addActionListener(this);

center.add(btns[i]);

}

contentPane.add(center,BorderLayout.CENTER);

}

public void go(){

this.setVisible(true);

}

public void actionPerformed(ActionEvent e) {

Object obj = e.getSource();

if(obj==startBtn){

startBtn.setEnabled(false); //开始按钮不可操作

level.setEditable(false); // 下拉框不可操作

for(int i=0; ibtns.length; i++)

btns[i].setEnabled(true); //九个按钮可以操作

//启动倒计时计时器和老鼠

timer.start();

postion.start();

timeLb1.setText("10");

centLb1.setText("0");

}

if(obj==timer){ // 先获得页面的值,然后判断是否为0,处理相应的逻辑

int time = Integer.parseInt(timeLb1.getText().trim());

if(time==0){

timeLb1.setText("game over!");

timer.stop();

postion.stop();

startBtn.setEnabled(true);

level.setEnabled(true);

for(int i=0; ibtns.length; i++){

btns[i].setEnabled(false);

btns[i].setIcon(null);

btns[i].setText("");

}

}else{

timeLb1.setText(--time+"");

}

}

if(obj==postion){

for(int i=0; ibtns.length; i++)

btns[i].setIcon(null);

index = (int)(Math.random()*9);

btns[index].setIcon(image);

//btns[index].setText("");

flag = false;

}

for(int i=0; ibtns.length; i++){

if(btns[i]==obj(!flag)i==index){

int cent = Integer.parseInt(centLb1.getText().trim());

centLb1.setText(++cent+"");

flag = true;

}

}

}

public static void main(String[] args) {

new MousePlay().go();

}

网上下的java手机游戏源码怎么用Eclipse在电脑上运行?

需要在eclipse中进行配置

工具:

eclipse

方法如下:

在eclipse中,鼠标放在一个android提供的类上,按下ctrl键,会打开一个新页面,提示找不到对应的类的class或者源文件,点击attach source...

之后点击external folder...选择下载好的source位置,确定后就可以了.

用c#做打地鼠小游戏怎么写入计分的代码啊

你这是把九个按钮作为打击对象吧?那你就定义两个int全局变量啊啊a、b,timer1_Tick事件执行一次a++,按钮点击一次,判断如果背景图是地鼠 b++,最后在timer2_Tick触发的时候就知道地鼠出现次数a,和你打中的次数b了


网站题目:java打地鼠简易代码 java打地鼠简易代码是什么
标题链接:http://bjjierui.cn/article/hghigo.html

其他资讯