"Unity3d" Devil and Priest game record--MVC architecture

Source: Internet
Author: User

Priests and devils is a puzzle-like mini-game that needs to help the priest and the devil to cross the river safely within the stipulated time. There were three devils and three priests, all wanting to cross the river, but there was only one boat on the river, and the ship had to carry only two, and a man had to drive the boat. If the number of devils on the river is more than the priest, the priest will be killed by the devil and the game is over. Game Links: http://www.flash-game.net/game/2535/priests-and-devils.html

Game finished drawing

Set 60s countdown--60s if you fail to safely ship all devils and priests, the game fails.

Try to improve the interface, not familiar with some things.

1 List the things mentioned in the game (Objects)

Object: Three Devils (expressed in White Cube), three priests (expressed in black sphere), a ship, two shore

2 Game Architecture:



ISceneController.cs and IUserAction.cs are interface classes, ISceneController.cs defines the scene control method, and FirstController.cs is the implementation of the specific scene control a scene, the implementation of the function is defined in the ISceneController.cs, and the scene manager does not know the implementation method, specifically implemented by the Director (Ssdir Ector) decided. Only the scene settings are visible, guaranteeing the security of the internal core code. IUserAction.cs defines the user interaction method, UserGUI.cs implements the corresponding method. MVC, reaching pattern, view, control separation.

For example:
1. Receive a user click event (UserGUI.cs)


2. Call the user interface function (function in IUserAction.cs)

3. Go to function implementation--go to Scene controller FirstController.cs

4. Request concrete method implementation--go to Director ssdirector.cs--control



2.3 Create rectangles, squares, balls and their colors in gengameobjects to represent objects in the game.
The game uses white squares to represent the devil, the black ball represents the priest, the cuboid represents the boat and the two sides.

2.4 Use the table to list the Player Action table (rule table), note that the less action the better

Table of action functions corresponding to the rule table:



Behavior can be broadly divided into three kinds, on board, sail and disembark. There are restrictions on sailing, and it is necessary to have a priest or a devil's ship in order to operate.

1. On board
There are two kinds of objects-the priest and the devil. This action can be a priest or devil as a sub-object of the ship, when there is a vacancy in the ship can be added to set the sub-object code. To distinguish between a devil or a priest, add the corresponding tag at a preset time. Priest for priest, devil for Devil

voidaboardtheboat (Gameobject obj) {if(_instance. Bcapacity ()! =0) {obj.transform.parent=_instance.boat_obj.transform; if(_instance.boat[0] ==NULL) {_instance.boat[0] =obj; Obj.transform.localPosition=NewVector3 (0,1.2f, -0.3f); } Else{_instance.boat[1] =obj; Obj.transform.localPosition=NewVector3 (0,1.2f,0.3f); }            }        }


2. Sailing
The ship must have a priest or a devil to move the boat from one shore to another.


3. Disembark
Do not divide the object, but the boat from the left boat to the right disembark, unbind the child object, and then move the corresponding object position.

 Public voidGetofftheboat (intside) {            if(_instance.boat[side]! =NULL) {_instance.boat[side].transform.parent=NULL; if(_instance.state = =state.bend) {if(_instance.boat[side].tag = ="Priest") {_instance.priestsend.push (boat[side]); }                    Else if(_instance.boat[side].tag = ="Devil") {_instance.devilsend.push (boat[side]); }                }                Else if(_instance.state = =State.bstart) {if(_instance.boat[side].tag = ="Priest") {_instance.priestsstart.push (boat[side]); }                    Else if(_instance.boat[side].tag = ="Devil") {_instance.devilsstart.push (boat[side]); }} _instance.boat[side]=NULL; }        }

About the code, mount the FirstContorller.cs to an empty object, and mount the UserGUI.cs to the main camera to run
2.5 Modify the code, use the C # collection type to organize the object effectively, and complete the game logic through Xxscenecontroller object gengameobjects interaction. (This requires a different one, now instead of the courseware framework.) If you need game object code, you can bind dynamically.

2.6 Precautions:
1. The entire game is only the main camera and an empty object, other objects must be dynamically generated code!!!

Dynamically generate objects using prefabrication. (No interface-modified objects are included)

2. The whole game is not allowed to Find game objects, SendMessage this kind of breakthrough program structure of the communication coupling statement. In contravention of this rule, no
3. Attention to details, such as: The ship is not docked, the priest and the devil in the boat movement, can not accept user events!

Approximate code logic reference Brother blog.

"Unity3d" Devil and Priest game record--MVC architecture

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.