快速业务通道

用java编写的俄罗斯方块小游戏 - 编程入门网

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-06-20

用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(

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号