「java怎么编游戏」java游戏编程教程

博主:adminadmin 2023-01-21 06:06:07 324

本篇文章给大家谈谈java怎么编游戏,以及java游戏编程教程对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

JAVA能写游戏吗?

Java可以写游戏的,但是一般来说不建议用Java开发游戏,因为Java这个语言是面向对象的语言对代码进行了大量的封装来达到模块组件可复用的目的,这也导致了它相对于面向过程的C,C++这种更偏向于底层的语言来说运行速度是偏慢的,Java更偏向于做服务端方面的工作,做电商网站,公司企业级的后台系统,因为Java语言的特点使其开发的系统具有较高的稳定性和安全性以及最重要的可维护性。

用java如何编写一个猜拳游戏?

我之前写了个猜拳游戏的源代码,不过没你想的这么精彩。你才给5分就给你你自己修改了,应该很简单的。要多给点分我可以帮你修改。

import java.util.Scanner;

import java.util.Random;

public class caiquan

{

final int jiandao=0;

final int shitou=1;

final int bu=2;

public static void main(String[] args)

{

String yn="y";

while (yn.equals("y"))

{

Scanner scanner = new Scanner(System.in);

System.out.println("欢迎玩猜拳游戏。请输入0,1,2:0表示剪刀,1表示石头,2表示布");

int a = scanner.nextInt();

Random rd = new Random();

int b = rd.nextInt(3);

switch (b)

{

case 0:

{

System.out.println("系统出的是剪刀");

switch(a)

{

case 0:System.out.println("平");break;

case 1:System.out.println("赢");break;

case 2:System.out.println("输");break;

}

}

break;

case 1:

{

System.out.println("系统出的是石头");

switch(a)

{

case 0:System.out.println("输");break;

case 1:System.out.println("平");break;

case 2:System.out.println("赢");break;

}

}

break;

case 2:

{

System.out.println("系统出的是布");

switch(a)

{

case 0:System.out.println("赢");break;

case 1:System.out.println("输");break;

case 2:System.out.println("平");break;

}

}

}

Scanner ynn = new Scanner(System.in);

System.out.println("是否继续?是请输入y,否则输入n。");

yn=ynn.next();

}

}

}

怎样自己动手做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;i10;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;i10;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;i10;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;i10;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做游戏?

主要是用Java分支中的J2ME来写,但是J2ME中需要Java的基础知识 。\x0d\x0a\x0d\x0a 现在有大部分人,都是从零开始学J2ME的,学习J2ME的时候,总是从Java基础开始学习,而且现在讲Java基础的书籍中都是以J2SE来讲基础,这就给学习造成了一些不必要的麻烦,下面将J2ME中用到的和不需要的Java基础知识做一个简单的说明。 \x0d\x0a\x0d\x0a J2ME中使用到的Java基础知识: \x0d\x0a\x0d\x0a1、Java语法基础:包括基本数据类型、关键字、运算符等等 \x0d\x0a2、面向对象的思想:类和对象的概念,继承和多态等等。 \x0d\x0a3、异常处理 \x0d\x0a4、多线程 \x0d\x0a\x0d\x0a J2ME中没有用到的Java基础知识: \x0d\x0a\x0d\x0a1、JDK中javac和java命令的使用 \x0d\x0a2、Java基础中的很多类在J2ME中没有,或者类中的方法做了大量的精简。所以建议在J2ME中熟悉类库。 \x0d\x0a3、Applet、AWT、Swing这些知识在J2ME中根本使用不到。\x0d\x0a \x0d\x0a 简单说这么多,希望学J2ME的朋友们能少走一些弯路,不足之处希望大家积极指正和补充

关于java怎么编游戏和java游戏编程教程的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。