Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1051444
  • 博文数量: 155
  • 博客积分: 5339
  • 博客等级: 大校
  • 技术积分: 1436
  • 用 户 组: 普通用户
  • 注册时间: 2005-08-10 21:41
文章分类

全部博文(155)

文章存档

2016年(3)

2015年(7)

2014年(3)

2013年(1)

2012年(8)

2011年(5)

2010年(1)

2009年(5)

2008年(4)

2007年(26)

2006年(46)

2005年(46)

分类: Java

2016-05-07 11:57:46

整理以前的硬盘资料,翻出来一个N年前的俄罗斯方块applet程序,很简陋,仅做个留存

点击(此处)折叠或打开

  1. import java.applet.*;
  2. import java.awt.*;

  3. public class mtetris extends Applet
  4. {
  5.     boolean tetrisMap=true;
  6.     Graphics background=null;
  7.     Color bg=new Color(0x33,0x99,0xcc);
  8.     Color fg=Color.blue;
  9.     mtetrisThread tetris;
  10.     public void init()
  11.     {
  12.         this.setLayout(new FlowLayout(FlowLayout.RIGHT,5,40));
  13.         //Button button2=new Button("Reset");
  14.         Button button1= new Button("Start");
  15.         //this.add(button2);
  16.         //this.setLayout(new FlowLayout(FlowLayout.RIGHT,5,60));
  17.         this.add(button1);
  18.         setBackground(bg);
  19.         setForeground(fg);
  20.     }
  21.     
  22.     public void start()
  23.     {
  24.         tetris=new mtetrisThread(this,10,20,bg,fg);
  25.     }    
  26.     /*public void paint(Graphics g)
  27.     *{
  28.     *    
  29.     *}
  30.     */
  31.     public void update(Graphics g)
  32.     {
  33.         g.drawLine(200,0,200,400);
  34.         g.setColor(bg);
  35.         g.fillRect(205,80,30,30);
  36.         g.setColor(fg);
  37.         g.drawString(tetris.retScore(),210,90);
  38.     }
  39.     
  40.     private boolean CommandAction(Object commandName)
  41.     {
  42.         if("Start".equals(commandName))
  43.             tetris.start();
  44.         return true;    
  45.     }
  46.     
  47.     public synchronized boolean handleEvent(Event event)
  48.     {
  49.         if(event.id==403||event.id==401)
  50.         {
  51.             tetris.keyAnswer(event.key);
  52.         }
  53.         if(event.id==1001)
  54.             return CommandAction(event.arg);
  55.         return true;
  56.     }
  57.     public synchronized void refresh()
  58.     {
  59.         repaint();
  60.     }
  61.         
  62. }    

  63. class mtetrisThread extends Thread
  64. {
  65.     private Graphics curGraphic;
  66.     private int i=0;
  67.     private mtetris curTetris;
  68.     private int width;
  69.     private int height;
  70.     private boolean mContinue;        //is the game over
  71.     private boolean mRun;            //is running
  72.     private boolean mKey;            //is calling keyAnswer()
  73.     private boolean isgetBlock;    //should get new Block
  74.     private int paintpoint[][];     
  75.     private int rootMap[][];
  76.     //public int activeMap[][];
  77.     
  78.     private int baseX;                //方块基准X
  79.     private int baseY;                //方块基准Y
  80.         
  81.     private Color bg;
  82.     private Color fg;

  83.     private static int Rotate=1004;
  84.     private static int Left=1006;
  85.     private static int Right=1007;
  86.     private static int Down=1005;

  87.     private int activeBlock[][];    //current active block
  88.     private int curBmode;            //blockmode
  89.     private int curPmode;            //paintmode
  90.     private int curCmode;            //changemode

  91.     private int score;
  92.     
  93.     public mtetrisThread(mtetris curApp,int width,int height,Color bg,Color fg)
  94.     {
  95.         curTetris=curApp;
  96.         this.width=width;
  97.         this.height=height;
  98.         this.bg=bg;
  99.         this.fg=fg;
  100.         //[0][],[1][]分别保存行坐标和纵坐标,和数组的存储是相反的
  101.         paintpoint=new int[2][width*height+1];    //[0][0]保存有效数据长度
  102.         rootMap=new int[height][width];
  103.         //activeBlock=new int[2][6];                    //[0][0] the length
  104.         
  105.         curBmode=0;                                        //blockmode
  106.         curPmode=0;                                        //paintmode
  107.         curCmode=0;                                        //changemode
  108.         score=0;
  109.         
  110.         isgetBlock=true;
  111.         mContinue=true;
  112.         mRun=true;
  113.         mKey=false;
  114.         
  115.         for(int i=0;i<height;i++)
  116.             for(int j=0;j<width;j++)
  117.                 rootMap[i][j]=0;
  118.     }
  119.     
  120.     public void keyAnswer(int key)
  121.     {
  122.         if(mContinue && !mRun)            //is Game over?
  123.         {
  124.             mKey=true;        
  125.             switch(key)
  126.             {
  127.                 case 1004:
  128.                     if(Layout(Rotate))
  129.                     {
  130.                         paintBlock(baseX,baseY,curBmode,curCmode,2);
  131.                         curCmode=(curCmode+1)%4;
  132.                         paintBlock(baseX,baseY,curBmode,curCmode,curPmode);
  133.                     }    
  134.                     break;
  135.                 case 1007:
  136.                     if(Layout(Right))
  137.                     {
  138.                         paintBlock(baseX,baseY,curBmode,curCmode,2);
  139.                         baseX++;
  140.                         paintBlock(baseX,baseY,curBmode,curCmode,curPmode);
  141.                     }
  142.                     break;
  143.                 case 1006:
  144.                     if(Layout(Left))
  145.                     {
  146.                         paintBlock(baseX,baseY,curBmode,curCmode,2);
  147.                         baseX--;
  148.                         paintBlock(baseX,baseY,curBmode,curCmode,curPmode);
  149.                     }
  150.                     break;
  151.                 case 1005:
  152.                     if(Layout(Down))
  153.                     {
  154.                         paintBlock(baseX,baseY,curBmode,curCmode,2);
  155.                         baseY++;
  156.                         paintBlock(baseX,baseY,curBmode,curCmode,curPmode);
  157.                     }
  158.                     break;
  159.             }
  160.         }
  161.         mKey=false;        
  162.         return;                
  163.     }
  164.     
  165.     public String retScore()
  166.     {
  167.         return new Integer(score).toString();
  168.     }
  169.     
  170.     private void getBlock()                //get new Block
  171.     {
  172.         curBmode=(int)(Math.random()*9571)%7;
  173.         
  174.         if(curBmode==0||curBmode==1)
  175.         {
  176.             baseX=3;
  177.             baseY=1;
  178.         }
  179.         else
  180.         {
  181.             baseX=3;
  182.             baseY=0;
  183.         }        
  184.         paintBlock(baseX,baseY,curBmode,curCmode,-1);
  185.         
  186.         //activeBlock[0][0]=paintpoint[0][0];
  187.         for(int i=1;i<=paintpoint[0][0];i++)
  188.             if(rootMap[paintpoint[1][i]][paintpoint[0][i]]!=0)
  189.             {
  190.                 GameStop();
  191.                 return;
  192.             }
  193.         Block(curPmode);    
  194.     }
  195.     
  196.     private void GameStop()
  197.     {
  198.         mContinue=false;
  199.         //curGraphic=curTetris.getGraphics();
  200.         //curGraphic.drawString("GameStop",200,20);
  201.         //curTetris.refresh();
  202.     }
  203.     
  204.     public void run()
  205.     {
  206.         while(true)
  207.         {
  208.             try
  209.             {
  210.                 sleep(300);
  211.             }
  212.             catch(InterruptedException e)
  213.             {
  214.             }
  215.             if(mContinue && !mKey)
  216.             {
  217.                 mRun=true;
  218.                 if(isgetBlock)                    //get new barrier
  219.                 {
  220.                     getBlock();
  221.                     isgetBlock=false;
  222.                     continue;
  223.                     //GameStop();
  224.                 }
  225.                 if(Layout(Down))
  226.                 {
  227.                     paintBlock(baseX,baseY,curBmode,curCmode,2);
  228.                     paintBlock(baseX,baseY+1,curBmode,curCmode,0);
  229.                     baseY++;
  230.                     /*activeBlock[0][0]=paintpoint[0][0];
  231.                     for(int i=1;i<=paintpoint[0][0];i++)
  232.                     {
  233.                         activeBlock[0][i]=paintpoint[0][i];
  234.                         activeBlock[1][i]=paintpoint[1][i];
  235.                     }*/
  236.                 }
  237.                 else
  238.                 {
  239.                     paintBlock(baseX,baseY,curBmode,curCmode,1);
  240.                     isgetBlock=true;
  241.                     //renew the changemode
  242.                     curCmode=0;
  243.                     for(int j=1;j<=paintpoint[0][0];j++)
  244.                         rootMap[paintpoint[1][j]][paintpoint[0][j]]=1;
  245.                     updateMap();
  246.                 }    
  247.             
  248.                 //curGraphic.fill3DRect(100,(100+20*i++)%400,20,20,true);
  249.             }
  250.             mRun=false;        
  251.         }
  252.     }
  253.     
  254.     private void updateMap()
  255.     {
  256.         boolean fullLine=true;
  257.         paintpoint[0][0]=0;
  258.         int count=0;
  259.         int numline=0;
  260.         for(int i=height-1;i>=0;i--)
  261.         {
  262.             for(int j=0;j<width;j++)
  263.                 if(rootMap[i][j]==0) fullLine=false;
  264.             
  265.             if(!fullLine)
  266.             {
  267.                 for(int k=0;k<width;k++)
  268.                     if(rootMap[i][k]!=0)
  269.                     {
  270.                         count++;
  271.                         paintpoint[1][count]=i+numline;
  272.                         paintpoint[0][count]=k;    
  273.                     }
  274.             }        
  275.             else
  276.             {
  277.                 numline++;
  278.                 score++;
  279.             }        
  280.             fullLine=true;        
  281.         }    
  282.         paintpoint[0][0]=count;
  283.         
  284.         if(numline==0)
  285.             return;
  286.         else
  287.         {
  288.             for(int i=0;i<height;i++)                    //refresh rootMap
  289.                 for(int j=0;j<width;j++)
  290.                 {
  291.                     rootMap[i][j]=0;
  292.                 }
  293.             for(int i=1;i<=paintpoint[0][0];i++)
  294.                 rootMap[paintpoint[1][i]][paintpoint[0][i]]=1;
  295.             
  296.             curGraphic=curTetris.getGraphics();
  297.             curGraphic.setColor(bg);
  298.             curGraphic.fillRect(0,0,200,400);
  299.             curGraphic.setColor(fg);
  300.             curTetris.refresh();
  301.             Block(1);
  302.             return;    
  303.         }                            
  304.     }
  305.     
  306.     private boolean Layout(int supposeMove)
  307.     {
  308.         boolean Feasibility=true;
  309.         switch(supposeMove)
  310.         {
  311.             case 1004:
  312.                 paintBlock(baseX,baseY,curBmode,(curCmode+1)%4,-1);
  313.                 for(int i=1;i<=paintpoint[0][0];i++)
  314.                     if(paintpoint[1][i]>=0 && paintpoint[1][i]<height && paintpoint[0][i]>=0 && paintpoint[0][i]<width)
  315.                     {
  316.                         if(rootMap[paintpoint[1][i]][paintpoint[0][i]]!=0)
  317.                             Feasibility=false;
  318.                     }
  319.                     else
  320.                     {
  321.                         return false;
  322.                     }            
  323.                 break;
  324.             case 1006:
  325.                 paintBlock(baseX-1,baseY,curBmode,curCmode,-1);
  326.                 for(int i=1;i<=paintpoint[0][0];i++)
  327.                     if(paintpoint[1][i]>=0 && paintpoint[1][i]<height && paintpoint[0][i]>=0 && paintpoint[0][i]<width)
  328.                     {
  329.                         if(rootMap[paintpoint[1][i]][paintpoint[0][i]]!=0)
  330.                             Feasibility=false;
  331.                     }
  332.                     else
  333.                     {
  334.                         return false;
  335.                     }            
  336.                 break;
  337.             case 1007:
  338.                 paintBlock(baseX+1,baseY,curBmode,curCmode,-1);
  339.                 for(int i=1;i<=paintpoint[0][0];i++)
  340.                     if(paintpoint[1][i]>=0 && paintpoint[1][i]<height && paintpoint[0][i]>=0 && paintpoint[0][i]<width)
  341.                     {
  342.                         if(rootMap[paintpoint[1][i]][paintpoint[0][i]]!=0)
  343.                             Feasibility=false;
  344.                     }
  345.                     else
  346.                     {
  347.                         return false;
  348.                     }            
  349.                 break;
  350.             case 1005:
  351.                 paintBlock(baseX,baseY+1,curBmode,curCmode,-1);
  352.                 for(int i=1;i<=paintpoint[0][0];i++)
  353.                     if(paintpoint[1][i]>=0 && paintpoint[1][i]<height && paintpoint[0][i]>=0 && paintpoint[0][i]<width)
  354.                     {
  355.                         if(rootMap[paintpoint[1][i]][paintpoint[0][i]]!=0)
  356.                             Feasibility=false;
  357.                     }
  358.                     else
  359.                     {
  360.                         return false;
  361.                     }            
  362.                 break;
  363.             default:
  364.                 Feasibility=false;    
  365.         }    
  366.         
  367.         if(paintpoint[0][0]==0)
  368.             Feasibility=false;
  369.         return Feasibility;
  370.     }
  371.     
  372.     private void Block(int paintmode)
  373.     {
  374.         boolean flag=false;
  375.         curGraphic=curTetris.getGraphics();
  376.         switch(paintmode)
  377.         {
  378.             case 0:    //绘制活动方块
  379.                 flag=true;
  380.             case 1:    //绘制固定方块
  381.                 for(int i=1;i<=paintpoint[0][0];i++)
  382.                     curGraphic.fill3DRect(paintpoint[0][i]*20,paintpoint[1][i]*20,20,20,flag);
  383.                 break;    
  384.             case 2:    //用背景色填充
  385.                 curGraphic.setColor(bg);
  386.                 for(int j=1;j<=paintpoint[0][0];j++)
  387.                     curGraphic.fillRect(paintpoint[0][j]*20,paintpoint[1][j]*20,20,20);
  388.                 curGraphic.setColor(fg);
  389.                 break;
  390.             default:
  391.                 return;    
  392.         }
  393.         curTetris.refresh();            //刷新
  394.         return;
  395.     }        
  396.     //(x,y)是方块的基准坐标,blockmode是方块样式共七种,changemode={0,1,2,3}
  397.     //paintmode={0,1,2}    
  398.     private void paintBlock(int x,int y,int blockmode,int changemode,int paintmode)
  399.     {
  400.         switch(blockmode)
  401.         {
  402.             case 0:
  403.                 paintpoint[0][0]=4;
  404.                 switch(changemode)
  405.                 {
  406.                     case 0:
  407.                         paintpoint[0][1]=x;
  408.                         paintpoint[1][1]=y-1;
  409.                         paintpoint[0][2]=x;
  410.                         paintpoint[1][2]=y;
  411.                         paintpoint[0][3]=x+1;
  412.                         paintpoint[1][3]=y;
  413.                         paintpoint[0][4]=x+1;
  414.                         paintpoint[1][4]=y+1;
  415.                         break;
  416.                     case 1:
  417.                         paintpoint[0][1]=x;
  418.                         paintpoint[1][1]=y;
  419.                         paintpoint[0][2]=x+1;
  420.                         paintpoint[1][2]=y;
  421.                         paintpoint[0][3]=x-1;
  422.                         paintpoint[1][3]=y+1;
  423.                         paintpoint[0][4]=x;
  424.                         paintpoint[1][4]=y+1;
  425.                         break;
  426.                     case 2:
  427.                         paintpoint[0][1]=x;
  428.                         paintpoint[1][1]=y;
  429.                         paintpoint[0][2]=x;
  430.                         paintpoint[1][2]=y+1;
  431.                         paintpoint[0][3]=x+1;
  432.                         paintpoint[1][3]=y+1;
  433.                         paintpoint[0][4]=x+1;
  434.                         paintpoint[1][4]=y+2;
  435.                         break;
  436.                     case 3:
  437.                         paintpoint[0][1]=x+1;
  438.                         paintpoint[1][1]=y;
  439.                         paintpoint[0][2]=x+2;
  440.                         paintpoint[1][2]=y;
  441.                         paintpoint[0][3]=x;
  442.                         paintpoint[1][3]=y+1;
  443.                         paintpoint[0][4]=x+1;
  444.                         paintpoint[1][4]=y+1;
  445.                         break;
  446.                     default:
  447.                         paintpoint[0][0]=0;    
  448.                 }
  449.                 break;
  450.             case 1:
  451.                 paintpoint[0][0]=4;
  452.                 switch(changemode)
  453.                 {
  454.                     case 0:
  455.                         paintpoint[0][1]=x+1;
  456.                         paintpoint[1][1]=y-1;
  457.                         paintpoint[0][2]=x;
  458.                         paintpoint[1][2]=y;
  459.                         paintpoint[0][3]=x+1;
  460.                         paintpoint[1][3]=y;
  461.                         paintpoint[0][4]=x;
  462.                         paintpoint[1][4]=y+1;
  463.                         break;
  464.                     case 1:
  465.                         paintpoint[0][1]=x-1;
  466.                         paintpoint[1][1]=y;
  467.                         paintpoint[0][2]=x;
  468.                         paintpoint[1][2]=y;
  469.                         paintpoint[0][3]=x;
  470.                         paintpoint[1][3]=y+1;
  471.                         paintpoint[0][4]=x+1;
  472.                         paintpoint[1][4]=y+1;
  473.                         break;
  474.                     case 2:
  475.                         paintpoint[0][1]=x+1;
  476.                         paintpoint[1][1]=y;
  477.                         paintpoint[0][2]=x;
  478.                         paintpoint[1][2]=y+1;
  479.                         paintpoint[0][3]=x+1;
  480.                         paintpoint[1][3]=y+1;
  481.                         paintpoint[0][4]=x;
  482.                         paintpoint[1][4]=y+2;
  483.                         break;
  484.                     case 3:
  485.                         paintpoint[0][1]=x;
  486.                         paintpoint[1][1]=y;
  487.                         paintpoint[0][2]=x+1;
  488.                         paintpoint[1][2]=y;
  489.                         paintpoint[0][3]=x+1;
  490.                         paintpoint[1][3]=y+1;
  491.                         paintpoint[0][4]=x+2;
  492.                         paintpoint[1][4]=y+1;
  493.                         break;
  494.                     default:
  495.                         paintpoint[0][0]=0;    
  496.                 }
  497.                 break;
  498.             case 2:                        //田字方块
  499.                 paintpoint[0][0]=4;
  500.                 paintpoint[0][1]=x;
  501.                 paintpoint[1][1]=y;
  502.                 paintpoint[0][2]=x;
  503.                 paintpoint[1][2]=y+1;
  504.                 paintpoint[0][3]=x+1;
  505.                 paintpoint[1][3]=y+1;
  506.                 paintpoint[0][4]=x+1;
  507.                 paintpoint[1][4]=y;
  508.                 break;
  509.             case 3:                        //Shape of 7
  510.                 paintpoint[0][0]=4;
  511.                 switch(changemode)
  512.                 {
  513.                     case 0:
  514.                         paintpoint[0][1]=x+1;
  515.                         paintpoint[1][1]=y;
  516.                         paintpoint[0][2]=x-1;
  517.                         paintpoint[1][2]=y+1;
  518.                         paintpoint[0][3]=x;
  519.                         paintpoint[1][3]=y+1;
  520.                         paintpoint[0][4]=x+1;
  521.                         paintpoint[1][4]=y+1;
  522.                         break;
  523.                     case 1:
  524.                         paintpoint[0][1]=x;
  525.                         paintpoint[1][1]=y;
  526.                         paintpoint[0][2]=x+1;
  527.                         paintpoint[1][2]=y;
  528.                         paintpoint[0][3]=x+1;
  529.                         paintpoint[1][3]=y+1;
  530.                         paintpoint[0][4]=x+1;
  531.                         paintpoint[1][4]=y+2;
  532.                         break;
  533.                     case 2:
  534.                         paintpoint[0][1]=x;
  535.                         paintpoint[1][1]=y;
  536.                         paintpoint[0][2]=x+1;
  537.                         paintpoint[1][2]=y;
  538.                         paintpoint[0][3]=x+2;
  539.                         paintpoint[1][3]=y;
  540.                         paintpoint[0][4]=x;
  541.                         paintpoint[1][4]=y+1;
  542.                         break;
  543.                     case 3:
  544.                         paintpoint[0][1]=x;
  545.                         paintpoint[1][1]=y-1;
  546.                         paintpoint[0][2]=x;
  547.                         paintpoint[1][2]=y;
  548.                         paintpoint[0][3]=x;
  549.                         paintpoint[1][3]=y+1;
  550.                         paintpoint[0][4]=x+1;
  551.                         paintpoint[1][4]=y+1;
  552.                         break;
  553.                     default:
  554.                         paintpoint[0][0]=0;    
  555.                 }
  556.                 break;
  557.             case 4:                            //Shape of reverse 7    
  558.                 paintpoint[0][0]=4;
  559.                 switch(changemode)
  560.                 {
  561.                     case 0:
  562.                         paintpoint[0][1]=x-1;
  563.                         paintpoint[1][1]=y;
  564.                         paintpoint[0][2]=x;
  565.                         paintpoint[1][2]=y;
  566.                         paintpoint[0][3]=x+1;
  567.                         paintpoint[1][3]=y;
  568.                         paintpoint[0][4]=x+1;
  569.                         paintpoint[1][4]=y+1;
  570.                         break;
  571.                     case 1:
  572.                         paintpoint[0][1]=x;
  573.                         paintpoint[1][1]=y;
  574.                         paintpoint[0][2]=x+1;
  575.                         paintpoint[1][2]=y;
  576.                         paintpoint[0][3]=x;
  577.                         paintpoint[1][3]=y+1;
  578.                         paintpoint[0][4]=x;
  579.                         paintpoint[1][4]=y+2;
  580.                         break;
  581.                     case 2:
  582.                         paintpoint[0][1]=x;
  583.                         paintpoint[1][1]=y;
  584.                         paintpoint[0][2]=x;
  585.                         paintpoint[1][2]=y+1;
  586.                         paintpoint[0][3]=x+1;
  587.                         paintpoint[1][3]=y+1;
  588.                         paintpoint[0][4]=x+2;
  589.                         paintpoint[1][4]=y+1;
  590.                         break;
  591.                     case 3:
  592.                         paintpoint[0][1]=x+1;
  593.                         paintpoint[1][1]=y-1;
  594.                         paintpoint[0][2]=x+1;
  595.                         paintpoint[1][2]=y;
  596.                         paintpoint[0][3]=x+1;
  597.                         paintpoint[1][3]=y+1;
  598.                         paintpoint[0][4]=x;
  599.                         paintpoint[1][4]=y+1;
  600.                         break;
  601.                     default:
  602.                         paintpoint[0][0]=0;    
  603.                 }        
  604.                 break;
  605.             case 5:                                //Shape of T
  606.                 paintpoint[0][0]=4;
  607.                 switch(changemode)
  608.                 {
  609.                     case 0:
  610.                         paintpoint[0][1]=x;
  611.                         paintpoint[1][1]=y;
  612.                         paintpoint[0][2]=x-1;
  613.                         paintpoint[1][2]=y+1;
  614.                         paintpoint[0][3]=x;
  615.                         paintpoint[1][3]=y+1;
  616.                         paintpoint[0][4]=x+1;
  617.                         paintpoint[1][4]=y+1;
  618.                         break;
  619.                     case 1:
  620.                         paintpoint[0][1]=x+1;
  621.                         paintpoint[1][1]=y;
  622.                         paintpoint[0][2]=x;
  623.                         paintpoint[1][2]=y+1;
  624.                         paintpoint[0][3]=x+1;
  625.                         paintpoint[1][3]=y+1;
  626.                         paintpoint[0][4]=x+1;
  627.                         paintpoint[1][4]=y+2;
  628.                         break;
  629.                     case 2:
  630.                         paintpoint[0][1]=x;
  631.                         paintpoint[1][1]=y;
  632.                         paintpoint[0][2]=x+1;
  633.                         paintpoint[1][2]=y;
  634.                         paintpoint[0][3]=x+2;
  635.                         paintpoint[1][3]=y;
  636.                         paintpoint[0][4]=x+1;
  637.                         paintpoint[1][4]=y+1;
  638.                         break;
  639.                     case 3:
  640.                         paintpoint[0][1]=x;
  641.                         paintpoint[1][1]=y-1;
  642.                         paintpoint[0][2]=x;
  643.                         paintpoint[1][2]=y;
  644.                         paintpoint[0][3]=x+1;
  645.                         paintpoint[1][3]=y;
  646.                         paintpoint[0][4]=x;
  647.                         paintpoint[1][4]=y+1;
  648.                         break;
  649.                     default:
  650.                         paintpoint[0][0]=0;
  651.                 }            
  652.                 break;
  653.             case 6:                                //Shape of l
  654.                 paintpoint[0][0]=4;
  655.                 switch(changemode)
  656.                 {
  657.                     case 0:
  658.                         paintpoint[0][1]=x-1;
  659.                         paintpoint[1][1]=y;
  660.                         paintpoint[0][2]=x;
  661.                         paintpoint[1][2]=y;
  662.                         paintpoint[0][3]=x+1;
  663.                         paintpoint[1][3]=y;
  664.                         paintpoint[0][4]=x+2;
  665.                         paintpoint[1][4]=y;
  666.                         break;
  667.                     case 1:
  668.                         paintpoint[0][1]=x;
  669.                         paintpoint[1][1]=y-1;
  670.                         paintpoint[0][2]=x;
  671.                         paintpoint[1][2]=y;
  672.                         paintpoint[0][3]=x;
  673.                         paintpoint[1][3]=y+1;
  674.                         paintpoint[0][4]=x;
  675.                         paintpoint[1][4]=y+2;
  676.                         break;
  677.                     case 2:
  678.                         paintpoint[0][1]=x-1;
  679.                         paintpoint[1][1]=y+1;
  680.                         paintpoint[0][2]=x;
  681.                         paintpoint[1][2]=y+1;
  682.                         paintpoint[0][3]=x+1;
  683.                         paintpoint[1][3]=y+1;
  684.                         paintpoint[0][4]=x+2;
  685.                         paintpoint[1][4]=y+1;
  686.                         break;
  687.                     case 3:
  688.                         paintpoint[0][1]=x+1;
  689.                         paintpoint[1][1]=y-1;
  690.                         paintpoint[0][2]=x+1;
  691.                         paintpoint[1][2]=y;
  692.                         paintpoint[0][3]=x+1;
  693.                         paintpoint[1][3]=y+1;
  694.                         paintpoint[0][4]=x+1;
  695.                         paintpoint[1][4]=y+2;
  696.                         break;
  697.                     default:
  698.                         paintpoint[0][0]=0;
  699.                 }            
  700.                 break;
  701.             default:
  702.                 return;    
  703.         }
  704.         if(paintmode!=-1)
  705.         {
  706.             Block(paintmode);
  707.             return;
  708.         }
  709.             return;
  710.     }                
  711. }

需要和html页面在同一目录下:

点击(此处)折叠或打开

  1. <html>
  2. <center>
  3. <applet code = "mtetris.class" width=250 height=400>
  4. </applet>
  5. </center>
  6. </html>


阅读(925) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~