初学者基于Android studio制作的简单版魔塔

 

 

用自定义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;
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值