unity3D-learnin:Priests and Devils

  • Read the game script below

Priests and Devils

Priests and Devils is a puzzle game in which you will help the Priests and Devils to cross the river within the time limit. There are 3 priests and 3 devils at one side of the river. They all want to get to the other side of this river, but there is only one boat and this boat can only carry two persons each time. And there must be one person steering the boat from one side to the other side. In the flash game, you can click on them to move them and click the go button to move the boat to the other direction. If the priests are out numbered by the devils on either side of the river, they get killed and the game is over. You can try it in many > ways. Keep all priests alive! Good luck!

Requirements the program needs to meet:

  • play the game ( http://www.flash-game.net/game/2535/priests-and-devils.html )
  • List the things mentioned in the game (Objects)
  • Use a table to list the player action table (rule table), note that the fewer actions the better
  • Please make in-game objects a prefab
  • Create rectangles, squares, balls and their colors in GenGameObjects to represent objects in the game.
  • Use C# Collection Types to Organize Objects Efficiently
  • The whole game is only the main camera and an Empty object,  other objects must be dynamically generated by code! ! !  . The entire game is not allowed to appear Find game objects, SendMessage and other communication coupling statements that break through the program structure. Violation of this rule, no points will be awarded
  • Please use the courseware architecture diagram for programming, non-MVC structure programs are not accepted
  • Pay attention to details, such as: the ship has not docked, the priest and the devil are in the movement of getting on and off the boat, and user events cannot be accepted!
  A: The objects mentioned in the game are : Priest , boat , devil , river , and River bank .
      Player action sheet:
        
Player action sheet
                   Action and implementation                                       condition                                             result          
Embark on the left bank (click the Embark button) There are people on the left bank, the boat is on the left bank, the crew is not full More people on board, fewer people on the left bank
Embark on the right bank ( click the Embark button ) There are people on the right bank, the boat is on the right bank, the crew is not full More people on board, fewer people on the right bank
sailing (click the sailing button) someone on board, Ship moves to the other side
Disembark on the left bank (click the disembark button) There are people on the boat, the boat is on the right bank More people on the left bank, fewer people on board
Right bank disembarkation (click the disembark button) There are people on the boat, the boat is on the left bank More people on the right bank, fewer people on board

  • Please make in-game objects a prefab

                

                                                            (The river and the boats on it)

                

                                                    (The green river bank and the priest sister and the dark devil standing on it)

  • Create rectangles, squares, balls and their colors in GenGameObjects to represent objects in the game.
         //set the two sides
        startside = GameObject.CreatePrimitive(PrimitiveType.Cube);
        homepage.transform.localScale = homepage scale;
        homepage.transform.position = homepage post;
        startside.GetComponent<Renderer>().material.color = Color.green;
        endside = GameObject.CreatePrimitive(PrimitiveType.Cube);
        endside.transform.localScale = endsidescale;
        endside.transform.position = endsidepos;
        endside.GetComponent<Renderer>().material.color = Color.green;
        //设置船只    
        Boat = GameObject.CreatePrimitive(PrimitiveType.Cube);
        Boat.transform.position = boatStartpos;
        Boat.transform.localScale = boatscale;
        Boat.GetComponent<Renderer>().material.color = Color.grey;
        //设置魔鬼与牧师
        for (int i = 0; i < 3; i++)
        {
            GameObject devil = GameObject.CreatePrimitive(PrimitiveType.Sphere);
            devil.GetComponent<Renderer>().material.color = Color.black;
            devil.transform.position = devilStartpos[i];
            devils.Add(devil);
            GameObject priest = GameObject.CreatePrimitive(PrimitiveType.Sphere);
            priest.transform.position = priestStartpos[i];
            priests.Add(priest);

        }
  • 整个游戏仅 主摄像机 和 一个 Empty 对象, 其他对象必须代码动态生成!!! 。 整个游戏不许出现 Find 游戏对象, SendMessage 这类突破程序结构的 通讯耦合 语句。 违背本条准则,不给分
  • 请使用课件架构图编程,不接受非 MVC 结构程序.

       完整代码在github给出,这里介绍部分代码。

       为了满足MVC结构,写了View.cs,Controller.cs,Models.cs  将两个脚本文件挂在摄像头上和一个挂在空对象上就实现了我们的程序,其中所有的对象都是动态生成,但是没有采用预制。

   void Update()
    {    //前提是船上有人
        if ( flag == true)
        {   //船在左岸开往右岸
            Boat.transform.position = Vector3.MoveTowards(Boat.transform.position, End, boatspeed);
            if (Boat.transform.position == End) flag = false;
        }
        else if (flag == false)
        {  //船在右岸开往左岸
            Boat.transform.position = Vector3.MoveTowards(Boat.transform.position, Start, boatspeed);
            if (Boat.transform.position == Start) falg = true;
        }
    }
    //判断游戏是否可以继续
    public void check()
    {
        //lose check
        print(devilStartside);
        print(devilEndside);
        print(priestStartside);
        print(priestEndside);
        if (state == 0)
        {
            if ((devilStartside > priestStartside && priestStartside != 0) || ((3 - devilStartside) > (3 - priestStartside) && (3 - priestStartside) != 0))
            {
                mygame.wl = WinOrLose.Lose;
                return;
            }
        }
        else if (state == 1)
        {
            if ((devilEndside > priestEndside && priestEndside != 0) || ((3 - devilEndside) > (3 - priestEndside) && (3 - priestEndside) != 0))
            {
                mygame.wl = WinOrLose.Lose;
                return;
            }
        }
        //win check
        if (devilStartside == 0 && priestStartside == 0) mygame.wl = WinOrLose.Win;

    }
 public interface ImyAction
    {
        void DevilGoOnBoat();
        void DevilGoOffBoat();
        void PriestGoOnBoat();
        void PriestGoOffBoat();
        void BoatGo();
        //魔鬼和牧师上下船还有行船五个操作,实现五个函数能够实现动作操作。
    }
完整代码在github上,游戏运行视频上传到百度云,链接在github上,代码参考师兄博客。思路和实现融入了自己的做法。




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325473873&siteId=291194637