package deom.test;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Toast;
public class imgView extends View{
private int x;
private int y;
private int blowupTimes;
private int blowupX;
private int blowupY;
private Bitmap blowup;
private Bitmap bg;
private Bitmap grassland;
private Bitmap mountains;
private Context imgContext;
private int count;
private foodItem[] foodItems;
private int point=0;
private Paint paint;
public cow gamecow;
public imgView(Context context) {
super(context);
x=112;
y=370;
count=10;
blowupTimes=0;
foodItems=new foodItem[count];
gamecow=new cow(context);
imgContext=context;
paint = new Paint();
paint.setColor(Color.RED);
paint.setStyle(Style.FILL);
paint.setTextSize(30);
bg=BitmapFactory.decodeResource(context.getResources(),R.drawable.bg);
mountains=BitmapFactory.decodeResource(context.getResources(),R.drawable.mountains);
grassland=BitmapFactory.decodeResource(context.getResources(),R.drawable.grassland);
blowup=BitmapFactory.decodeResource(context.getResources(),R.drawable.blow_up);
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawColor(Color.rgb(123, 204, 246));
canvas.drawBitmap(mountains, 0, 480 - 176- 75 , null);
canvas.drawBitmap(grassland, 0, 480 - 127 , null);
gamecow.draw(canvas,x,y);
drawFoods(canvas);
if(blowupTimes!=0)
{
canvas.drawBitmap(blowup,blowupX, blowupY, null);
blowupTimes--;
}
drawlife(canvas);
drawPoint(canvas);
}
private void drawFoods(Canvas canvas)
{
int j;
for(j=0;j<foodItems.length;j++)
{
if (foodItems[j]!=null)
{
foodItems[j].draw(canvas);
if (foodItems[j].isEat(gamecow.getx(), gamecow.gety()))
{
if(foodItems[j].getStyle()==0)
{
point=point+30;
if (point!=0&&point%180==0) gamecow.addlife();
}
else
blowup(canvas);
foodItems[j]=null;
}
if (foodItems[j]!=null&&foodItems[j].getY()>480)
foodItems[j]=null;
}
}
}
public void blowup(Canvas canvas)
{
gamecow.sumlife();
blowupTimes=10;
blowupX=gamecow.getx();
blowupY=gamecow.gety();
}
private void drawlife(Canvas canvas)
{
canvas.drawText("X"+String.valueOf(gamecow.getlife()),65,445, paint);
}
private void drawPoint(Canvas canvas)
{
canvas.drawBitmap(bg, 0, 0, null);
canvas.drawText("分数"+String.valueOf(point),150,80, paint);
}
public boolean onTouchEvent(MotionEvent event)
{
x=(int)event.getX();
//y=(int)event.getY();
if(x<20)x=20;
if(x>260)x=260;
//this.draw(viewCanvas);
//invalidate();
//DisplayToast("触笔点击坐标:("+Integer.toString(x)+","+Integer.toString((int)event.getY())+")");
//return super.onTouchEvent(event);
return true;
}
public void DisplayToast(String str)
{
Toast.makeText(imgContext,str,Toast.LENGTH_SHORT).show();
}
public void addFoods()
{
int j;
int x;
int style;
int speed;
x=imgRandom(30,260);
style=imgRandom(0,1);
speed=imgRandom(1,10);
for (j=0;j<count;j++)
if (foodItems[j]==null)
{
foodItems[j]=new foodItem(imgContext,x,style,speed);
break;
}
}
public int imgRandom(int min,int max)
{
return (int)Math.round(Math.random()*(max-min)+min);
}
public void clearFoodItems()
{
int j;
for (j=0;j<count;j++)
if (foodItems[j]!=null) foodItems[j]=null;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
MyTestDemo.rar_Activity切换_activity_android_android activity
共53个文件
class:24个
png:9个
java:7个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 69 浏览量
2022-09-21
06:55:21
上传
评论
收藏 650KB RAR 举报
温馨提示
android编程 实现了layout的切换,activity之间数据的交换,以及一个利用自定义view实现的小游戏
资源推荐
资源详情
资源评论
收起资源包目录
MyTestDemo.rar (53个子文件)
MyTestDemo
bin
classes.dex 17KB
test.apk 210KB
resources.ap_ 199KB
deom
test
test$3$1.class 767B
test$1.class 685B
foodItem.class 2KB
imgViewAdapter.class 2KB
R$layout.class 392B
imgView.class 5KB
R$id.class 663B
R$drawable.class 679B
test$3.class 2KB
imgViewAdapter$overThread.class 1KB
test.class 3KB
R$attr.class 313B
test$4.class 781B
test$2.class 685B
R.class 505B
test_1.class 2KB
imgViewAdapter$1.class 2KB
cow.class 2KB
R$string.class 758B
imgViewAdapter$1$1.class 1KB
imgViewAdapter$drawThread.class 1KB
imgViewAdapter$addThread.class 1015B
R$anim.class 363B
test_1$1.class 718B
res
drawable
bg.png 107KB
blow_up.png 10KB
icon.png 3KB
bomb.png 8KB
Thumbs.db 6KB
cow_right.png 6KB
apple.png 4KB
mountains.png 21KB
cow_left.png 6KB
grassland.png 48KB
values
strings.xml 638B
color.xml 158B
anim
blowup.xml 267B
layout
m.xml 2KB
main.xml 1KB
assets
default.properties 449B
gen
deom
test
R.java 2KB
src
deom
test
test.java 4KB
imgView.java 4KB
imgViewAdapter.java 3KB
foodItem.java 2KB
cow.java 2KB
test_1.java 1KB
.project 846B
.classpath 280B
AndroidManifest.xml 719B
共 53 条
- 1
资源评论
weixin_42653672
- 粉丝: 93
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功