用java编写的俄罗斯方块小游戏
时间:2011-01-22
import java.awt.*;
import java.applet.Applet;
public class Blocks extends Applet implements Runnable
{
Dimension d;
Font largefont= new Font("Helvetica", Font.BOLD, 28);
Font smallfont= new Font("Helvetica", Font.BOLD, 10);
Color textcolor1=new Color(96,128,255);
Color textcolor2=new Color(255,160,64);
FontMetrics fmsmall, fmlarge;
Graphics goff;
Image ii;
Threadthethread;
boolean ingame=false;
final short xblocks=10;
final short yblocks=20;
final int blocksize=16;
final int width=xblocks*blocksize;
final int height=yblocks*blocksize;
short[][] screendata;
final short maxcolors=6;
Color[] blocks;
final int barwidth=8;
final Color barcolor=new Color(128,255,64);
final Color background=new Color(0,0,0);
int score;
short emptyline;
int objectx, objecty;
int objectx;
short objecttype;
short objectcolor;
int objectrotation;
int objectrotationd=0;
short objectptr;
short checkptr;
final short itemcount=7;
final short itemrotlen=8;
final short itemlen=itemrotlen*4;
short count;
final short maxcount=5;
short curcount;
boolean fast=false;
final short screendelay=40;
short screencount=40;
boolean showtitle=true;
int items[]={
0,0, -1,0, 0,-1, -1,-1, //四方形,正常状态
0,0, -1,0, 0,1, -1,1, //被旋转90度
0,0, 1,0, 0,1, 1,1,
0,0, 1,0, 0,-1, 1,-1,
0,0, 0,-1, 0,-2, 0,-3,
0,0, -1,0, -2,0, -3,0,
0,0, 0,1, 0,2, 0,3,
0,0, 1,0, 2,0, 3,0,
0,0, 1,0, 0,-1, -1,-1,
0,0, 0,-1, -1,0, -1,1,
0,0, -1,0, 0,1, 1,1,
0,0, 0,1, 1,0, 1,-1,
0,0, -1,0, 0,-1, 1,-1,
0,0, 0,1, -1,0, -1,-1,
0,0, 1,0, 0,1, -1,1,
0,0, 0,-1, 1,0, 1,1,
0,0, 1,0, -1,0, 0,-1,
0,0, 0,1, 0,-1, -1,0,
0,0, 0,1, -1,0, 1,0,
0,0, 1,0, 0,-1, 0,1,
0,0, 0,-1, 1,-1, 0,1,
0,0, -1,0, -1,-1, 1,0,
0,0, -1,1, 0,1, 0,-1,
0,0, -1,0, 1,0, 1,1,
0,0, 0,1, 0,-1, -1,-1,
0,0, 1,0, -1,0, -1,1,
0,0, 0,-1, 0,1, 1,1,
0,0, -1,0, 1,0, 1,-1,
};
int checks[]={
-1,1, 0,1, -1,1, 0,1,
-1,2, 0,2, -1,2, 0,2,
0,2, 1,2, 0,2, 1,2,
0,1, 1,1, 0,1, 1,1,
0,1, 0,1, 0,1, 0,1,
0,1, -1,1, -2,1, -3,1,
0,4, 0,4, 0,4, 0,4,
0,1, 1,1, 2,1, 3,1,
0,1, -1,0, 1,1, 0,1,
0,1, -1,2, 0,1, -1,2,
0,2, 1,2, -1,2, 0,2,
0,2, 1,1, 0,2, 1,1,
-1,1, 0,1, 1,0, 1,0,
-1,1, 0,2, 0,2, -1,1,
-1,2, 0,2, 1,1, 1,1,
0,1, 1,2, 0,1, 1,2,
-1,1, 0,1, 1,1, 1,1,
-1,1, 0,2, 0,2, -1,1,
-1,1, 0,2, 1,1, 1,1,
0,2, 1,1, 0,2, 1,1,
0,2, 1,0, 1,0, 0,2,
-1,1, 0,1, 1,1, 1,1,
-1,2, 0,2, 0,2, -1,2,
-1,1, 0,1, 1,2, 1,2,
-1,0, 0,2, 0,2, -1,0,
-1,2, 0,1, 1,1, 1,1,
0,2, 1,2, 1,2, 0,2,
-1,1, 0,1, 1,1, 1,1,
};
public string getAppletInfo()
{
return("Blocks - by Ali");
}
//初始化applet
public void init()
{
short i;
screendata=new short[xblocks][yblocks];
blocks=new Color[maxcolors+1];
//设置背景色
blocks[0]=background;
//设置方块颜色
blocks[1]=new Color(255,0,0);
blocks[2]=new Color(0,255,0);
blocks[3]=new Color(0,0,255);
blocks[4]=new Color(255,255,0);
blocks[5]=new Color(255,0,255);
blocks[6]=new Color(0,255,255);
Graphics g;
resize(width+2*barwidth,height+30);
d=size();
setBackground(background);
g=getGraphics();
g.setFont(
|