java做的游戲
① 一個簡單的java做的小游戲
我也不知道你要什麼樣的游戲
我隨便貼了一個
第一個Java文件:
import java.util.Scanner;
public class GameA_B {
public static void main(String[] args) {
Scanner reader=new Scanner(System.in);
int area;
System.out.println("Game Start…………Please enter the area:(1-9)" +
'\n'+"1,2,3 means easy"+'\n'+"4,5,6 means middle"+'\n'+
"7,8,9 means hard"+'\n'+"Please choose:");
area=reader.nextInt();
switch((area-1)/3)
{
case 0:System.out.println("You choose easy! ");break;
case 1:System.out.println("You choose middle! ");break;
case 2:System.out.println("You choose hard! ");break;
}
System.out.println("Good Luck!");
GameProcess game1=new GameProcess(area);
game1.process();
}
}
第二個Java文件:
import java.util.Random;
import java.util.Scanner;
public class GameProcess {
int area,i,arrcount,right,midright,t;
int base[]=new int[arrcount],userNum[]=new int[area],sysNum[]=new int[area];
Random random=new Random();
Scanner reader=new Scanner(System.in);
GameProcess(int a)
{
area=a;
arrcount=10;
right=0;
midright=0;
t=0;
base=new int[arrcount];
userNum=new int[area];
sysNum=new int[area];
for(int i=0;i<arrcount;i++)
{
base[i]=i;
//System.out.println(base[i]);
}
}
void process()
{
rand();
while(right!=area)
{
scanf();
compare();
print();
check();
}
}
void rand()
{
for(i=0;i<area;i++)
{
t=random.nextInt(arrcount);
//System.out.println(t);
sysNum[i]=base[t];
System.out.println(base[t]);
delarr(t);
}
}
void delarr(int t)
{
for(int j=t;j<arrcount-1;j++)
base[j]=base[j+1];
arrcount--;
}
void scanf()
{
System.out.println("The system number has created!"+"\n"+"Please enter "+area+" Numbers");
for(int i=0;i<area;i++)
{
userNum[i]=reader.nextShort();
}
}
void check()
{
if(right==area)
System.out.println("You win…………!");
}
boolean check(int i)
{
return true;
}
void compare()
{
int i=0,j=0;
right=midright=0;
for(i=0;i<area;i++)
{
for(j=0;j<area;j++)
{
if(userNum[i]==sysNum[j])
{
if(i==j)
right++;
else
midright++;
}
}
}
}
void print()
{
System.out.println(" A "+right+" B "+midright);
}
}
希望能幫到你
忘點贊
② 怎麼用java做游戲
主要是用Java分支中的J2ME來寫,但是J2ME中需要Java的基礎知識 。
現在有大部分人,都是從零開始學J2ME的,學習J2ME的時候,總是從Java基礎開始學習,而且現在講Java基礎的書籍中都是以J2SE來講基礎,這就給學習造成了一些不必要的麻煩,下面將J2ME中用到的和不需要的Java基礎知識做一個簡單的說明。
J2ME中使用到的Java基礎知識:
1、Java語法基礎:包括基本數據類型、關鍵字、運算符等等
2、面向對象的思想:類和對象的概念,繼承和多態等等。
3、異常處理
4、多線程
J2ME中沒有用到的Java基礎知識:
1、JDK中javac和java命令的使用
2、Java基礎中的很多類在J2ME中沒有,或者類中的方法做了大量的精簡。所以建議在J2ME中熟悉類庫。
3、Applet、AWT、Swing這些知識在J2ME中根本使用不到。
簡單說這么多,希望學J2ME的朋友們能少走一些彎路,不足之處希望大家積極指正和補充
③ 用JAVA編寫一個小游戲
前天寫的猜數字游戲,yongi控制猜測次數,有詳細解析,用黑窗口可以直接運行,
我試驗過了,沒問題
import javax.swing.Icon;
import javax.swing.JOptionPane;
public class CaiShuZi4JOptionPane {
/**
* @param args
*/
public static void main(String[] args) {
Icon icon = null;
boolean bl = false;
int put = 0;
int c = (int) (((Math.random())*100)+1); //獲取一個1-100的隨機數
System.out.println("你獲取的隨機數是:"+c); //列印你的隨機數字
String str1 = (String) JOptionPane.showInputDialog(null,"請輸入你的猜測數字(1-100): ","猜數字游戲",JOptionPane.PLAIN_MESSAGE,icon,null,"在這輸入"); //第一次輸入你的猜測數字
if(str1==null){
JOptionPane.showMessageDialog(null, "你已經取消了本次游戲"); //如果你點取消那麼本次游戲結束
}else{
bl = num(str1); //判斷是輸入的是不是數字或者是整數
if(true==bl){ //如果是數字的話進入與隨機數比較的程序
System.out.println("你輸入的數字是:"+str1); //列印你輸入的數字
put = Integer.valueOf(str1);
for(int i = 4;i > 0;i--){ //i是你可以猜測的次數
if(put==c){
JOptionPane.showMessageDialog(null, "恭喜你猜對了,正確答案是:"+c+"。"); //如果你猜對了就直接結束循環
break;
}else if(put>c){ //如果輸大了就讓你再次從新輸入
str1 = (String) JOptionPane.showInputDialog(null,"你的輸入過大。你還有"+i+"次機會,請重新輸入: ","猜數字游戲",JOptionPane.PLAIN_MESSAGE,icon,null,"在這輸入");
if(str1==null){
JOptionPane.showMessageDialog(null, "你已經取消了本次輸入");
break;
}else{
bl =num(str1);
if(true==bl){
put = Integer.valueOf(str1);
}else{
JOptionPane.showMessageDialog(null, "你的輸入不正確,請重新輸入");
}
}
}else if(put<c){ //如果你輸小了也讓你從新輸入
str1 = (String) JOptionPane.showInputDialog(null,"你的輸入過小。你還有"+i+"次機會,請重新輸入: ","猜數字游戲",JOptionPane.PLAIN_MESSAGE,icon,null,"在這輸入");
if(str1==null){
JOptionPane.showMessageDialog(null, "你已經取消了本次輸入");
break;
}else{
bl =num(str1);
if(true==bl){
put = Integer.valueOf(str1);
}else{
JOptionPane.showMessageDialog(null, "你的輸入不正確,請重新輸入");
}
}
}
}
}else if(bl==false){ //這個 是你第一次如果填寫的不是數字的話也會結束本次游戲
JOptionPane.showMessageDialog(null, "請您下次按要求填寫。本次游戲結束");
}
if(true==bl && c!=put){ //如果你i次都沒猜對,那麼就直接告訴你這個數十什麼
JOptionPane.showMessageDialog(null, "很遺憾你沒能猜對,這個數字是:"+c+".");
}
}
}
public static boolean num(String value){ //一個靜態方法,判斷你輸入的是不是數字
try {
Integer.parseInt(value);
return true;
} catch (Exception e) {
return false;
}
}
}
④ 做JAVA游戲的軟體
有一個軟體可以,但功能不全,名字叫halo,可以修改劇情,但游戲主線不能。
下載地址
http://forum.minisoyo.com/thread-72678-1-1.html
⑤ JAVA可以做什麼類的游戲
你是想問「來Java可以做什麼自類型的游戲」嗎?
嗯,怎麼說呢?簡單來說就是,它可以做任何游戲!但是相對來說,各種「領域」都有適合各自的開發語言,比如:大型網路游戲用C++;手機APP用安卓和IOS...它 們在各自的領域或方向都已經開發應用的相對很成熟和穩定了,所以就很適合了。上面的這些用Java一樣可以做出來,而且估計效果也會很好,但是相對的,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能做游戲嗎
可以的,可以做Java游戲。
【資料】
主要是用Java分支中的J2ME來寫,但是J2ME中需要Java的基礎知識 。
現在有大部分人,都是從零開始學J2ME的,學習J2ME的時候,總是從Java基礎開始學習,而且現在講Java基礎的書籍中都是以J2SE來講基礎,這就給學習造成了一些不必要的麻煩,下面將J2ME中用到的和不需要的Java基礎知識做一個簡單的說明。
J2ME中使用到的Java基礎知識:
1、Java語法基礎:包括基本數據類型、關鍵字、運算符等等
2、面向對象的思想:類和對象的概念,繼承和多態等等。
3、異常處理
4、多線程
⑧ Java主要是用來做什麼的游戲嗎
Java是一種高級語言,就是用來編程的,相關工作用途:
1、Java可以開發網回站,例如,一些企業答的門戶網站;
2、Java可以做軟體,例如,信息管理系統、員工打卡系統;
3、Java用於手機開發,例如,做手機系統。
4、Java做游戲,例如一些網路游戲,手機游戲等等(不常用)
再給你張圖,圖文均摘自網路,望點贊
⑨ 求幾個java做的小游戲
這方面不算很精通哦!不過有幾個好的網站!可以去看看!
http://www.mooqq.com/