這是一款基於安卓的打地鼠游戲,界面簡潔,有level模式打地鼠和無盡模式打地鼠兩種游戲模式,並可以通過商店使用金幣進行道具的購買,道具可以讓你更容易通關;同時金幣可以在游戲通關的時候獲取。工程中有較為詳細的註釋說明,可以供你參考學習。項目中使用了自定義動畫和資料庫操作。 部分實行代碼: /** * ...
這是一款基於安卓的打地鼠游戲,界面簡潔,有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);
}
}
};
功能非常強大,想學習的可以去源碼搜藏網下載完整程式源碼