Me下的贪吃蛇小游戏
来源:技术人生 责任编辑:栏目编辑 发表时间:2013-07-01 11:53 点击:次
package com.game;
import java.util.Vector;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
public class SnakeMap_Canvas extends Canvas
{
private Vector Snake_List=new Vector() ;//用来储存蛇的单元容器
private int Canvas_Width=0;//画板的宽度
private int Canvas_Height=0;//画板的高度
static Snake_Element element;
static Snake_Element element1;
static Snake_Element element2;
static Snake_Element headSanke;
int i=0;
int j =0;
public SnakeMap_Canvas()
{
Canvas_Width=getWidth();
Canvas_Height=getHeight();
for(int i=0;i<8;i++)//初始化开始蛇身共有八段
{
Snake_List.addElement(new Snake_Element(40-i*Snake_Direction.SNAKE_SIZE,50));
}
new SnakeMoveThread().start();
}
protected void paint(Graphics g)
{
/*****************
* 清屏相当于重画
* ***************/
g.setColor(255, 255, 255);
g.fillRect(0, 0, Canvas_Width, Canvas_Height);
g.setColor(0,0,0);
for(i=0;i<Snake_List.size();i++)
{
element =(Snake_Element)Snake_List.elementAt(i);
g.fillRect(element.getPoint_x(), element.getPoint_Y(), element.getSize(), element.getSize());
}
}
private class SnakeMoveThread extends Thread
{
public void run()
{
while(true)
{
sanke_Move();<
相关新闻>>
- 发表评论
-
- 最新评论 更多>>