这是一款基于安卓的打地鼠游戏,界面简洁,有level模式打地鼠和无尽模式打地鼠两种游戏模式,并可以通过商店使用金币进行道具的购买,道具可以让你更容易通关;同时金币可以在游戏通关的时候获取。工程中有较为详细的注释说明,可以供你参考学习。项目中使用了自定义动画和数据库操作。
部分实行代码:
/**
* 初始化购买弹出的界面
* */
private void initbuymian(){
buylinearlayout = (LinearLayout)this.findViewById(R.id.buylinearlayout);
buytitletv = (TextView)this.findViewById(R.id.buytitletv);
buycontenttv = (TextView)this.findViewById(R.id.buycontenttv);
buynumtv = (TextView)this.findViewById(R.id.buynumtv);
buygoldtv = (TextView)this.findViewById(R.id.buygoldtv);
yesbt = (ImageButton)this.findViewById(R.id.yesbt);
nobt = (ImageButton)this.findViewById(R.id.nobt);
yesbt.setOnClickListener(ocl);
nobt.setOnClickListener(ocl);
}
OnClickListener ocl = new OnClickListener(){
@Override
public void onClick(View v) {
if(v==yesbt){
buylinearlayout.setVisibility(View.GONE);
if(Def.goldnum>=typegold[downPosition]){
/**金币足够*/
cursor.moveToPosition(downPosition);
if(cursor.getInt(1)!=5){
shopdb.update(cursor.getInt(0), cursor.getInt(1), cursor.getInt(2)+1, "true");
initshopdb();
initShopinfo();
sa.notifyDataSetChanged();
}else{
saveLifeNum(Def.lifenum+1);
Def.lifenum = Def.lifenum+1;
sa.notifyDataSetChanged();
}
Def.goldnum = Def.goldnum - typegold[downPosition];
havegoldtv.setText(""+Def.goldnum);
saveGoldNum(Def.goldnum);
}else{
/**金币不够,用积分来替代*/
Toast.makeText(cxt, cxt.getResources().getString(R.string.coinnoenough), 2000).show();
/**算出还要多少积分替代金币*/
// final int count = typegold[downPosition] - Def.goldnum;
//调用queryPoints获取积分余额
// AppConnect.getInstance(cxt).spendPoints(count, new UpdatePointsNotifier() {
//
// @Override
// public void getUpdatePointsFailed(String paramString) {
//// Toast.makeText(MainActivity.this, "paramString:"+paramString, 2000).show();
// if(paramString.equals("您的账户已不足,无法消费")){
// new Handler(Looper.getMainLooper()).post(new Runnable(){
//
// @Override
// public void run() {
// Toast.makeText(cxt, "亲,需要"+count+"积分,您积分不够哦!请去更多游戏获取积分吧!", 2000).show();
// AppConnect.getInstance(cxt).showOffers(cxt);
// }
//
// });
// }else{
//
// if(cursor.getInt(1)!=5){
// shopdb.update(cursor.getInt(0), cursor.getInt(1), cursor.getInt(2)+1, "true");
// initshopdb();
// initShopinfo();
// sa.notifyDataSetChanged();
// }else{
// saveLifeNum(Def.lifenum+1);
// Def.lifenum = Def.lifenum+1;
// sa.notifyDataSetChanged();
// }
//
// Def.goldnum = 0;
// havegoldtv.setText(""+Def.goldnum);
// saveGoldNum(Def.goldnum);
//
// }
//
// }
//
// @Override
// public void getUpdatePoints(String paramString, int paramInt) {
// if(Def.defaultvalue.equals("true")){
// new Handler(Looper.getMainLooper()).post(new Runnable(){
//
// @Override
// public void run() {
// Toast.makeText(cxt, "正在使用积分代替", 2000).show();
//
// if(cursor.getInt(1)!=5){
// shopdb.update(cursor.getInt(0), cursor.getInt(1), cursor.getInt(2)+1, "true");
// initshopdb();
// initShopinfo();
// sa.notifyDataSetChanged();
// }else{
// saveLifeNum(Def.lifenum+1);
// Def.lifenum = Def.lifenum+1;
// sa.notifyDataSetChanged();
// }
//
// Def.goldnum = 0;
// havegoldtv.setText(""+Def.goldnum);
// saveGoldNum(Def.goldnum);
//
// }
//
// });
// }
// else{
//
// }
// }
// });
}
}
if(v==nobt){
buylinearlayout.setVisibility(View.GONE);
}
if(v==backbt){
finish();
}
}
};
OnItemClickListener oicl = new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
cursor.moveToPosition(position);
int type = cursor.getInt(1);
downPosition = position;
if(cursor.getInt(2)>=1&&cursor.getInt(1)!=5){
for(int i=0;i<cursor.getCount();i++){
cursor.moveToPosition(i);
if(cursor.getInt(1)==type){
shopdb.update(cursor.getInt(0), cursor.getInt(1), cursor.getInt(2), "true");
Def.wuqiType = cursor.getInt(1);
}else{
shopdb.update(cursor.getInt(0), cursor.getInt(1), cursor.getInt(2), "false");
}
}
// Toast.makeText(cxt, "替换成功", 2000).show();
initshopdb();
initShopinfo();
sa.notifyDataSetChanged();
}else{
bigAnimation(position);
}
}
};
功能非常强大,想学习的可以去源码搜藏网下载完整程序源码