2020-10-20

Unity3d 作业4(牧师与魔鬼动作分离版)

一、基本操作演练

下载 Fantasy Skybox FREE, 构建自己的游戏场景
首先上Assert Store下载Skybox,之后在unity中,把下载好的天空盒拖入摄像机中
最后成品如下:
成品图
在这里插入图片描述

二、编程实践

牧师与魔鬼 动作分离版

【2019新要求】:设计一个裁判类,当游戏达到结束条件时,通知场景控制器游戏结束
类图
在这里插入图片描述

我们新建的SSActionManager类需要将动作与游戏场景分离出来,其中包含的方法是characterIsClicked方法,这样能够将FirstController的功能减少:

//动作管理基类 – SSActionManager

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class SSActionManager : MonoBehaviour
{
    public Judge jd;
    public void icharacterIsClicked(CharacterModel characterCtrl,BoatModel boat,CoastModel to_Coast,CoastModel from_Coast, UserGUI userGUI)
    {
        if (characterCtrl.isOnBoat())
        {
            CoastModel whichCoast;
            if (boat.get_to_from() == -1)
            {
                whichCoast = to_Coast;
            }
            else
            {
                whichCoast = from_Coast;
            }

            boat.GetOffBoat(characterCtrl.getName());
            characterCtrl.moveToPosition(whichCoast.getEmptyPosition());
            characterCtrl.getOnCoast(whichCoast);
            whichCoast.getOnCoast(characterCtrl);

        }
        else
        {
            CoastModel whichCoast = characterCtrl.getCoastController();

            if (boat.getEmptyNum() == -1)
            {
                return;
            }

            if (whichCoast.get_to_or_from() != boat.get_to_from())
                return;

            whichCoast.getOffCoast(characterCtrl.getName());
            characterCtrl.moveToPosition(boat.getEmptyPosition());
            characterCtrl.getOnBoat(boat);
            boat.GetOnBoat(characterCtrl);
        }
        userGUI.status = jd.icheck_game_status(boat,to_Coast, from_Coast);
    }

}

新增的裁判类Judge判断游戏的状态:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Judge : MonoBehaviour
{
    public int icheck_game_status(BoatModel boat, CoastModel to_Coast, CoastModel from_Coast)
    {
        int from_priest = 0;
        int from_devil = 0;
        int to_priest = 0;
        int to_devil = 0;

        int[] fromCount = from_Coast.getCharacterNum();
        from_priest += fromCount[0];
        from_devil += fromCount[1];

        int[] toCount = to_Coast.getCharacterNum();
        to_priest += toCount[0];
        to_devil += toCount[1];

        //胜利
        if (to_priest + to_devil == 6)
            return 2;

        int[] boatCount = boat.getCharacterNum();

        if (boat.get_to_from() == -1)
        {
            to_priest += boatCount[0];
            to_devil += boatCount[1];
        }

        else
        {
            from_priest += boatCount[0];
            from_devil += boatCount[1];
        }

        if (from_priest < from_devil && from_priest > 0)
        {
            return 1;
        }
        if (to_priest < to_devil && to_priest > 0)
        {
            return 1;
        }

        return 0;
    }

}

代码:

源码

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值