JAVA可以做出游戏么
发布网友
发布时间:2022-04-27 07:05
我来回答
共5个回答
热心网友
时间:2022-06-28 05:49
可以的,我就做过一个即时战略游戏。Java最大的问题是性能比较差。如果你不做非常复杂的游戏就可以光用Java。
做复杂的2D游戏或者3D游戏可以用JOGL(Java的OpenGL),性能还是比C要差一些,但一般的游戏足够了。
让用户安装JVM并不是大问题。不说现在大部分电脑都已经安装了JRE,你也可以*一个不用安装的JVM和你的游戏一起。比如JRE6一共有86 MB。作为比较Adobe Reader(看pdf文件用的)有41.1 MB,一般不会有人嫌这个东西太大而不下载的。
热心网友
时间:2022-06-28 05:49
我知道C的,软件用WIN-TC,代码如下:
#include<stdio.h>
#include<graphics.h>
#include<bios.h>
#include<stdlib.h>
#include<conio.h>
#define BC LIGHTBLUE
#define FC RED
#define LEFT 0x4b00
#define RIGHT 0x4d00
#define DOWN 0x5000
#define UP 0x4800
#define ESC 0x011b
#define ONE 0x231
#define TWO 0x332
#define THREE 0x433
void printsnake(int x,int y,int corlor);
void moveh(int *x,int *y,char (*p)[30],int dir);
void movet(int *tx,int *ty,char (*p)[30]);
void food(char (*p)[30]);
void level(char (*p)[30]);
void ashui();
void drawmat(char *mat,int matsize,int x,int y,int color);
void main()
{
int x,y,tx,ty,driver=DETECT,mode,key,key1,score=0;
char snake[40][30]={0};
char s[10];
registerbgidriver(EGAVGA_driver);
initgraph(&driver,&mode,"");
ashui();
level(snake);
outtextxy(80,60,"score=0");
setcolor(RED);
rectangle(80,80,520,420) ;
rectangle(99,99,501,401) ;
setfillstyle(SOLID_FILL,BC);
floodfill(200,200,RED);
setfillstyle(SOLID_FILL,BROWN);
for(y=0;y<30;y++)
for(x=0;x<40;x++)
if(snake[x][y]==6)bar(100+10*x,100+10*y,110+10*x,110+10*y);
printsnake(2,15,FC);
printsnake(3,15,FC);
snake[2][15]=snake[3][15]=1;
food(snake);
key=RIGHT;
x=3;y=15;tx=2;ty=15;
for(;;)
{
if(bioskey(1))key1=bioskey(0);
if(key1==ESC)break;
if(key1==LEFT&&key!=RIGHT||key1==RIGHT&&key!=LEFT||key1==UP&&key!=DOWN||key1==DOWN&&key!=UP)key=key1;
moveh(&x,&y,snake,key);
if(snake[x][y]!=5)
{
movet(&tx,&ty,snake);
if(x<0||x>39||y<0||y>29)
{
printsnake(x,y,0);
break;
}
else if(snake[x][y])break;
}
else
{
food(snake);
score++;
sprintf(s,"score=%d",score);
setfillstyle(SOLID_FILL,0);
bar(80,60,150,75);
outtextxy(80,60,s);
}
delay(30000);
}
setcolor(YELLOW);
moveto(260,240);
outtext("GAME OVER!");
getch();
}
void printsnake(int x,int y,int corlor)
{
int xx,yy;
setfillstyle(SOLID_FILL,corlor);
setcolor(corlor);
xx=100+10*x+5;
yy=100+10*y+5;
circle(xx,yy,5);
floodfill(xx,yy,corlor);
}
void moveh(int *x,int *y,char (*p)[30],int dir)
{
int i,j;
i=*x;j=*y;
switch(dir)
{
case RIGHT:p[i][j]=1;(*x)++;break;
case UP:p[i][j]=2;(*y)--;break;
case LEFT:p[i][j]=3;(*x)--;break;
case DOWN:p[i][j]=4;(*y)++;break;
}
printsnake(*x,*y,FC);
}
void movet(int *tx,int *ty,char (*p)[30])
{
int i,j;
i=*tx;j=*ty;
printsnake(i,j,BC);
switch(p[i][j])
{
case 1:(*tx)++;break;
case 2:(*ty)--;break;
case 3:(*tx)--;break;
case 4:(*ty)++;break;
}
p[i][j]=0;
}
void food(char (*p)[30])
{
int x,y;
for(;;)
{
randomize();
x=random(40);
y=random(30);
if(!p[x][y])break;
}
printsnake(x,y,WHITE);
p[x][y]=5;
}
void level(char (*p)[30])
{
int key,i,x,y,l=0;
outtextxy(180,150,"press 1,2,3 to choose game level");
outtextxy(200,170,"1.Easy");
outtextxy(200,190,"2.Normal");
outtextxy(200,210,"3.Hard");
key=bioskey(0);
switch(key)
{
case ONE:l=0;break;
case TWO:l=15;break;
case THREE:l=30;break;
}
cleardevice();
setfillstyle(SOLID_FILL,BROWN);
for(i=0;i<l;i++)
{
for(;;)
{
x=random(40);
y=random(30);
if(y==15||x<6||p[x][y])continue;
p[x][y]=6;
break;
}
}
}
void drawmat(char *mat,int matsize,int x,int y,int color)
{
int i, j, k, n;
n = (matsize - 1) / 8 + 1;
for(j = 0; j < matsize; j++)
for(i = 0; i < n; i++)
for(k = 0;k < 8; k++)
if(mat[j * n + i] & (0x80 >> k))
putpixel(x + i * 8 + k, y + j, color);
}
void ashui()
{
char tan32K[]={
0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,
0x00,0x03,0x00,0x00,0x00,0x07,0x00,0x00,
0x00,0x07,0x80,0x00,0x00,0x0C,0x60,0x00,
0x00,0x18,0x30,0x00,0x00,0x38,0x1C,0x00,
0x00,0x73,0x0E,0x00,0x00,0xE1,0x83,0x80,
0x01,0x80,0x01,0xF0,0x03,0x03,0xF0,0xFE,
0x06,0x7E,0x70,0x3E,0x0C,0x00,0xC0,0x00,
0x30,0x00,0x80,0x00,0x40,0x01,0x00,0x00,
0x00,0x43,0xF8,0x00,0x00,0x7C,0x1C,0x00,
0x00,0x60,0x18,0x00,0x00,0x63,0x18,0x00,
0x00,0x63,0x18,0x00,0x00,0x63,0x18,0x00,
0x00,0x62,0x18,0x00,0x00,0x62,0x18,0x00,
0x00,0x46,0x18,0x00,0x00,0x04,0x00,0x00,
0x00,0x0C,0xC0,0x00,0x00,0x18,0x70,0x00,
0x00,0x30,0x38,0x00,0x00,0x60,0x1C,0x00,
0x01,0xC0,0x0C,0x00,0x02,0x00,0x04,0x00,
};
char chi32K[]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,
0x00,0x00,0x70,0x00,0x00,0x00,0x70,0x00,
0x00,0x00,0x60,0x00,0x00,0x00,0xE0,0x00,
0x00,0x00,0xC1,0x80,0x00,0x01,0x9F,0xC0,
0x00,0xC1,0xFE,0x00,0x67,0xE3,0x00,0x00,
0x7C,0xE2,0x00,0x00,0x20,0xC4,0x00,0x00,
0x30,0xC8,0x00,0x00,0x30,0x80,0x38,0x00,
0x30,0x81,0xF8,0x00,0x17,0xC7,0x60,0x00,
0x1E,0x00,0x60,0x00,0x10,0x00,0xC0,0x00,
0x10,0x00,0xC0,0x00,0x00,0x00,0x80,0x08,
0x00,0x01,0x80,0x08,0x00,0x01,0x00,0x08,
0x00,0x01,0x00,0x08,0x00,0x03,0x00,0x18,
0x00,0x01,0x80,0x3C,0x00,0x01,0xFF,0xF8,
0x00,0x00,0x7F,0xE0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
char she32K[]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x1C,0x00,0x01,0x80,0x0E,0x00,
0x01,0x80,0x06,0x00,0x01,0x80,0x02,0x00,
0x00,0x80,0x00,0x00,0x00,0x80,0x00,0x70,
0x00,0x80,0x87,0xF8,0x00,0xBC,0xF8,0x30,
0x3F,0xCE,0xC0,0x60,0x18,0x8D,0x80,0x40,
0x18,0x89,0x80,0x00,0x08,0x89,0x30,0x40,
0x08,0xB8,0x10,0x60,0x0B,0xE0,0x10,0xE0,
0x0C,0x80,0x11,0xC0,0x00,0x88,0x13,0x00,
0x00,0x8C,0x1C,0x00,0x00,0x8C,0x10,0x00,
0x00,0xF6,0x30,0x08,0x03,0xC4,0x30,0x08,
0x7F,0x00,0x10,0x08,0x3C,0x00,0x10,0x18,
0x00,0x00,0x18,0x3C,0x00,0x00,0x0F,0xFC,
0x00,0x00,0x03,0xF0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
char a16S[]={
0x00,0x00,0x7B,0xFE,0x48,0x08,0x50,0x08,
0x60,0x08,0x53,0xE8,0x4A,0x28,0x4A,0x28,
0x4A,0x28,0x6B,0xE8,0x50,0x08,0x40,0x08,
0x40,0x08,0x40,0x08,0x40,0x28,0x40,0x10,
};
char shui16S[]={
0x01,0x00,0x01,0x00,0x01,0x08,0x01,0x10,
0x7D,0x20,0x05,0xC0,0x05,0x40,0x09,0x20,
0x09,0x20,0x11,0x10,0x11,0x18,0x21,0x0E,
0xC1,0x04,0x01,0x00,0x05,0x00,0x02,0x00,
};
char zuo16S[]={
0x08,0x80,0x0C,0x80,0x09,0x00,0x13,0xFE,
0x12,0x80,0x34,0x88,0x50,0xFC,0x90,0x80,
0x10,0x80,0x10,0x84,0x10,0xFE,0x10,0x80,
0x10,0x80,0x10,0x80,0x10,0x80,0x10,0x80,
};
char pin16S[]={
0x00,0x00,0x0F,0xF0,0x08,0x10,0x08,0x10,
0x08,0x10,0x0F,0xF0,0x08,0x10,0x00,0x00,
0x7E,0xFC,0x42,0x84,0x42,0x84,0x42,0x84,
0x42,0x84,0x7E,0xFC,0x42,0x84,0x00,0x00,
};
drawmat(tan32K,32,150,180,BLUE);
drawmat(chi32K,32,300,180,BLUE);
drawmat(she32K,32,450,180,BLUE);
drawmat(a16S,16,350,250,RED);
drawmat(shui16S,16,370,250,RED);
drawmat(zuo16S,16,390,250,RED);
drawmat(pin16S,16,410,250,RED);
getch();
cleardevice();
}
热心网友
时间:2022-06-28 05:50
唉,楼主和我有一样的梦想啊,我也马上大四了,时间真快啊...
这个问题是这样的。
游戏要看是什么游戏,我这里说的是3D游戏,我相信你的意思也不是要做个扫雷,呵呵。
游戏开发常用的框架说白了就是DirectX,OpenGL确实大不如当前了。因为游戏开发大量设计与系统底层的交互,而这恰恰是Java程序的软肋。Java必须使用JNI调用本地库才能实现硬件3D加速,这当然比直接开发的本地代码效率低的多,所以目前用Java做3D游戏的相当少。
但这并不代表Java不能进行3D开发,java.net维护的java3d项目,https://java3d.dev.java.net/,就是一个j2se上的3d API。可以说是3d在Java上的官方实现。
具体说到3D游戏,Java确实是可以做出高水平的3D游戏的。你关注游戏开发的话应该知道一些C++的开源游戏引擎,比如Ogre什么的。Java方面也有比较成熟的游戏引擎,有一个开源项目叫java monkey engine,在JavaOne 2008上还是很受瞩目的,它应该是基于Java3D实现。http://www.jmonkeyengine.com/ 这个是它的网站,上面有很多Demo,你可以慢慢看看。
参考资料:https://java3d.dev.java.net/
热心网友
时间:2022-06-28 05:50
java做游戏不现实。可能WEB GAME还可以。你想别人玩CS(这个不是*战)类型的游戏。玩你个不大的游戏还必须装JVM,很多用户肯定不愿意。
热心网友
时间:2022-06-28 05:51
java一般都是做小型的手机游戏之类的。
不过好像现在出了一个Java做到网络游戏。