導航:首頁 > 編程語言 > 打地鼠java代碼

打地鼠java代碼

發布時間:2022-04-04 06:01:52

A. C語言編程打地鼠

剛寫好的,打地鼠小游戲。

功能:每三秒,會在游戲區域隨機位置刷出地鼠,滑鼠點擊地鼠,無論點中與否,地鼠都會立即刷新。

點中地鼠按你要求計分,點不中記錄失敗次數,3次失敗,游戲結束,顯示GAME OVER!

#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
#include<conio.h>
#include<time.h>
#include<string.h>
#include<malloc.h>
#definegSizek30//區域大小寬度
#definegSizeg20//區域大小高度
#definegBegin3//活動區域起始行
intmain()
{
intt=0,s0,s1,i,j,count=0,fen=0,row=0,clo=0;
chargameA[gSizeg][gSizek+1],fSave[10]={0};
SetConsoleTitle("打地鼠");
HANDLEhInput=GetStdHandle(STD_INPUT_HANDLE);//獲取標准輸入設備句柄
INPUT_RECORDinRec;
DWORDres;
COORDp0;
p0.X=0;
p0.Y=0;

srand(time(0));
s0=time(NULL);
strcpy(gameA[0],"GAME");
strcpy(gameA[1],"未命中次數:0,計分:000000");
for(i=gBegin-1;i<gSizeg;i++)
{
for(j=0;j<gSizek+1;j++)
{
if(i>gBegin-1&&i<gSizeg-1&&j>0&&j<gSizek-1)
gameA[i][j]='';
else
gameA[i][j]=4;
if(j==gSizek)
gameA[i][j]=0;
}
}
for(i=0;i<gSizeg;i++)
printf("%s ",gameA[i]);

while(1)
{

if(t>=3)
{
if(row>0&&clo>0)
gameA[row][clo]='';
row=rand()%(gSizeg-1);
clo=rand()%(gSizek-1);
s0=time(NULL);
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),p0);

if(row<3)
row=4;
if(clo<1)
clo=1;
gameA[row][clo]=2;
for(i=0;i<gSizeg;i++)
{
//gameA[i][gSizeg+1]=0;
printf("%s ",gameA[i]);
}

}
if(count==3)
{
p0.X=10;
p0.Y=8;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),p0);
printf("GAMEOVER!");
break;
}
s1=time(NULL);
t=s1-s0;
ReadConsoleInput(hInput,&inRec,1,&res);
if(inRec.EventType==MOUSE_EVENT&&inRec.Event.MouseEvent.dwButtonState==FROM_LEFT_1ST_BUTTON_PRESSED)//滑鼠左鍵
{
if(inRec.Event.MouseEvent.dwMousePosition.X==clo&&inRec.Event.MouseEvent.dwMousePosition.Y==row)
{

if(fen==0)
fen=1;
if(fen>999999)
fen=999999;
else
fen=fen*2;

sprintf(fSave,"%06d",fen);
gameA[1][18]=0;
strcat(gameA[1],fSave);
}
else
{
count++;
fen=0;
gameA[1][11]=count+'0';
}
t=4;
}
}
while(1);
return0;
}

B. 求手機觸屏打地鼠游戲java格式及調整手機屏幕亮度軟體java格式

有款觸摸屏打僵屍的java游戲,性質和打地鼠一樣,只是地鼠換成了僵屍,不知道你喜歡不喜歡。

觸摸屏的話選下載到電腦-360x640下載地址。

下載頁面:http://www.sjfan.com/game/java/8/2011/02/586.html

C. java打地鼠程序的問題 求大神指教

this.getClass().getResource("1.jpg")

返回null。。。

可以在這句前面,先把path打出來看看是不是存在1.jpg

Stringpath=this.getClass().getResource("").getPath();
System.out.println(newFile(path).getAbsolutePath());

D. 打地鼠游戲java編程,要整個程序代碼,謝謝

不好意思 我也不知道 也正在找

E. 求人解決java編程打地鼠的問題

好像有成員變數沒有初始化

F. 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();
}
}
}

呵呵,線程加數組就可以了,但是不知道能不能滿足你的要求。截圖如下:

G. java入門程序,簡易打地鼠。

增加一個count計數,用來統計打中的次數。
點擊一個button的時候,判斷當前點擊的button的顏色是不是紅色,如果是,count++

H. JAVA做的打地鼠小游戲,地鼠圖片上有黑色邊框,高手進

你做的是iptv游戲嗎 機頂盒游戲嗎 還是模擬器運行的啊

請提供更多詳細信息,方便問題定位朋友

I. java 砸地鼠代碼

//CatchMice.java
//還有部分功能未實現,自己去搞吧

import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.net.URL;
import javax.imageio.ImageIO;
import javax.swing.*;

public class CatchMice {
public static void main(String[] args) {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(new Mice().setUser("Haha"));
f.pack();
f.setResizable(false);
f.setLocationRelativeTo(null);
f.setVisible(true);
}
}

class Mice extends Canvas implements MouseListener,MouseMotionListener{
private String url="http://tbn1.google.cn/images?q=tbn:PsL93ZaiwcOVfM:";//老鼠圖片
private int index=-1;
private int score;
private int initDelay=2000;
private int delay = initDelay;
private int level = 1;
private int gradeScore=160;
private int caughtScore=10;
private Image mice;
private BufferedImage bimg;
private int cellW=80,cellH=80,r=4,c=4;//53
private Rectangle rec;
private String user;
private Thread t;
private long time;
private boolean pause,gameover;
public Mice(){
try{
bimg=ImageIO.read(new URL(url));
mice=bimg.getSubimage(0,0,cellW,cellH);
bimg=null;
}catch(Exception e){
if(bimg==null){
bimg=new BufferedImage(cellW,cellH,BufferedImage.TYPE_INT_ARGB);
Graphics2D g = bimg.createGraphics();
g.setColor(Color.LIGHT_GRAY);
g.drawOval(10,10,cellW-20,cellH-20);
g.dispose();
mice=bimg.getSubimage(0,0,cellW,cellH);
bimg=null;
}
};
setPreferredSize(new Dimension(cellW*c,cellH*r+60));
index=next();
rec = new Rectangle(0,0,cellW,cellH);
this.addMouseListener(this);
this.addMouseMotionListener(this);
}
public Mice setUser(String u){user=u;return this;}
private int next(){
int next = (int)(Math.random()*r*c);
return index==next?next():next;
}
public void paint(Graphics gg){
Graphics g=gg.create();
g.setColor(Color.white);
g.fillRect(0,0,cellW*c,cellH*r);
g.setColor(Color.gray);
for(int i=0; i<r*c; i++){
if(i==index){
g.drawImage(mice,i%c*cellW,i/r*cellH,this);
rec.setLocation(i%c*cellW,i/r*cellH);
}
g.drawRect(i%c*cellW,i/r*cellH,cellW,cellH);
}
g.setColor(Color.DARK_GRAY);
g.setColor(Color.blue);
String info = "User:"+user+" Level:"+level+" Score:"+score+" Delay:"+delay;
g.drawString(info,1,r*cellH+16);
g.dispose();
if(t==null){
start();
}
}
private void start(){
time = System.currentTimeMillis();
t=new Thread(){
public void run(){
while(true){
if(pause){
time=System.currentTimeMillis();
try{sleep(50);}catch(Exception e){}
continue;
}
if(!gameover&&time+delay<System.currentTimeMillis()){
gameOver();
}
if(!gameover)
drawTime();
else
drawGameOver();
try{sleep(50);}catch(Exception e){}
}
}
};
t.start();
}
private void drawGameOver() {
Graphics g = this.getGraphics();
g.setColor(Color.DARK_GRAY);
g.fillRect(0,r*cellH+18,80,18);
if(System.currentTimeMillis()%1000<500){
g.setColor(Color.yellow);
g.drawString("Game over!",4,r*cellH+32);
}
g.dispose();
}
private void drawTime() {
Graphics g = this.getGraphics();
long t = delay+time-System.currentTimeMillis();;
g.setColor(Color.DARK_GRAY);
g.fillRect(0,r*cellH+18,48,18);
g.setColor(Color.yellow);
g.drawString(""+t,4,r*cellH+32);
g.dispose();
}
private void gameOver() {
gameover=true;
index=-1;
repaint();
}
public void mouseClicked(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mousePressed(MouseEvent e) {
// if(!gameover&&rec.contains(e.getPoint())){
// index=next();
// time=System.currentTimeMillis();
// score+=caughtScore;
// level=score/gradeScore+1;
// delay=initDelay;
// for(int i=0; i<level-1; i++)
// delay=(int)(delay*2f/3);
// repaint();
// }
}
public void mouseReleased(MouseEvent e) {}
public void mouseDragged(MouseEvent e) {}
public void mouseMoved(MouseEvent e) {
if(!gameover&&rec.contains(e.getPoint())){
index=next();
time=System.currentTimeMillis();
score+=caughtScore;
level=score/gradeScore+1;
delay=initDelay;
for(int i=0; i<level-1; i++)
delay=(int)(delay*2f/3);
repaint();
}
}
}

J. java打地鼠游戲的源程序會用到數據結構嗎

只要是涉及到Map,List,Tree等等集合、列表之類的都算用到數據結構。
所以說一般稍復雜點的程序都會用到數據結構,我想你應該問的是如何用數據結構的思想去理解打地鼠游戲吧?
如果是面向對象語言編程的話,首先你需要將每個小鼠洞看做一個對象,將全部鼠洞設計成該對象的二維數組。然後你需要有隨機演算法來指定哪個鼠洞是否出現老鼠。然後還需要有觸發事件來確定錘子的擊打坐標。
真正要做出來要考慮還很多,希望你先理清思路然後由淺入深。

閱讀全文

與打地鼠java代碼相關的資料

熱點內容
優信二手車解壓後過戶 瀏覽:61
Windows常用c編譯器 瀏覽:778
關於改善國家網路安全的行政命令 瀏覽:833
安卓如何下載網易荒野pc服 瀏覽:654
javainetaddress 瀏覽:104
蘋果4s固件下載完了怎麼解壓 瀏覽:1002
命令zpa 瀏覽:285
python編譯器小程序 瀏覽:944
在app上看視頻怎麼光線調暗 瀏覽:540
可以中文解壓的解壓軟體 瀏覽:592
安卓卸載組件應用怎麼安裝 瀏覽:912
使用面向對象編程的方式 瀏覽:339
程序員項目經理的年終總結範文 瀏覽:929
內衣的加密設計用來幹嘛的 瀏覽:432
淮安數據加密 瀏覽:292
魔高一丈指標源碼 瀏覽:982
松下php研究所 瀏覽:168
c回調java 瀏覽:399
夢幻端游長安地圖互通源碼 瀏覽:745
電腦本地文件如何上傳伺服器 瀏覽:313