java小游戏求好玩的手机java小游戏?

java小游戏  时间:2021-09-12  阅读:()

新人Eclipse编写的Java小游戏

去百度文库,查看完整内容> 内容来自用户:uzvjy35 Eclipse编写的Java小游戏 初学java时编写的简单小游戏,非界面版,纯java基础组成,新人都能看得懂可以做的来,主要是其中的逻辑思想。

使用eclipse编程,直接建立一个java复制代码进去就可以了。

希望对大家学习java编程有点帮助游戏一:随即取5个数排列,要求猜出这5个数packageday; importjava.util.Random;importjava.util.Scanner;importjava.util.regex.Matcher;importjava.util.regex.Pattern; lassGame{ publicstaticvoidmain(String[]args){Randomr=newRandom();inta1=r.nextInt(10);inta2=r.nextInt(10);inta3=r.nextInt(10);inta4=r.nextInt(10);inta5=r.nextInt(10);System.out.println("游戏规则:随即取5个数,请输入5个数,数字顺序 要求一致,会告诉你答对几个,看你能在几次猜对");Scannerscan=newScanner(System.in);for(inti=1;;i++){intc=0;System.out.println("请输入5个数:");Stringdir=scan.nextLine();Patternpattern=pile("^[0-9]{5$");Matchermatcher=pattern.matcher(dir);if(matcher.find()){intb1=Integer.parseInt(dir.substring(0,1));intb2=Integer.parseInt(dir.substring(1,2));intb3=Integer.parseInt(dir.substring(2,3));intb4=Integer.parseInt(dir.substring(3,4));intb5=Integer.parseInt(dir.substring(4,5));

帮忙给个java小游戏源程序

这是一个贪食蛇的程序,仅供参考(多给点分吧,代码注释非常详细,给100分就很满足了): /************************************************************************** *要点分析: *1)主要部分已经集成为一个对象SnakeModel,利用键盘控制实现操作。

*************************************************************************/ import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.*; //============================================= //Main Class //============================================= public class GreedSnake implements KeyListener { JFrame mainFrame; Canvas paintCanvas; JLabel labelScore;//计分牌 SnakeModel snakeModel=null;// 蛇 public static final int canvasWidth=200; public static final int canvasHeight=300; public static final int nodeWidth=10; public static final int nodeHeight=10; //---------------------------------------------------------------------- //GreedSnake():初始化游戏界面 //---------------------------------------------------------------------- public GreedSnake() { //设置界面元素 mainFrame=new JFrame("GreedSnake"); Container cp=mainFrame.getContentPane(); labelScore=new JLabel("Score:"); cp.add(labelScore,BorderLayout.NORTH); paintCanvas=new Canvas(); paintCanvas.setSize(canvasWidth+1,canvasHeight+1); paintCanvas.addKeyListener(this); cp.add(paintCanvas,BorderLayout.CENTER); JPanel panelButtom=new JPanel(); panelButtom.setLayout(new BorderLayout()); JLabel labelHelp;// 帮助信息 labelHelp=new JLabel("PageUp, PageDown for speed;",JLabel.CENTER); panelButtom.add(labelHelp,BorderLayout.NORTH); labelHelp=new JLabel("ENTER or R or S for start;",JLabel.CENTER); panelButtom.add(labelHelp,BorderLayout.CENTER); labelHelp=new JLabel("SPACE or P for pause",JLabel.CENTER); panelButtom.add(labelHelp,BorderLayout.SOUTH); cp.add(panelButtom,BorderLayout.SOUTH); mainFrame.addKeyListener(this); mainFrame.pack(); mainFrame.setResizable(false); mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); mainFrame.setVisible(true); begin(); } //---------------------------------------------------------------------- //keyPressed():按键检测 //---------------------------------------------------------------------- public void keyPressed(KeyEvent e) { int keyCode=e.getKeyCode(); if(snakeModel.running) switch(keyCode) { case KeyEvent.VK_UP: snakeModel.changeDirection(SnakeModel.UP); break; case KeyEvent.VK_DOWN: snakeModel.changeDirection(SnakeModel.DOWN); break; case KeyEvent.VK_LEFT: snakeModel.changeDirection(SnakeModel.LEFT); break; case KeyEvent.VK_RIGHT: snakeModel.changeDirection(SnakeModel.RIGHT); break; case KeyEvent.VK_ADD: case KeyEvent.VK_PAGE_UP: snakeModel.speedUp();// 加速 break; case KeyEvent.VK_SUBTRACT: case KeyEvent.VK_PAGE_DOWN: snakeModel.speedDown();// 减速 break; case KeyEvent.VK_SPACE: case KeyEvent.VK_P: snakeModel.changePauseState();// 暂停或继续 break; default: } //重新开始 if(keyCode==KeyEvent.VK_R || keyCode==KeyEvent.VK_S || keyCode==KeyEvent.VK_ENTER) { snakeModel.running=false; begin(); } } //---------------------------------------------------------------------- //keyReleased():空函数 //---------------------------------------------------------------------- public void keyReleased(KeyEvent e) { } //---------------------------------------------------------------------- //keyTyped():空函数 //---------------------------------------------------------------------- public void keyTyped(KeyEvent e) { } //---------------------------------------------------------------------- //repaint():绘制游戏界面(包括蛇和食物) //---------------------------------------------------------------------- void repaint() { Graphics g=paintCanvas.getGraphics(); //draw background g.setColor(Color.WHITE); g.fillRect(0,0,canvasWidth,canvasHeight); //draw the snake g.setColor(Color.BLACK); LinkedList na=snakeModel.nodeArray; Iterator it=na.iterator(); while(it.hasNext()) { Node n=(Node)it.next(); drawNode(g,n); } // draw the food g.setColor(Color.RED); Node n=snakeModel.food; drawNode(g,n); updateScore(); } //---------------------------------------------------------------------- //drawNode():绘画某一结点(蛇身或食物) //---------------------------------------------------------------------- private void drawNode(Graphics g,Node n) { g.fillRect(n.x*nodeWidth,n.y*nodeHeight,nodeWidth-1,nodeHeight-1); } //---------------------------------------------------------------------- //updateScore():改变计分牌 //---------------------------------------------------------------------- public void updateScore() { String s="Score: "+snakeModel.score; labelScore.setText(s); } //---------------------------------------------------------------------- //begin():游戏开始,放置贪吃蛇 //---------------------------------------------------------------------- void begin() { if(snakeModel==null||!snakeModel.running) { snakeModel=new SnakeModel(this,canvasWidth/nodeWidth, this.canvasHeight/nodeHeight); (new Thread(snakeModel)).start(); } } //---------------------------------------------------------------------- //main():主函数 //---------------------------------------------------------------------- public static void main(String[] args) { GreedSnake gs=new GreedSnake(); } } /************************************************************************** *要点分析: *1)数据结构:matrix[][]用来存储地图上面的信息,如果什么也没有设置为false, * 如果有食物或蛇,设置为true;nodeArray,一个LinkedList,用来保存蛇的每 * 一节;food用来保存食物的位置;而Node类是保存每个位置的信息。

*2)重要函数: * changeDirection(int newDirection) ,用来改变蛇前进的方向,而且只是 * 保存头部的前进方向,因为其他的前进方向已经用位置来指明了。

其中newDirection * 必须和原来的direction不是相反方向,所以相反方向的值用了同样的奇偶性。

在测试 * 的时候使用了direction%2!=newDirection%2 进行判断。

* moveOn(),用来更新蛇的位置,对于当前方向,把头部位置进行相应改变。

如果越界, * 结束;否则,检测是否遇到食物(加头部)或身体(结束);如果什么都没有,加上头部, * 去掉尾部。

由于用了LinkedList数据结构,省去了相当多的麻烦。

*************************************************************************/ //---------------------------------------------------------------------- //Node:结点类 //---------------------------------------------------------------------- class Node { int x; int y; Node(int x,int y) { this.x=x; this.y=y; } } //---------------------------------------------------------------------- //SnakeModel:贪吃蛇模型 //---------------------------------------------------------------------- class SnakeModel implements Runnable { GreedSnake gs; boolean[][] matrix;// 界面数据保存在数组里 LinkedList nodeArray=new LinkedList(); Node food; int maxX;//最大宽度 int maxY;//最大长度 int direction=2;//方向 boolean running=false; int timeInterval=200;// 间隔时间(速度) double speedChangeRate=0.75;// 速度改变程度 boolean paused=false;// 游戏状态 int score=0; int countMove=0; // UP和DOWN是偶数,RIGHT和LEFT是奇数 public static final int UP=2; public static final int DOWN=4; public static final int LEFT=1; public static final int RIGHT=3; //---------------------------------------------------------------------- //GreedModel():初始化界面 //---------------------------------------------------------------------- public SnakeModel(GreedSnake gs,int maxX,int maxY) { this.gs=gs; this.maxX=maxX; this.maxY=maxY; matrix=new boolean[maxX][]; for(int i=0;i<maxX;++i) { matrix[i]=new boolean[maxY]; Arrays.fill(matrix[i],false);// 没有蛇和食物的地区置false } //初始化贪吃蛇 int initArrayLength=maxX>20 ? 10 : maxX/2; for(int i=0;i<initArrayLength;++i) { int x=maxX/2+i; int y=maxY/2; nodeArray.addLast(new Node(x,y)); matrix[x][y]=true;// 蛇身处置true } food=createFood(); matrix[food.x][food.y]=true;// 食物处置true } //---------------------------------------------------------------------- //changeDirection():改变运动方向 //---------------------------------------------------------------------- public void changeDirection(int newDirection) { if(direction%2!=newDirection%2)// 避免冲突 { direction=newDirection; } } //---------------------------------------------------------------------- //moveOn():贪吃蛇运动函数 //---------------------------------------------------------------------- public boolean moveOn() { Node n=(Node)nodeArray.getFirst(); int x=n.x; int y=n.y; switch(direction) { case UP: y--; break; case DOWN: y++; break; case LEFT: x--; break; case RIGHT: x++; break; } if((0<=x&&x<maxX)&&(0<=y&&y<maxY)) { if(matrix[x][y])// 吃到食物或者撞到身体 { if(x==food.x&&y==food.y)// 吃到食物 { nodeArray.addFirst(food);// 在头部加上一结点 //计分规则与移动长度和速度有关 int scoreGet=(10000-200*countMove)/timeInterval; score+=scoreGet>0 ? scoreGet : 10; countMove=0; food=createFood(); matrix[food.x][food.y]=true; return true; } else return false;// 撞到身体 } else//什么都没有碰到 { nodeArray.addFirst(new Node(x,y));// 加上头部 matrix[x][y]=true; n=(Node)nodeArray.removeLast();// 去掉尾部 matrix[n.x][n.y]=false; countMove++; return true; } } return false;//越界(撞到墙壁) } //---------------------------------------------------------------------- //run():贪吃蛇运动线程 //---------------------------------------------------------------------- public void run() { running=true; while(running) { try { Thread.sleep(timeInterval); }catch(Exception e) { break; } if(!paused) { if(moveOn())// 未结束 { gs.repaint(); } else//游戏结束 { JOptionPane.showMessageDialog(null,"GAME OVER", "Game Over",JOptionPane.INFORMATION_MESSAGE); break; } } } running=false; } //---------------------------------------------------------------------- //createFood():生成食物及放置地点 //---------------------------------------------------------------------- private Node createFood() { int x=0; int y=0; do { Random r=new Random(); x=r.nextInt(maxX); y=r.nextInt(maxY); }while(matrix[x][y]); return new Node(x,y); } //---------------------------------------------------------------------- //speedUp():加快蛇运动速度 //---------------------------------------------------------------------- public void speedUp() { timeInterval*=speedChangeRate; } //---------------------------------------------------------------------- //speedDown():放慢蛇运动速度 //---------------------------------------------------------------------- public void speedDown() { timeInterval/=speedChangeRate; } //---------------------------------------------------------------------- //changePauseState(): 改变游戏状态(暂停或继续) //---------------------------------------------------------------------- public void changePauseState() { paused=!paused; } }

Java手机游戏下载

上 找 手机业可以上 上后设你机型 你好!都是免费破解 游戏网站:绿游网爱爱机智能网天游网百分网泽乐网宝软网 泡椒网手机乐园小游戏掌上花园娱乐网八神网7723手机游戏电脑就去像塞班这种论坛下载就可以了!

无需注册,可以设定机型,设定机型之后可以自动识别自己的机型游戏,储存书签就你可以随心所欲的下载游戏了

希望能帮到你

JAVA版的什么游戏好玩

<仙剑传说>人气和评分都超高 仙剑传说游戏简介:这是一个讲述穿越时空的故事,故事发生在武周时期,我们的男主角郝仁,因死亡而意外穿越时空来到这个纷乱的世界,在那里他附身在一个伤重男人的身上,而救他的则是一个美丽的亡夫女人赵欣婷,既然就这样身处这个世界,那郝仁便决定随遇而安,并顺便追求这个漂亮的女人,但也因此享受到了帮赵欣婷报杀夫之仇的待遇,既然要帮那就帮到底,在帮赵欣婷报仇的途中发生了一系列有趣的事,法力比不过土地公的仙人找郝仁做什么?一向都是郝仁追求别人,为什么却会被人反追?仁慈的师父真正的身份是什么?最后杀夫之仇得报之时,却又发生了什么意外?

用java开发小游戏

  我给你个华容道的游戏参照下吧。

可以自己照着做下。

多看例子想想就行了。

  找个游戏做的不好,不要笑话啊。

  import java.awt.*;   import javax.swing.JApplet.*;   import java.awt.event.*;   import javax.swing.*;   class People extends JButton implements FocusListener   {   Rectangle rect=null;   int left_x,left_y;//按钮左上角坐标.   int width,height; //按钮的宽和高.   String name;   int number;   public People(int number,String s,int x,int y,int w,int h,HuaRongRoad road)   {   super(s);   name=s;   this.number=number;   left_x=x;   left_y=y;   width=w;   height=h;   setBackground(Color.GREEN);   road.add(this);   addKeyListener(road);   setBounds(x,y,w,h);   addFocusListener(this);   rect=new Rectangle(x,y,w,h);   }   public void focusGained(FocusEvent e)   {   setBackground(Color.red);   }   public void focusLost(FocusEvent e)   {   setBackground(Color.GREEN);   }   }   public class HuaRongRoad extends JApplet implements KeyListener,ActionListener   {   People people[]=new People[10];   Rectangle left,right,above,below;//华容道的边界   JButton restart=new JButton("restart");   public void init()   {   getContentPane().setLayout(null);   getContentPane().add(restart);   restart.setBounds(5,5,80,25);   restart.addActionListener(this);   getContentPane().setBackground(Color.white);   people[0]=new People(0,"曹操",154,54,200,200,this);   people[1]=new People(1,"关羽",154,254,200,100,this);   people[2]=new People(2,"张飞",54,254,100,200,this);   people[3]=new People(3,"刘备",354,254,100,200,this);   people[4]=new People(4,"张辽",54,54,100,200,this);   people[5]=new People(5,"曹仁",354,54,100,200,this);   people[6]=new People(6,"兵 ",54,454,100,100,this);   people[7]=new People(7,"兵 ",354,454,100,100,this);   people[8]=new People(8,"兵 ",154,354,100,100,this);   people[9]=new People(9,"兵 ",254,354,100,100,this);   people[9].requestFocus();   people[0].setForeground(Color.white);   left=new Rectangle(49,49,5,510);   right=new Rectangle(454,49,5,510);   above=new Rectangle(49,49,410,5);   below=new Rectangle(49,554,410,5);   }   public void paint(Graphics g)   { //华容道的边界   super.paint(g);   g.setColor(Color.cyan);   g.fillRect(49,49,5,510);   g.fillRect(454,49,5,510);   g.fillRect(49,49,410,5);   g.fillRect(49,554,410,5);   //   g.drawString("单击,按方向箭头移动",100,20);   g.setColor(Color.red);   g.drawString("曹操到达该位置",110,300);   }   public void keyPressed(KeyEvent e)   {   People man=(People)e.getSource();   man.rect.setLocation(man.getBounds().x,man.getBounds().y);   if(e.getKeyCode()==KeyEvent.VK_DOWN)   {   man.left_y=man.left_y+100; //向下前进50个单位   man.setLocation(man.left_x,man.left_y);   man.rect.setLocation(man.left_x,man.left_y);   //判断是否和其他人或边界重叠,出现就退回50个单位   for(int i=0;i<10;i++)   {   if((man.rect.intersects(people[i].rect))&&(man.number!=i))   {   man.left_y=man.left_y-100;   man.setLocation(man.left_x,man.left_y);   man.rect.setLocation(man.left_x,man.left_y);   }   }   if(man.rect.intersects(below))   {   man.left_y=man.left_y-100;   man.setLocation(man.left_x,man.left_y);   man.rect.setLocation(man.left_x,man.left_y);   }   }   if(e.getKeyCode()==KeyEvent.VK_UP)   {   man.left_y=man.left_y-100; //向上前进50个单位   man.setLocation(man.left_x,man.left_y);   man.rect.setLocation(man.left_x,man.left_y);   //判断是否和其他人或边界重叠,出现就退回50个单位   for(int i=0;i<10;i++)   {   if((man.rect.intersects(people[i].rect))&&(man.number!=i))   {   man.left_y=man.left_y+100;   man.setLocation(man.left_x,man.left_y);   man.rect.setLocation(man.left_x,man.left_y);   }   }   if(man.rect.intersects(above))   {   man.left_y=man.left_y+100;   man.setLocation(man.left_x,man.left_y);   man.rect.setLocation(man.left_x,man.left_y);   }   }   if(e.getKeyCode()==KeyEvent.VK_LEFT)   {   man.left_x=man.left_x-100; //向左前进50个单位   man.setLocation(man.left_x,man.left_y);   man.rect.setLocation(man.left_x,man.left_y);   //判断是否和其他人或边界重叠,出现就退回50个单位   for(int i=0;i<10;i++)   {   if((man.rect.intersects(people[i].rect))&&(man.number!=i))   {   man.left_x=man.left_x+100;   man.setLocation(man.left_x,man.left_y);   man.rect.setLocation(man.left_x,man.left_y);   }   }   if(man.rect.intersects(left))   {   man.left_x=man.left_x+100;   man.setLocation(man.left_x,man.left_y);   man.rect.setLocation(man.left_x,man.left_y);   }   }   if(e.getKeyCode()==KeyEvent.VK_RIGHT)   {   man.left_x=man.left_x+100; //向右进50个单位   man.setLocation(man.left_x,man.left_y);   man.rect.setLocation(man.left_x,man.left_y);   //判断是否和其他人或边界重叠,出现就退回50个单位   for(int i=0;i<10;i++)   {   if((man.rect.intersects(people[i].rect))&&(man.number!=i))   {   man.left_x=man.left_x-100;   man.setLocation(man.left_x,man.left_y);   man.rect.setLocation(man.left_x,man.left_y);   }   }   if(man.rect.intersects(right))   {   man.left_x=man.left_x-100;   man.setLocation(man.left_x,man.left_y);   man.rect.setLocation(man.left_x,man.left_y);   }   }   }   public void keyTyped(KeyEvent e){}   public void keyReleased(KeyEvent e){}   public void actionPerformed(ActionEvent e)   {   getContentPane().removeAll();   this.init();   }   }

求好玩的手机java小游戏?

【烈焰风暴】 媲美雷电 经典的飞行射击游戏 【宠物狗狗 dogz】GL出品的经典养成游戏 【陨石方块】一款不错的益智游戏 【多米诺骨牌】如此经典绝对值得收藏 【兔子波比】可爱的兔子益智游戏男女都适合 【绿豆蛙钻石之旅】画面非常细腻 适合男女生玩 休闲娱乐的好游戏 【彩虹城堡 1-3】经典的角色游戏 现在很热门 【雷电豪华版】移植 电脑上经典的飞行射击游戏 绝对震撼 【火焰纹章1-3】战棋游戏的大作 绝对好玩 【苍神录全集】绝对经典 要一个一个玩 【雷电风暴】 3D 赛车游戏 手机版的极品飞车 【天空战记】 手机版的战国利刃(经典的街机游戏) 【豆包】休闲娱乐游戏 大集合 打包成一个软件 可以联网 可以单机

  • java小游戏求好玩的手机java小游戏?相关文档

酷番云78元台湾精品CN2 2核 1G 60G SSD硬盘

酷番云怎么样?酷番云就不讲太多了,介绍过很多次,老牌商家完事,最近有不少小伙伴,一直问我台湾VPS,比较难找好的商家,台湾VPS本来就比较少,也介绍了不少商家,线路都不是很好,有些需求支持Windows是比较少的,这里我们就给大家测评下 酷番云的台湾VPS,支持多个版本Linux和Windows操作系统,提供了CN2线路,并且还是原生IP,更惊喜的是提供的是无限流量。有需求的可以试试。可以看到回程...

JUSTG提供俄罗斯和南非CN2 GIA主机年$49.99美元JUSTGgia南非cn2南非CN2justG

JUSTG,这个主机商第二个接触到,之前是有介绍到有提供俄罗斯CN2 GIA VPS主机活动的,商家成立时间不久看信息是2020年,公司隶属于一家叫AFRICA CLOUD LIMITED的公司,提供的产品为基于KVM架构VPS主机,数据中心在非洲(南非)、俄罗斯(莫斯科),国内访问双向CN2,线路质量不错。有很多服务商实际上都是国人背景的,有的用英文、繁体搭建的冒充老外,这个服务商不清楚是不是真...

RepriseHosting:$27.97/月-L5640,16G内存,1TB硬盘,10TB月流量,西雅图机房

RepriseHosting是成立于2012年的国外主机商,提供独立服务器租用和VPS主机等产品,数据中心在美国西雅图和拉斯维加斯机房。商家提供的独立服务器以较低的价格为主,目前针对西雅图机房部分独立服务器提供的优惠仍然有效,除了价格折扣外,还免费升级内存和带宽,商家支持使用支付宝或者PayPal、信用卡等付款方式。配置一 $27.97/月CPU:Intel Xeon L5640内存:16GB(原...

java小游戏为你推荐
电脑手机网页浏览器怎样将手机浏览器改为电脑版融360融360贷款是假的是骗人的,大家注意了项目质量管理在项目质量管理中有什么资源优化配置什么是优化产业结构,资源优化配置??小项目奥运会一共有几个大项目小项目?招行信用卡还款招商银行信用卡还款日如何计算t320在网上买的三星平板T320,怎么检查是不是正品行货?burndownburn down是否及物?能用被动语态吗?海淀区公司注册北京海淀培训公司注册如何办理?科学计算器说明书求科学计算器怎么用
awardspace 牛人与腾讯客服对话 申请个人网站 刀片服务器的优势 33456 怎么建立邮箱 空间登陆首页 畅行云 如何登陆阿里云邮箱 中国联通宽带测试 阿里云个人邮箱 存储服务器 云销售系统 789电视剧网 谷歌搜索打不开 建站技术 htaccess godaddy中文 web服务器 美国服务器 更多