java根本不是写游戏用的... ------------------------------------------------------
           我们还年轻牛奶会有的奶牛也会有的 
             可天天在 csdn 混这些会有吗 ??

解决方案 »

  1.   

    JAVA也可以用来写游戏啊.看写什么游戏.你说大型游戏当然不能用JAVA来写了....
      

  2.   

    星际争霸是用C++写的,java不是设计用来写游戏的
      

  3.   

    呵呵 有必要用java来写吗 
    当然真的要写的话 那是肯定行的了 事在人为了
    有好的算法 有好的游戏题材 当然也要有好使的脑子了
    用java写本人不认同了 呵呵
      

  4.   

    星际看来使用了directx编程,你说java会支持吗?
      

  5.   

    未来也许会有人用 JAVA 3D 写些什么东西,不过用 JAVA 写的东西的效率无论如何也和用 C 写的本地代码的效率没得比 (也许有 10 倍的差距),因此在近几年内 (硬件没有很发达),用 JAVA 写大型游戏程序都得考虑再三。
      

  6.   

    java对于界面的支持程序肯定不能与原生的编译语言相比的,主要是效率问题,
    我想游戏可能都会针对每个平台进行优化的,这样才能产生比较好的郊果。或许精通java,只要经过自己艰辛的努力就行了,但是其实java中有许多局限性的,
    当你能突破java的局限性时,你就成为高手了。
    突破java?哈哈,妙!!
      

  7.   

    java天生就是为服务器打造的最优编程语言。
      

  8.   

    不知到星级争霸在linux夏能不能玩,如果不能那绝对不是java写的。
      

  9.   

    谁说不可以写游戏呀!呵呵..import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;/*
        TRTRIS GAME
        WRITE BY DELFAN
        EMAIL : [email protected]
        URL : http://www.delfan.com    经典"俄罗斯方块"游戏
        作者 : DELFAN
        EMail : [email protected]
        主页 : http://www.delfan.com    版本信息:
        2002.01.13 基本完成    请任何时候都保留以上信息.谢谢!
    */
    public class tetris extends Applet implements Runnable
    {
        Thread thread;
        private Image offImg; // 缓冲图象
        private Graphics offG; // 缓冲
        final int BaseX = 20;
        final int BaseY = 20;
        final int BlockSize = 20;  // 每个块的大小    //
        //  定义游戏中出现的信息
        //
        final String INFO_READY = "S键 开始游戏";
        final String INFO_PAUSE = "P键 继续游戏";
        final String INFO_GAMEOVER = "游戏结束 任意键继续";    byte SHAPE[][][][] = // [造型索引][旋转索引][4][坐标]
        {
            {  // 造型一
              {{ 0, 0},{ 1, 0},{ 0, 1},{ 1, 1}}, // 旋转一  [][]....
              {{ 0, 0},{ 1, 0},{ 0, 1},{ 1, 1}}, // 旋转二  [][]....
              {{ 0, 0},{ 1, 0},{ 0, 1},{ 1, 1}}, // 旋转三  ........
              {{ 0, 0},{ 1, 0},{ 0, 1},{ 1, 1}}  // 旋转四  ........
            },
            {  // 造型二
              {{-1, 0},{ 0, 0},{ 0, 1},{ 1, 1}}, // 旋转一              []
              {{ 0,-1},{ 0, 0},{-1, 0},{-1, 1}}, // 旋转二  []()      []()
              {{-1, 0},{ 0, 0},{ 0, 1},{ 1, 1}}, // 旋转三    [][]    []
              {{ 0,-1},{ 0, 0},{-1, 0},{-1, 1}}  // 旋转四
            },
            {  // 造型三
              {{ 1, 0},{ 0, 0},{ 0, 1},{-1, 1}}, // 旋转一            []
              {{ 0,-1},{ 0, 0},{ 1, 0},{ 1, 1}}, // 旋转二    ()[]    ()[]
              {{ 1, 0},{ 0, 0},{ 0, 1},{-1, 1}}, // 旋转三  [][]        []
              {{ 0,-1},{ 0, 0},{ 1, 0},{ 1, 1}}  // 旋转四
            },
            {  // 造型四
              {{ 0, 0},{ 1, 0},{ 2, 0},{ 0, 1}}, // 旋转一                       []    []
              {{ 0,-2},{ 0,-1},{ 0, 0},{ 1, 0}}, // 旋转二  ()[][]    []()   [][]()    []
              {{-2, 0},{-1, 0},{ 0, 0},{ 0,-1}}, // 旋转三  []          []             ()[]
              {{-1, 0},{ 0, 0},{ 0, 1},{ 0, 2}}  // 旋转四              []
            },
            {  // 造型五
              {{-2, 0},{-1, 0},{ 0, 0},{ 0, 1}}, // 旋转一            []
              {{ 0, 0},{ 1, 0},{ 0, 1},{ 0, 2}}, // 旋转二  [][]()    []   []       ()[]
              {{ 0,-1},{ 0, 0},{ 1, 0},{ 2, 0}}, // 旋转三      []  []()   ()[][]   []
              {{ 0,-2},{ 0,-1},{ 0, 0},{-1, 0}}  // 旋转四                          []
            },
            {  // 造型六
              {{-1, 0},{ 0, 0},{ 1, 0},{ 0, 1}}, // 旋转一
              {{ 0,-1},{ 0, 0},{ 0, 1},{ 1, 0}}, // 旋转二    []     []                []
              {{-1, 0},{ 0, 0},{ 1, 0},{ 0,-1}}, // 旋转三  []()[]   ()[]    []()[]  []()
              {{-1, 0},{ 0, 0},{ 0,-1},{ 0, 1}}  // 旋转四           []        []      []
            },
            {  // 造型六
              {{ 0,-1},{ 0, 0},{ 0, 1},{ 0, 2}}, // 旋转一  []
              {{-1, 0},{ 0, 0},{ 1, 0},{ 2, 0}}, // 旋转二  ()   []()[][]
              {{ 0,-1},{ 0, 0},{ 0, 1},{ 0, 2}}, // 旋转三  []
              {{-1, 0},{ 0, 0},{ 1, 0},{ 2, 0}}  // 旋转四  []
            }
        };    //
        //  定义游戏中使用的变量
        //
        final int[] Speeds = {60,50,40,30,20,15,10,5,3,1};  // 速度值定义    byte[][] Ground = new byte[10][20];  // 在 10 X 20 的场地游戏,预留顶部放置方块的空间一格
        byte[][] NextShape = new byte[4][2]; // 存放下块造型
        int CurrentX;                   // 当前X左边
        int CurrentY;                   // 当前Y坐标
        int CurrentShapeIndex;          // 当前造型索引
        int CurrentTurnIndex;           // 当前旋转索引
        int CurrentColorIndex;          // 当前造型色彩索引
        int NextShapeIndex;             // 下块出现的造型的索引
        int GameSpeed = 0;              // 游戏速度
        int SpeedVar = 0;               // 延时计数
        int FlashSpeed = 60;            // 信息提示闪烁速度
        int FlashVar = 0;               // 闪烁延时计数
        int ClearTotalLine = 0;         // 消掉的总行数
        Color[] Colors = {Color.black,Color.red,Color.green,Color.blue,Color.magenta,Color.yellow,Color.orange,Color.pink};    //
        //   定义游戏中出现的状态
        //
        final int READY = 0;
        final int GAMING = 1;
        final int PAUSE = 2;
        final int GAMEOVER = 3;
        private int CurrentMode = READY ;   // 游戏状态变量    String InfoStr = new String(INFO_READY);    public void init()
        {
            offImg = createImage(getSize().width, getSize().height); // 创建缓冲图象大小
            offG = offImg.getGraphics();
            setBackground(Color.black);
        }    public void MakeNextShape()
        {
            NextShapeIndex = (int)(Math.random()*70) /10;
            NextShape = SHAPE[NextShapeIndex][0];
        }    public void ClearGround()  // 清除场地
        {
            for(int i=0; i<10; i++)
               for(int j=0; j<20; j++) Ground[i][j]=0;
            CurrentMode = READY;
            ClearTotalLine = 0;
        }    public void StartGame()  // 开始游戏
        {
            ClearGround();
            CurrentShapeIndex = (int)(Math.random()*70) /10;
            CurrentX = 4;
            CurrentY = 0;
            CurrentMode = GAMING;
            CurrentColorIndex = (int)(Math.random()*70) /10 +1;
            MakeNextShape();
        }    public void drawABlock(Graphics g,int x,int y,int colorIndex)  // 用指定的颜色画一个方块
        {
            g.setColor(Colors[colorIndex]);
            g.fill3DRect(BaseX + x * BlockSize, BaseY + y * BlockSize , BlockSize, BlockSize, true);
            g.fill3DRect(BaseX + x * BlockSize + 1, BaseY + y * BlockSize +1, BlockSize -2, BlockSize-2, true);
        }    public void drawShape(Graphics g,int x,int y, int shapeindex,int trunindex) // 在指定位置画指定的造型
        {
            for(int i=0; i<4; i++)
            {
                if(y+SHAPE[shapeindex][trunindex][i][1]>=0)   // 不画最顶上不在区域的块
                    drawABlock(g,x+SHAPE[shapeindex][trunindex][i][0]
                                ,y+SHAPE[shapeindex][trunindex][i][1],CurrentColorIndex);
            }
        }    public void drawGround(Graphics g)  // 画整个画面
        {
            // 画提示信息及行数及其他
            g.setColor(new Color(255,255,255));
            if(CurrentMode == READY) g.drawString(" + / - : 调整速度",BaseX,BaseY-3);
            if(CurrentMode == GAMING) g.drawString("Up:翻转 Left/Right:移动 Down:快落 R:重玩",BaseX,BaseY-3);
            g.drawRect(BaseX-1,BaseY-1,BlockSize*10, BlockSize*20);
            for(int i=0; i<10; i++)
              for(int j=1; j<20; j++)
                  if(Ground[i][j]!=0) drawABlock(g,i,j,Ground[i][j]);
      

  10.   

    // 显示相关信息
            g.setColor(Color.lightGray);
            g.drawRect(BaseX + BlockSize * 10 , BaseY-1,BlockSize * 2 + BlockSize /2 + BlockSize/2,20);  // 与下一块提示对齐
            g.drawString("TETRIS",BaseX + BlockSize * 10+8,BaseY + 14); // 画游戏相关信息
            g.drawString("已消行数",BaseX + BlockSize * 10+5,BaseY * 3 );
            g.drawString(String.valueOf(ClearTotalLine),BaseX + BlockSize * 10+5,BaseY * 4);
            g.drawString("当前速度",BaseX + BlockSize * 10+5,BaseY * 6 );
            g.drawString(String.valueOf(GameSpeed),BaseX + BlockSize * 10+5,BaseY * 7);
            g.drawString("http://www.delfan.com" ,BaseX,BaseY + BlockSize * 21-10 );
        }    public void drawNextBlock(Graphics g)  //  画下一块
        {
            g.setColor(Color.lightGray);
            g.drawString("下一块",BaseX+11*BlockSize - BlockSize / 2,BaseY+17*BlockSize);
            g.drawRect(BaseX + BlockSize * 10, BaseY + BlockSize *18 - BlockSize / 2
                                   ,BlockSize * 2 + BlockSize / 2,BlockSize * 2);
            g.setColor(Color.blue);
            for(int i=0; i<4; i++)
                g.fill3DRect(BaseX + 11 * BlockSize + NextShape[i][0]*BlockSize / 2
                           , BaseY + 18 * BlockSize + NextShape[i][1]*BlockSize / 2 , BlockSize / 2 , BlockSize /2, true);
        }    public void drawInfo(Graphics g)  // 绘制提示的信息
        {
            g.setColor(Color.white);
            Font old = g.getFont();
            g.setFont(new Font("宋体",0,24));
            g.drawString(InfoStr,BaseX+5*BlockSize - InfoStr.length()* 7 ,BaseY+10*BlockSize);
            g.setFont(old);
        }    public void paint(Graphics g)
        {
            offG.clearRect(0,0,getSize().width,getSize().height);
            drawGround(offG);
            switch(CurrentMode)
            {
                case READY :
                case PAUSE :
                case GAMEOVER :
                       drawInfo(offG);
                       break;
                case GAMING :
                       drawShape(offG,CurrentX,CurrentY,CurrentShapeIndex,CurrentTurnIndex);
                       drawNextBlock(offG);
                       break;
            }
            if(offG!=null) g.drawImage(offImg,0,0,this);
        }    public void update(Graphics g)
        {
            paint(g);
        }    public void start()
        {
            thread = new Thread(this);
            thread.start();
        }    public void stop()
        {
            thread = null;
        }    public void run()
        {
            Thread current = Thread.currentThread();        while(thread == current)
            {
                try
                {
                   Thread.currentThread().sleep(10);
                } catch (InterruptedException e) {}            if(CurrentMode == GAMING)
                {
                    if(SpeedVar ++ > Speeds[GameSpeed])
                    {
                        SpeedVar = 0;
                        DownIt();
                        repaint();
                    }
                }
                else
                if(FlashVar ++ > FlashSpeed)
                {
                    FlashVar = 0;
                    switch(CurrentMode)
                    {
                        case READY  :
                                if(InfoStr.equals("")) InfoStr = INFO_READY;
                                else InfoStr = "";
                                break;
                        case PAUSE  :
                                if(InfoStr.equals("")) InfoStr = INFO_PAUSE;
                                else InfoStr = "";
                                break;
                        case GAMEOVER :
                                if(InfoStr.equals("")) InfoStr = INFO_GAMEOVER;
                                else InfoStr = "";
                    }
                    repaint();
                } // End of if(FlashVar++...
            }// End of While
        }    public boolean CanMoveTo(int shape,int turn,int x,int y)  //判断是否能移动到指定位置
        {
            boolean result = true;        turn %=4;        for(int i=0; i<4; i++)
            {
                if( (x + SHAPE[shape][turn][i][0] < 0) || (x + SHAPE[shape][turn][i][0] > 9) )
                {
                    result = false;
                    break;
                }
                if( y + SHAPE[shape][turn][i][1] > 19)
                {
                    result = false;
                    break;
                }
                if(Ground[x+SHAPE[shape][turn][i][0]][y + SHAPE[shape][turn][i][1]] != 0)
                {
                    result = false;
                    break;
                }
            }
            return result;
        }    public synchronized void DownIt()  // 处理下落过程
        {
            if(CanMoveTo(CurrentShapeIndex,CurrentTurnIndex,CurrentX,CurrentY+1))
            {
                CurrentY++;
            }
            else  // 已经下落到底部了
            {
                if(CurrentY == 0) CurrentMode = GAMEOVER;
                else
                {
                    // 将当前块放到Ground中去
                    for(int i=0; i<4; i++)
                        Ground[CurrentX + SHAPE[CurrentShapeIndex][CurrentTurnIndex][i][0]]
                              [CurrentY + SHAPE[CurrentShapeIndex][CurrentTurnIndex][i][1]] = (byte)CurrentColorIndex;
                    CurrentX=4;
                    CurrentY=0;
                    CurrentShapeIndex = NextShapeIndex;
                    CurrentColorIndex = (int)(Math.random()*70) /10 + 1;
                    MakeNextShape();
                    CurrentTurnIndex =0;
                    // 判断有没有一行的数据
                    int total;
                    for(int y=19; y>=0; y--)
                    {
                        total = 0;
                        for(int x=0; x<10; x++)
                            if(Ground[x][y] != 0) total ++;                    if(total == 10) // 说明行满了
                        {
                            // 将此行上面所有数据复制下来
                            for(int i=0; i<10; i++)
                              for(int j=y; j>0; j--)    Ground[i][j] = Ground[i][j-1];
                            y++;
                            ClearTotalLine++;
                            if(ClearTotalLine % 50 == 0)
                            {
                                GameSpeed ++;   // 每消50行增加一次速度
                                if(GameSpeed>9) GameSpeed = 9;
                            }
                        }
                    }//end of For
                } // of else
            } // of else
        }
       public boolean keyDown(Event e, int key) // 处理键盘事件
        {
            switch(CurrentMode)
            {
                case READY :
                        if(key == 's' || key =='S') StartGame();
                        if(key == '+')
                        {
                             GameSpeed ++;
                             if(GameSpeed>9) GameSpeed = 9;
                        }
                        if(key == '-')
                        {
                             GameSpeed --;
                             if(GameSpeed<0) GameSpeed = 0;
                        }
                        break;
                case PAUSE :
                        if(key == 'p' || key =='P') CurrentMode = GAMING;
                        break;
                case GAMEOVER :
                        CurrentMode = READY;   // 按任意键准备游戏
                        break;
                case GAMING :
                        if(key == 'p' || key == 'P') CurrentMode = PAUSE;
                        if(key == 'r' || key == 'R') CurrentMode = READY;
                        if(key == Event.LEFT && CanMoveTo(CurrentShapeIndex,CurrentTurnIndex,CurrentX-1,CurrentY)) CurrentX --;
                        if(key == Event.RIGHT && CanMoveTo(CurrentShapeIndex,CurrentTurnIndex,CurrentX+1,CurrentY)) CurrentX ++;
                        if(key == Event.UP && CurrentY>1 && CanMoveTo(CurrentShapeIndex,CurrentTurnIndex+1,CurrentX,CurrentY))
                        {
                             CurrentTurnIndex ++;
                             CurrentTurnIndex %= 4;
                        }
                        if(key == Event.DOWN) DownIt();
                        repaint();
                        break;
            }
            return true;
        }
    }
      

  11.   

    to:yuxiangyu(yxy)
    你当星际是个窗口程序哪!
    想在linux下玩,你可以试试用wine来模拟,diablo可以玩,sc也应该没问题。
      

  12.   

    由于效力问题,java不太适合写大型游戏!!