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;
}
}