快速业务通道

如何使用J2ME中的线程 - 编程入门网

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-06-19
e (Blocker != null) { } } ... }

F. 程序逻辑:下面给出程序清单。程序中我们使用一个数组来存储方块的信息,一共有十九种,还有一个数组来存储当前的画面方格的内容.在程序中

有一个paint方法来实现重画,注意绘制的先后次序,当程序规模变得很大的时候,重画的效率就非常重要,需要进行优化.我们在程序中使用了背景,

在没有背景的情况下,程序仅5k,采用背景后,程序47k,可见对图片的优化至关重要.

/* * TetrisCanvas.java * * Created on 2005年7月13日, 上午11:31 * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */ package Tetris; import java.util.*; import java.lang.Math; import javax.microedition.lcdui.*; /** * * @author lin */ public class TetrisCanvas extends Canvas implements Runnable{ private Thread Blocker = null; private Random generator; private int FutureBlockType, BlockType,LastType,LastX,LastY,BlockX,BlockY ; private int BlockLines,BlockScore; private int BlockSpeed,CurSpeed; private static final int COLOR_GRAY = 0x00eeeeee; private static final int COLOR_RED = 0x00ff0000; private static final int COLOR_BLACK = 0x00000000; private static final int COLOR_WHITE = 0x00ffffff; private static final int COLOR_BLUE = 0x000000ff; private static final int COLOR_LIGHT_BLUE= 0x0089a5d1; private static final int COLOR_DARK_GRAY = 0x00808080; private static final int COLOR_BACKGROUND= COLOR_LIGHT_BLUE; private static final int BLOCK_SIZE = 7; private static final int CANVAS_SIZE_WIDTH = 12; private static final int CANVAS_SIZE_HEIGHT = 22; private static final int CANVAS_OFFSET_X = 5; private static final int CANVAS_OFFSET_Y = 7; /** * The paint status. */ boolean ISCLEAR = false; boolean ISDOWN = false; boolean ISDEL = false; /** * the block information matrix. */ int BlockInfo[][]={{1,0,1,1,1,2,1,3,0xff0000,2}, {0,1,1,1,2,1,3,1,0xff0000,4}, {0,0,0,1,1,1,1,2,0x0000ff,2}, {0,1,1,0,1,1,2,0,0x0000ff,3}, {0,1,0,2,1,0,1,1,0x00ff00,2}, {0,0,1,0,1,1,2,1,0x00ff00,3}, {0,0,0,1,1,0,1,1,0xffff00,2}, {0,1,1,0,1,1,1,2,0x00ffff,2}, {0,1,1,0,1,1,2,1,0x00ffff,3}, {1,0,1,1,1,2,2,1,0x00ffff,3}, {0,1,1,1,1,2,2,1,0x00ffff,3}, {0,1,0,2,1,1,2,1,0xff00ff,3}, {0,0,1,0,1,1,1,2,0xff00ff,3}, {0,1,1,1,2,0,2,1,0xff00ff,3}, {1,0,1,1,1,2,2,2,0xff00ff,3}, {0,0,0,1,1,1,2,1,0xffffff,3}, {1,0,1,1,1,2,2,0,0xffffff,3}, {0,1,1,1,2,1,2,2,0xffffff,3}, {0,2,1,0,1,1,1,2,0xffffff,3}, }; // Gridmatrix 中只存储颜色信息 int Gridmatrix[][]=new int[CANVAS_SIZE_HEIGHT][CANVAS_SIZE_WIDTH]; /** * Initialize the applet. Resize and load images. */ public void init() { BlockType=Math.abs(generator.nextInt()%19); FutureBlockType=Math.abs(generator.nextInt()%19); LastType=BlockType; BlockLines=0; BlockScore=0; BlockSpeed=1; CurSpeed=BlockSpeed; BlockX=4; LastX=BlockX; BlockY=0; LastY=BlockY; //初始化Gridmatrix矩阵,内容为带边框的主绘图区。 for(int i=0;i for(int j=0;j Gridmatrix[i][j]=0; for(int i=0;i Gridmatrix[CANVAS_SIZE_HEIGHT-1][i]=COLOR_DARK_GRAY; for(int i

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站: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号