package form.act;
import java.io.IOException;
import java.io.InputStream;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.KeyEvent;
import android.view.View;
import android.graphics.*;
import android.graphics.Bitmap.Config;
import android.graphics.Paint.Style;
import android.graphics.drawable.BitmapDrawable;
public class Game extends Activity {
MediaPlayer mp;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new GameView(this));
mp=MediaPlayer.create(this, R.drawable.xh);
mp.setLooping(false);
}
//自定义view
public class GameView extends View
{
//初始方块显示位置
public float eleX=75f,eleY=15f;
//关卡
public int GuanQia=1;
//得分
public int Scroll=0;
//方块下落速度
public int speed=1000;
//各种方块bitmap数组
Bitmap[] Block;
//当前下落方块
public Bitmap CurrentBlock;
//落定方块画布
public Bitmap Tcanvas;
//绘制落定方块的Canvas
public Canvas CurrentCv;
//当前随机下落方块的编号
public int CurrentNum;
//整体画布对应的二维数组
public int[][] arrBlock;
//当前下落方块所在的对应而为数组的位置
Point[] CurrentPoint;
//画小方块paint
Bitmap smBlock;
public GameView(Context context) {
super(context);
// TODO Auto-generated constructor stub
setFocusable(true); //允许获得焦点
setFocusableInTouchMode(true); //获取焦点时允许触控
Block=new Bitmap[7];//各种方块bitmap数组
Block[0]=Bitmap.createBitmap(30, 30, Config.ARGB_8888);
Block[1]=Bitmap.createBitmap(45, 45, Config.ARGB_8888);
Block[2]=Bitmap.createBitmap(45, 45, Config.ARGB_8888);
Block[3]=Bitmap.createBitmap(45, 45, Config.ARGB_8888);
Block[4]=Bitmap.createBitmap(15, 60, Config.ARGB_8888);
Block[5]=Bitmap.createBitmap(45, 45, Config.ARGB_8888);
Block[6]=Bitmap.createBitmap(45, 45, Config.ARGB_8888);
Tcanvas=Bitmap.createBitmap(195, 405, Config.ARGB_8888);
smBlock=Bitmap.createBitmap(15, 15, Config.ARGB_8888);
CurrentCv=new Canvas(Tcanvas);
arrBlock=new int[15][28];
CurrentPoint=new Point[4];
CurrentPoint[0]=new Point();
CurrentPoint[1]=new Point();
CurrentPoint[2]=new Point();
CurrentPoint[3]=new Point();
for(int i=0;i<15;i++)
{
for(int j=0;j<28;j++)
{
if(i==0||i==14)
{
arrBlock[i][j]=2;
}
else
{
if(j==27)
{
arrBlock[i][j]=2;
}
else
{
arrBlock[i][j]=0;
}
}
}
}
drawTian(Block[0]);
drawL(Block[1]);
draw_L(Block[2]);
draw_tu(Block[3]);
draw_yi(Block[4]);
draw_yu(Block[5]);
draw_fyu(Block[6]);
draw_smBlock(smBlock);
Csh();
//第一秒后,没500毫秒执行一次
timer.schedule(task, speed,1000);
}
//定义计时器
Timer timer = new Timer();
Handler handler = new Handler(){
public void handleMessage(Message msg) {
switch (msg.what) {
case 1:
if(arrBlock[CurrentPoint[0].x][CurrentPoint[0].y+1]==0&&
arrBlock[CurrentPoint[1].x][CurrentPoint[1].y+1]==0&&
arrBlock[CurrentPoint[2].x][CurrentPoint[2].y+1]==0&&
arrBlock[CurrentPoint[3].x][CurrentPoint[3].y+1]==0)
{
eleY=eleY+15f;
CurrentPoint[0].y++;
CurrentPoint[1].y++;
CurrentPoint[2].y++;
CurrentPoint[3].y++;
}
else
{
Stop();
invalidate();
}
invalidate();
break;
}
super.handleMessage(msg);
}
};
TimerTask task = new TimerTask(){
public void run() {
Message message = new Message();
message.what = 1;
handler.sendMessage(message);
}
};
@Override
public void onDraw(Canvas cv)
{
DrawBackGround(cv);
cv.drawBitmap(CurrentBlock, eleX, eleY, null);
cv.drawBitmap(Tcanvas, 15f, 15f, null);
}
//初始化
public void Csh()
{
eleX=75f;eleY=15f;
Random R=new Random();
CurrentNum=R.nextInt(7);
DrawBlockPoint(CurrentNum);
CurrentBlock=Block[CurrentNum];
}
//方块停止运动
public void Stop()
{
mp.start();
float x=eleX-15f,y=eleY-15f;
arrBlock[CurrentPoint[0].x][CurrentPoint[0].y]=1;
CurrentCv.drawBitmap(smBlock, (CurrentPoint[0].x-1)*15, (CurrentPoint[0].y)*15, null);
arrBlock[CurrentPoint[1].x][CurrentPoint[1].y]=1;
CurrentCv.drawBitmap(smBlock, (CurrentPoint[1].x-1)*15, (CurrentPoint[1].y)*15, null);
arrBlock[CurrentPoint[2].x][CurrentPoint[2].y]=1;
CurrentCv.drawBitmap(smBlock, (CurrentPoint[2].x-1)*15, (CurrentPoint[2].y)*15, null);
arrBlock[CurrentPoint[3].x][CurrentPoint[3].y]=1;
CurrentCv.drawBitmap(smBlock, (CurrentPoint[3].x-1)*15, (CurrentPoint[3].y)*15, null);
//消行方法
for(int j=0;j<=26;j++)
{
if(arrBlock[1][j]==1&&arrBlock[2][j]==1&&arrBlock[3][j]==1&&arrBlock[4][j]==1&&arrBlock[5][j]==1&&
arrBlock[6][j]==1&&arrBlock[7][j]==1&&arrBlock[8][j]==1&&arrBlock[9][j]==1&&arrBlock[10][j]==1&&
arrBlock[11][j]==1&&arrBlock[12][j]==1&&arrBlock[13][j]==1)
{
Bitmap buffer=Bitmap.createBitmap(195, 405, Config.ARGB_8888);
Canvas cvBuffer=new Canvas(buffer);
//消去的行数组为0
for(int i=1;i<=13;i++)
{
arrBlock[i][j]=0;
}
//将此行上面为1的元素向下移动一格
for(int n=1;n<=13;n++)
{
for(int m=j-1;m>=0;m--)
{
if(arrBlock[n][m]==1)
{
arrBlock[n][m+1]=1;
arrBlock[n][m]=0;
}
}
}
//遍历数组中的元素,重新绘制Tcanvas
for(int n=1;n<=13;n++)
{
for(int m=0;m<=26;m++)
{
if(arrBlock[n][m]==1)
{
cvBuffer.drawBitmap(smBlock, (n-1)*15, m*15, null);
}
}
}
//加分
this.Scroll++;
//转换bitmap
Tcanvas=Bitmap.createBitmap(buffer);
CurrentCv=new Canvas(Tcanvas);
buffer.recycle();
}
}
Csh();
}
//事件按键事件
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
//处理按键事件,响应的轨迹球事件为 public boolean onTrackballEvent (MotionEvent event)
int tempX1,tempY1,tempX2,tempY2,tempX3,tempY3,tempX4,tempY4;
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_UP:
tempX1=CurrentPoint[0].x;
tempY1=CurrentPoint[0].y;
tempX2=CurrentPoint[1].x;
tempY2=CurrentPoint[1].y;
tempX3=CurrentPoint[2].x;
tempY3=CurrentPoint[2].y;
tempX4=CurrentPoint[3].x;
tempY4=CurrentPoint[3].y;
switch(CurrentNum)
{
case 0://田
break;
case 1://L
CurrentPoint[0].set(tempY2-tempY1+tempX2,tempX1+tempY2-tempX2
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
ActTest.rar (57个子文件)
ActTest
.project 843B
default.properties 364B
bin
form
act
Game$GameView$2.class 808B
R$string.class 397B
R$layout.class 393B
Game.class 841B
R$drawable.class 614B
Game$GameView$1.class 1KB
R.class 461B
Game$GameView$4.class 874B
Login.class 2KB
R$attr.class 310B
Game$GameView.class 12KB
Game$GameView$3.class 972B
R$id.class 443B
ActTest.apk 90KB
resources.ap_ 80KB
act
data
classes.dex 16KB
AndroidManifest.xml 744B
src
form
act
Game.java 19KB
Login.java 2KB
act
data
GameView.java 153B
res
values
strings.xml 173B
layout
login.xml 739B
game.xml 265B
drawable-ldpi
yu.png 3KB
fyu.png 3KB
xh.wav 12KB
yi.png 3KB
tu.png 3KB
l.png 3KB
smallblock.png 3KB
icon.png 4KB
fl.png 3KB
tian.png 3KB
drawable-hdpi
yu.png 3KB
fyu.png 3KB
xh.wav 12KB
yi.png 3KB
tu.png 3KB
l.png 3KB
smallblock.png 3KB
icon.png 4KB
fl.png 3KB
tian.png 3KB
drawable-mdpi
yu.png 3KB
fyu.png 3KB
xh.wav 12KB
yi.png 3KB
tu.png 3KB
l.png 3KB
smallblock.png 3KB
icon.png 3KB
fl.png 3KB
tian.png 3KB
.classpath 280B
gen
form
act
R.java 1KB
assets
共 57 条
- 1
资源评论
- xihuanxuexi11172014-05-05不错的小程序谢谢
- whj4122538672014-05-23不错的程序
- angge42013-06-09还不错,看了很给力嘛
- changwazi122014-03-14基本功能差不多都有实现,还可以
arthasiori
- 粉丝: 9
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功