用自定义View的游戏界面,通过循环的方式 绘制每一个格子的图标
for (i = 0; i < 11; i++) { for (j = 0; j < 11; j++) { x = setx * j; y = setx * i; int id=MapData.map[Hero.currentfloor][i][j]; Bitmap bitmap=init(id); Bitmap bitmapgai=alterSizeBitmap(bitmap,setx,setx); canvas.drawBitmap(bitmapgai,x,y,paint); } }
碰到怪物时的战斗逻辑
private static void battle(int id, int x, int y) { Monster monster; int hp,atk,def; monster=MonsterData.monsterMap.get(id); hp=monster.getHp(); atk=monster.getAttack(); def=monster.getDefend(); while (true){ if (Heroatk<=def){ if (atk==Herodef){ break; } }else { hp=hp-(Heroatk-def); } if (hp<=0){ if (id==8){ System.exit(0); } MapData.map[currentfloor][y][x]=0; Hero.set(x,y); break; } if (atk<=Herodef){ }else { Herohp=Herohp-(atk-Herodef); } if (Herohp<=0){ AlertDialog.Builder builder=new AlertDialog.Builder(mcontext); builder.setTitle("你失败了"); builder.setMessage("凡人怎么能战胜魔王!"); builder.setPositiveButton("再来一次", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { System.exit(0); } }); AlertDialog alertDialog=builder.create(); alertDialog.show(); break; } } }
碰到物品时的逻辑
private static void add(int id, int x, int y) { Item item; int addhp,addatk,adddef; item=ItemData.itemMap.get(id); addhp=item.getHp(); addatk=item.getAttack(); adddef=item.getDefend(); Herohp=Herohp+addhp; Heroatk=Heroatk+addatk; Herodef=Herodef+adddef; MapData.map[currentfloor][y][x]=0; }