乔山办公网我们一直在努力
您的位置:乔山办公网 > excel表格制作 > 做出来一个贪吃蛇,俄罗斯方块难吗-excel俄罗斯方块,excel俄罗斯方块制作代码

做出来一个贪吃蛇,俄罗斯方块难吗-excel俄罗斯方块,excel俄罗斯方块制作代码

作者:乔山办公网日期:

返回目录:excel表格制作


import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Game extends JFrame implements KeyListener,Runnable
{
Thread Down10 = new Thread(this);
GameCanvas test = new GameCanvas();
JLabel LabelTetris = new JLabel("Tetris Game");
JLabel ScorePrint1 = new JLabel("Score");
JLabel ScorePrint2 = new JLabel("0"+test.Score);
Game()
{
7a64e78988e69d83365setSize(400,800);
setVisible(true);
setLayout(new FlowLayout());
test.addKeyListener(this);
LabelTetris.setBackground(Color.white);
LabelTetris.setFont((new Font("Tahoma",1,50)));
ScorePrint1.setFont((new Font("Tahoma",1,40)));
ScorePrint2.setBackground(Color.white);
JLabel LM = new JLabel("L.M");
ScorePrint2.setFont((new Font("Tahoma",1,40)));
add(LabelTetris);
add(test);
add(ScorePrint1);
add(ScorePrint2);
LM.setForeground(Color.white);
add(LM);
validate();
Down10.start();
}
public void run()
{
while(true)
{
try
{
test.Down1();
Down10.sleep(700);
}
catch(InterruptedException I){I.printStackTrace();}
}
}
public void keyPressed(KeyEvent K)
{
if(K.getKeyCode()==KeyEvent.VK_LEFT)
test.Left1();
else if(K.getKeyCode()==KeyEvent.VK_UP)
test.Turn();
else if(K.getKeyCode()==KeyEvent.VK_RIGHT)
test.Right1();
else if(K.getKeyCode()==KeyEvent.VK_DOWN)
{
test.Down1();
if(test.ScoreBool==1)
{ScorePrint2.setText(""+test.Score);}
}
}
public void keyReleased(KeyEvent e){}
public void keyTyped(KeyEvent e){}
}
class GameCanvas extends Canvas
{
int x=5,y=0;
int GameMap[][]=new int [50][100];
int BlockShape;
int BlockWay;
int Score=0;
int ScoreBool=0;
int OverBool=0;
public final static int[][][] Blocks={{{0,0,0,0,1,1,1,1,0,0,0,0,0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;i<16;i++)
{
GameMap[i][24]=2;
}
}
public void NewBlocks()
{
x=5;y=0;
BlockShape=(int)(Math.random()*6);
BlockWay=(int)(Math.random()*3);
if(IsOver(x,y)==true)
{OverBool=1;}
}
public void Keep(int x,int y,int BlockShape,int BlockWay)
{
int n=0;
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
{
if(GameMap[x+j+1][y+i]==0)
{
GameMap[x+j+1][y+i]=Blocks[BlockShape][BlockWay][n];
}
n++;
}
}
public void paint(Graphics G)
{
G.setColor(Color.white);
for(int i=0;i<16;i++)
{
if(Blocks[BlockShape][BlockWay][i]==1)
G.drawRect((i%4+x+1)*20,(i/4+y)*20,20,20);
}
for(int i=0;i<30;i++)
for(int j=0;j<50;j++)
if(GameMap[i][j]==1||GameMap[i][j]==2)
G.fillRect(i*20,j*20,20,20);
}
public void Turn()
{
if(IsFeasible(x,y,BlockShape,BlockWay)==1)
{
BlockWay=(BlockWay+1)%4;
repaint();
}
}
public void Left1()
{
if(IsFeasible(x-1,y,BlockShape,BlockWay)==1)
{
x-=1;
repaint();
}
}
public void Right1()
{
if(IsFeasible(x+1,y,BlockShape,BlockWay)==1)
{
x+=1;
repaint();
}
}
public void Down1()
{
if(IsFeasible(x,y+1,BlockShape,BlockWay)==1)
{
y+=1;
repaint();
}
else if(IsFeasible(x,y+1,BlockShape,BlockWay)==0)
{
Keep(x,y,BlockShape,BlockWay);
Deline();
if(OverBool==0)
NewBlocks();
}
}
public int IsFeasible(int x,int y,int BlockShape,int BlockWay)
{
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
if(Blocks[BlockShape][BlockWay][i*4+j]==1&&GameMap[x+j+1][y+i]==1)
return 0;
else if(Blocks[BlockShape][BlockWay][i*4+j]==1&&GameMap[x+j+1][y+i]==2)
return 0;
}
}
return 1;
}
public void Deline()
{
int BlocksSum = 0;
for(int i=0;i<25;i++)
{
for(int j=0;j<16;j++)
{
if (GameMap[j][i]==1)
{
BlocksSum++;
if (BlocksSum==15)
{
for(int p=i;p>0;p--)
{
for(int q=0;q<16;q++)
{
GameMap[q][p]=GameMap[q][p-1];
}
}
Score+=10;
ScoreBool=1;
}
}
}
BlocksSum = 0;
}
}
public boolean IsOver(int x,int y)
{
if(IsFeasible(x,y,BlockShape,BlockWay)==0)
return true;
else
return false;
}
}
public class Tetris
{
public static void main(String[] args)
{
Game test2 = new Game();
}
}

拿去玩 JAVA新建文件命名为 Tetris 以前写的 懒得布置界面

dowhile 循环是 while 循环的变种。
该循环程序在初次运行时会首先执行一遍其中的代码,然后当指定的条件为 true 时,它会继续这个循环。
所以可以这么说,dowhile 循环至少执行一遍其中的代码,即使条件为 false,因为其中的代码执行后才会进行条件验证。

现在来分析:
(1):先执行到最后一个e 的时候:
do{
result=patt1.exec("The best things in life are free");
document.write(result);
}
这时页面上的result就是eeeeee

(2):下来继续验证执行
result的值e799bee5baa6e79fa5e98193e78988e69d83361为eeeeee,
while判断result不为空,又继续执行
do{
result=patt1.exec("The best things in life are free");
document.write(result);
}
这时指针已经到了末尾,返回的就是null。

所以document.write(result)就打印了null。
加起来就是eeeeeenull。

这个问题所在就是,你要理解了do while的运行原理。
它是先执行代码,再去验证。
遇到问题不解的时候,可以跟着程序一步一步的去查看,为什么会出现null ,是从哪里出来的,搞清楚了它的“错误”步骤,结合掌握的do while 就会想通了。

希望可以帮到你,^_~
没必要。有些知识时间久了自然就会了。可以试着写点其它的小东西。

1、互联网上有现成的例子,是用excel的二次开发语言VBA写的。
2、代码很多不copy能都贴上来。需要的话可以给你发邮件。
3、具体方法就是先做好用户窗体
4、做好方块的模型zd
5、方向键控制方块的移动
6、方块的生成是随机的

相关阅读

关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网