3D游戏编程与设计_HW3

2023-10-25 04:50
文章标签 设计 编程 3d 游戏 hw3

本文主要是介绍3D游戏编程与设计_HW3,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1、简答并用程序验证【建议做】

  • 游戏对象运动的本质是什么?
    • 游戏对象运动的本质是对象随着每一帧的空间位置的变化,空间位置的变化有两个属性分别是 position 和 rotation,position 表示游戏对象的绝对坐标或者相对坐标,rotation 表示物体绕着某一旋转轴旋转的角度。这两个属性就能描述出游戏对象运动。

  • 请用三种方法以上方法,实现物体的抛物线运动。(如,修改Transform属性,使用向量Vector3的方法…)
    • 方法1:

    • using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;public class Move1: MonoBehaviour {public float speed = 1;// Use this for initializationvoid Start () {}// Update is called once per framevoid Update () {this.transform.position += Vector3.down*Time.deltaTime*(speed/10);this.transform.position += Vector3.right*Time.deltaTime*5;speed++;}}
      

      方法2:

    • using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;public class Move2 : MonoBehaviour {public float speed=1;// Use this for initializationvoid Start () {}// Update is called once per framevoid Update () {Vector3 change= new Vector3(Time.deltaTime*5,-Time.deltaTime*(speed/10),0);this.transform.position += change;}
      }
      

      方法3:

    • using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;public class Move2 : MonoBehaviour {public float speed=1;// Use this for initializationvoid Start () {}// Update is called once per framevoid Update () {Vector3 change= new Vector3(Time.deltaTime*5,-Time.deltaTime*(speed/10),0);transform.Translate(change);speed++;}
      }
      

       

  • 写一个程序,实现一个完整的太阳系, 其他星球围绕太阳的转速必须不一样,且不在一个法平面上。
    • 先做好预设,添加好每个行星

    • 之后,创建一个空对象,然后编写启动脚本,并将脚本挂载在空对象上。启动脚本代码如下:

    • using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;public class Controller : MonoBehaviour {void LoadResources(){GameObject sunset = Instantiate<GameObject>(Resources.Load<GameObject>("prefabs/sun"),Vector3.zero, Quaternion.identity);sunset.name = "sunset";Debug.Log("load sunset ...\n");}// Use this for initializationprivate void Awake(){LoadResources(); }
      }
      

      然后要做的就是编写每个行星的运动脚本,这里为了避免每次开始都要手动挂载对象对应到每个行星,所以采取,编写好脚本,挂载好每个对象之后再将其存为预设。运动脚本代码如下:

    • using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;public class RoundSun : MonoBehaviour {public Transform sun;public Transform moon;public Transform Mercury;public Transform Venus;public Transform earth;public Transform Mars;public Transform Jupite;public Transform Saturn;public Transform Neptune;public Transform Uranus;// Use this for initializationvoid LoadResources(){GameObject sunset = Instantiate<GameObject>(Resources.Load<GameObject>("prefabs/sun"),Vector3.zero, Quaternion.identity);sunset.name = "sunset";Debug.Log("load sunset ...\n");}void Start () {sun.position = Vector3.zero;earth.position = new Vector3 (-3, 0,-3 );moon.position = new Vector3 (-3, 0, -2);Mercury.position = new Vector3(0,0 ,3 );Venus.position = new Vector3(0, 3, -3);Mars.position = new Vector3(6, 3, 6);Jupite.position = new Vector3(-6, 2, -4);Saturn.position = new Vector3(8, 6, 3);Neptune.position = new Vector3(-9, -3, 12);Uranus.position = new Vector3(-12 -3, 9);rand();}Vector3 p, p1, p2, p3, p4, p5, p6, p7, p8, p9;void rand() {int a1 = Random.Range(0, 5) % 5;int b1 = Random.Range(0, 5) % 5;int c1 = Random.Range(0, 5) % 5;p1 = new Vector3(a1, b1, c1);// Update is called once per frameint a3 = Random.Range(0, 5) % 5;int b3 = Random.Range(0, 5) % 5;int c3 = Random.Range(0, 5) % 5;p3 = new Vector3(a3, b3, c3);int a4 = Random.Range(0, 5) % 5;int b4 = Random.Range(0, 5) % 5;int c4 = Random.Range(0, 5) % 5;p4 = new Vector3(a4, b4, c4);int a5 = Random.Range(0, 5) % 5;int b5 = Random.Range(0, 5) % 5;int c5 = Random.Range(0, 5) % 5;p5 = new Vector3(a5, b5, c5);int a6 = Random.Range(0, 5) % 5;int b6 = Random.Range(0, 5) % 5;int c6 = Random.Range(0, 5) % 5;p6 = new Vector3(a6, b6, c6);int a7 = Random.Range(0, 5) % 5;int b7 = Random.Range(0, 5) % 5;int c7 = Random.Range(0, 5) % 5;p7 = new Vector3(a7, b7, c7);int a8 = Random.Range(0, 5) % 5;int b8 = Random.Range(0, 5) % 5;int c8 = Random.Range(0, 5) % 5;p8 = new Vector3(a8, b8, c8);int a9 = Random.Range(0, 5) % 5;int b9 = Random.Range(0, 5) % 5;int c9 = Random.Range(0, 5) % 5;p9 = new Vector3(a9, b9, c9); }void Update () {earth.RotateAround(sun.position, p1, 10 * Time.deltaTime);earth.Rotate (Vector3.up * 30 * Time.deltaTime);moon.transform.RotateAround(earth.position, Vector3.up, 359 * Time.deltaTime);Mercury.RotateAround(sun.position, p3, 20 * Time.deltaTime);Venus.RotateAround(sun.position, p4, 15 * Time.deltaTime);Mars.RotateAround(sun.position, p5, 25 * Time.deltaTime);Jupite.RotateAround(sun.position, p6, 18 * Time.deltaTime);Saturn.RotateAround(sun.position, p7, 12 * Time.deltaTime);Neptune.RotateAround(sun.position, p8, 40 * Time.deltaTime);Uranus.RotateAround(sun.position, p9, 30 * Time.deltaTime);}
      }
      

      在上述代码中,每个行星的旋转轴都是随机确定的。

  • 2、编程实践

  • 阅读以下游戏脚本
  • play the game ( http://www.flash-game.net/game/2535/priests-and-devils.html )
  • 列出游戏中提及的事物(Objects)
  • 用表格列出玩家动作表(规则表),注意,动作越少越好
  • 请将游戏中对象做成预制
  • 在 GenGameObjects 中创建 长方形、正方形、球 及其色彩代表游戏中的对象。
  • 使用 C# 集合类型 有效组织对象
  • 整个游戏仅 主摄像机 和 一个 Empty 对象, 其他对象必须代码动态生成!!! 。 整个游戏不许出现 Find 游戏对象, SendMessage 这类突破程序结构的 通讯耦合 语句。 违背本条准则,不给分
  • 请使用课件架构图编程,不接受非 MVC 结构程序
  • 注意细节,例如:船未靠岸,牧师与魔鬼上下船运动中,均不能接受用户事件!
  • 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!

    程序需要满足的要求:

  • play the game ( http://www.flash-game.net/game/2535/priests-and-devils.html )
  • 列出游戏中提及的事物(Objects)
    • 两个岸边

    • 3个牧师

    • 3个魔鬼

  • 用表格列出玩家动作表(规则表),注意,动作越少越好
    • 动作规则
      船过河船上有人,从所在岸移动带另一岸
      开始岸牧师上船船上有空位,船在开始岸
      开始岸魔鬼上船船上有空位,船在开始岸
      结束岸牧师上船船上有空位,船在结束岸
      结束岸魔鬼上船船上有空位,船在结束岸
      船空位1下船船空位1有人
      船空位2下船船空位2有人

       

  • 请将游戏中对象做成预制
  • 在 GenGameObjects 中创建 长方形、正方形、球 及其色彩代表游戏中的对象。
  • 使用 C# 集合类型 有效组织对象
  • 整个游戏仅 主摄像机 和 一个 Empty 对象, 其他对象必须代码动态生成!!! 。 整个游戏不许出现 Find 游戏对象, SendMessage 这类突破程序结构的 通讯耦合 语句。 违背本条准则,不给分
  • 请使用课件架构图编程,不接受非 MVC 结构程序
  • 注意细节,例如:船未靠岸,牧师与魔鬼上下船运动中,均不能接受用户事件!
    • 先编写导演类,负责联系场景的切换

      using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;public class SSDirector : System.Object {// singlton instanceprivate static SSDirector _instance;public ISceneController currentSceneController { get; set;}// https://blog.csdn.net/qiaoquan3/article/details/51339242public bool Paused { get { return Time.timeScale == 0; } set {Time.timeScale = value?0:1;} } // get instance anytime anywhare!public static SSDirector getInstance() {if (_instance == null) {_instance = new SSDirector ();}return _instance;}public int getFPS() {return Application.targetFrameRate;}public void setFPS(int fps) {Application.targetFrameRate = fps;}public void NextScene(){Debug.Log ("Waiting next Scene now...");#if UNITY_EDITOR  UnityEditor.EditorApplication.isPlaying = false;//UnityEditor.EditorApplication.Exit(0);#else  Application.Quit();  #endif  }
      }

      之后写出场景控制的接口,和用户行为的接口方便调用

    • using System;/// <summary>
      /// Abstact Scene Controller. Interface between scene controllers and the director
      /// </summary>
      public interface ISceneController
      {void LoadResources();
      }
      
      using System;public interface IUserAction
      {void GameOver();
      }
      

      之后开始编写第一个场景控制FirstScenceController

    • 首先要让导演类指示该场景应该实现了,所以代码如下:

    •   void Awake(){SSDirector director = SSDirector.getInstance();director.setFPS(60);director.currentSceneController = this;director.currentSceneController.LoadResources();}

      之后场景类负责该场景内所有对象的加载和交互,首先先实现资源的加载:

    • public void LoadResources(){Boat = Instantiate<GameObject>(Resources.Load<GameObject>("prefabs/Boat"),new Vector3((float)0, (float)-1, (float)0), Quaternion.identity);Boat.name = "Boat";Devils1 = Instantiate<GameObject>(Resources.Load<GameObject>("prefabs/Devils1"),new Vector3((float)-0.3, (float)-0.5, (float)3.5), Quaternion.identity);Devils1.name = "Devils1";Devils2 = Instantiate<GameObject>(Resources.Load<GameObject>("prefabs/Devils2"),new Vector3((float)-0.3, (float)-0.5, (float)4), Quaternion.identity);Devils2.name = "Devils2";Devils3 = Instantiate<GameObject>(Resources.Load<GameObject>("prefabs/Devils3"),new Vector3((float)-0.3, (float)-0.5, (float)4.5), Quaternion.identity);Devils3.name = "Devils3";Priests1 = Instantiate<GameObject>(Resources.Load<GameObject>("prefabs/Priests1"),new Vector3((float)-0.3, (float)-0.5, (float)2), Quaternion.identity);Priests1.name = "Priests1";Priests2 = Instantiate<GameObject>(Resources.Load<GameObject>("prefabs/Priests2"),new Vector3((float)-0.3, (float)-0.5, (float)2.5), Quaternion.identity);Priests2.name = "Priests2";Priests3 = Instantiate<GameObject>(Resources.Load<GameObject>("prefabs/Priests3"),new Vector3((float)-0.3, (float)-0.5, (float)3), Quaternion.identity);Priests3.name = "Priests3";Left = Instantiate<GameObject>(Resources.Load<GameObject>("prefabs/Left"),new Vector3((float)-0.3, (float)-0.7, (float)3.5), Quaternion.identity);Left.name = "Left";Right = Instantiate<GameObject>(Resources.Load<GameObject>("prefabs/Right"),new Vector3((float)-0.3, (float)-0.7, (float)-6), Quaternion.identity);Right.name = "Right";}

      加载好资源后,就要实现资源的行为,这里定义为,每点击一下按钮就从一个位置移动到另一个位置,所以定义好按钮和位置变化。

    • int Boatchair = 0;//0代表船上没人,1代表船上右边有人 ,2代表船上左边有人,3代表船上满人int BoatFlag = 1;//上述变量: // 1代表船上没人,且在左岸// 2代表船上没人,且在右岸// 3代表船上有人,且在左岸,左// 4代表船上有人,且在右岸double Priests1flag = 1;double Priests2flag = 1;double Priests3flag = 1;double Devils1flag = 1;double Devils2flag = 1;double Devils3flag = 1;void OnGUI(){if (state == 0){//give advice firsbool DriveFlag = GUI.Button(new Rect(350, 350, 100, 50), "Drive");if (DriveFlag == true && BoatFlag == 1 && Boatchair != 0){Boat.transform.position = new Vector3(0, -1, -3);BoatFlag = 2;if (Math.Abs(Priests1flag - 2.1) < 1E-6 || Math.Abs(Priests1flag - 2.2) < 1E-6){Priests1.transform.position = new Vector3((float)0, (float)-0.8, (float)-3);Priests1flag = 3.1;}if (Math.Abs(Priests1flag - 2.3) < 1E-6 || Math.Abs(Priests1flag - 2.4) < 1E-6){Priests1.transform.position = new Vector3((float)0, (float)-0.8, (float)-2);Priests1flag = 3.3;}if (Math.Abs(Priests2flag - 2.1) < 1E-6 || Math.Abs(Priests2flag - 2.2) < 1E-6){Priests2.transform.position = new Vector3((float)0, (float)-0.8, (float)-3);Priests2flag = 3.1;}if (Math.Abs(Priests2flag - 2.3) < 1E-6 || Math.Abs(Priests2flag - 2.4) < 1E-6){Priests2.transform.position = new Vector3((float)0, (float)-0.8, (float)-2);Priests2flag = 3.3;}if (Math.Abs(Priests3flag - 2.1) < 1E-6 || Math.Abs(Priests3flag - 2.2) < 1E-6){Priests3.transform.position = new Vector3((float)0, (float)-0.8, (float)-3);Priests3flag = 3.1;}if (Math.Abs(Priests3flag - 2.3) < 1E-6 || Math.Abs(Priests3flag - 2.4) < 1E-6){Priests3.transform.position = new Vector3((float)0, (float)-0.8, (float)-2);Priests3flag = 3.3;}if (Math.Abs(Devils1flag - 2.1) < 1E-6 || Math.Abs(Devils1flag - 2.2) < 1E-6){Devils1.transform.position = new Vector3((float)0, (float)-0.8, (float)-3);Devils1flag = 3.1;}if (Math.Abs(Devils1flag - 2.3) < 1E-6 || Math.Abs(Devils1flag - 2.4) < 1E-6){Devils1.transform.position = new Vector3((float)0, (float)-0.8, (float)-2);Devils1flag = 3.3;}if (Math.Abs(Devils2flag - 2.1) < 1E-6 || Math.Abs(Devils2flag - 2.2) < 1E-6){Devils2.transform.position = new Vector3((float)0, (float)-0.8, (float)-3);Devils2flag = 3.1;}if (Math.Abs(Devils2flag - 2.3) < 1E-6 || Math.Abs(Devils2flag - 2.4) < 1E-6){Devils2.transform.position = new Vector3((float)0, (float)-0.8, (float)-2);Devils2flag = 3.3;}if (Math.Abs(Devils3flag - 2.1) < 1E-6 || Math.Abs(Devils3flag - 2.2) < 1E-6){Devils3.transform.position = new Vector3((float)0, (float)-0.8, (float)-3);Devils3flag = 3.1;}if (Math.Abs(Devils3flag - 2.3) < 1E-6 || Math.Abs(Devils3flag - 2.4) < 1E-6){Devils3.transform.position = new Vector3((float)0, (float)-0.8, (float)-2);Devils3flag = 3.3;}checkGame();}else if (DriveFlag == true && BoatFlag == 2){Boat.transform.position = new Vector3(0, -1, 0);BoatFlag = 1;if (Math.Abs(Priests1flag - 3.2) < 1E-6 || Math.Abs(Priests1flag - 3.1) < 1E-6){Priests1.transform.position = new Vector3((float)0, (float)-0.8, (float)0);Priests1flag = 2.2;}if (Math.Abs(Priests1flag - 3.3) < 1E-6 || Math.Abs(Priests1flag - 3.4) < 1E-6){Priests1.transform.position = new Vector3((float)0, (float)-0.8, (float)1);Priests1flag = 2.4;}if (Math.Abs(Priests2flag - 3.2) < 1E-6 || Math.Abs(Priests2flag - 3.1) < 1E-6){Priests2.transform.position = new Vector3((float)0, (float)-0.8, (float)0);Priests2flag = 2.2;}if (Math.Abs(Priests2flag - 3.3) < 1E-6 || Math.Abs(Priests2flag - 3.4) < 1E-6){Priests2.transform.position = new Vector3((float)0, (float)-0.8, (float)1);Priests2flag = 2.4;}if (Math.Abs(Priests3flag - 3.2) < 1E-6 || Math.Abs(Priests3flag - 3.1) < 1E-6){Priests2.transform.position = new Vector3((float)0, (float)-0.8, (float)0);Priests2flag = 2.2;}if (Math.Abs(Priests3flag - 3.3) < 1E-6 || Math.Abs(Priests3flag - 3.4) < 1E-6){Priests3.transform.position = new Vector3((float)0, (float)-0.8, (float)1);Priests3flag = 2.4;}if (Math.Abs(Devils1flag - 3.2) < 1E-6 || Math.Abs(Devils1flag - 3.1) < 1E-6){Devils1.transform.position = new Vector3((float)0, (float)-0.8, (float)0);Devils1flag = 2.2;}if (Math.Abs(Devils1flag - 3.3) < 1E-6 || Math.Abs(Devils1flag - 3.4) < 1E-6){Devils1.transform.position = new Vector3((float)0, (float)-0.8, (float)1);Devils1flag = 2.4;}if (Math.Abs(Devils2flag - 3.2) < 1E-6 || Math.Abs(Devils2flag - 3.1) < 1E-6){Devils2.transform.position = new Vector3((float)0, (float)-0.8, (float)0);Devils2flag = 2.2;}if (Math.Abs(Devils2flag - 3.3) < 1E-6 || Math.Abs(Devils2flag - 3.4) < 1E-6){Devils2.transform.position = new Vector3((float)0, (float)-0.8, (float)1);Devils2flag = 2.4;}if (Math.Abs(Devils3flag - 3.2) < 1E-6 || Math.Abs(Devils3flag - 3.1) < 1E-6){Devils3.transform.position = new Vector3((float)0, (float)-0.8, (float)0);Devils3flag = 2.2;}if (Math.Abs(Devils3flag - 3.3) < 1E-6 || Math.Abs(Devils3flag - 3.4) < 1E-6){Devils3.transform.position = new Vector3((float)0, (float)-0.8, (float)1);Devils3flag = 2.4;}checkGame();}bool P1flag = GUI.Button(new Rect(260, 250, 30, 30), "P1");bool P2flag = GUI.Button(new Rect(225, 250, 30, 30), "P2");bool P3flag = GUI.Button(new Rect(190, 250, 30, 30), "P3");bool D1flag = GUI.Button(new Rect(155, 250, 30, 30), "D1");bool D2flag = GUI.Button(new Rect(120, 250, 30, 30), "D2");bool D3flag = GUI.Button(new Rect(85, 250, 30, 30), "D3");if (P1flag == true){if (Math.Abs(Priests1flag - 1) < 1E-6 && BoatFlag == 1 && Boatchair == 0){Debug.Log(Boatchair);Priests1.transform.position = new Vector3((float)0, (float)-0.8, (float)0);Priests1flag = 2.1;Boatchair = 1;checkleft[1] = 0;}if (Math.Abs(Priests1flag - 1) < 1E-6 && BoatFlag == 1 && Boatchair == 2){Debug.Log(Boatchair);Priests1.transform.position = new Vector3((float)0, (float)-0.8, (float)0);Priests1flag = 2.1;Boatchair = 3;checkleft[1] = 0;}if (Math.Abs(Priests1flag - 1) < 1E-6 && BoatFlag == 1 && Boatchair == 1){Debug.Log(Boatchair);Priests1.transform.position = new Vector3((float)0, (float)-0.8, (float)1);Priests1flag = 2.3;Boatchair = 3;checkleft[1] = 0;}if (Math.Abs(Priests1flag - 4) < 1E-6 && BoatFlag == 2 && Boatchair == 0){Priests1.transform.position = new Vector3((float)0, (float)-0.8, (float)-3);Priests1flag = 3.2;Boatchair = 1;checkright[1] = 0;}if (Math.Abs(Priests1flag - 4) < 1E-6 && BoatFlag == 2 && Boatchair == 1){Priests1.transform.position = new Vector3((float)0, (float)-0.8, (float)-2);Priests1flag = 3.4;Boatchair = 3;checkright[1] = 0;}if (Math.Abs(Priests1flag - 4) < 1E-6 && BoatFlag == 2 && Boatchair == 2){Priests1.transform.position = new Vector3((float)0, (float)-0.8, (float)-3);Priests1flag = 3.2;Boatchair = 3;checkright[1] = 0;}if (Math.Abs(Priests1flag - 2.2) < 1E-6){Priests1.transform.position = new Vector3((float)-0.3, (float)-0.5, (float)2);Priests1flag = 1;if (Boatchair == 3)Boatchair = 2;if (Boatchair == 1)Boatchair = 0;checkleft[1] = 1;}if (Math.Abs(Priests1flag - 2.4) < 1E-6){Priests1.transform.position = new Vector3((float)-0.3, (float)-0.5, (float)2);Priests1flag = 1;if (Boatchair == 3)Boatchair = 1;if (Boatchair == 2)Boatchair = 0;checkleft[1] = 1;}if (Math.Abs(Priests1flag - 3.1) < 1E-6){Priests1.transform.position = new Vector3((float)-0.3, (float)-0.5, (float)-4.5);Priests1flag = 4;if (Boatchair == 3)Boatchair = 2;if (Boatchair == 1)Boatchair = 0;checkright[1] = 1;}if (Math.Abs(Priests1flag - 3.3) < 1E-6){Priests1.transform.position = new Vector3((float)-0.3, (float)-0.5, (float)-4.5);Priests1flag = 4;if (Boatchair == 3)Boatchair = 1;if (Boatchair == 2)Boatchair = 0;checkright[1] = 1;}}if (P2flag == true){if (Math.Abs(Priests2flag - 1) < 1E-6 && BoatFlag == 1 && (Boatchair == 0)){Priests2.transform.position = new Vector3((float)0, (float)-0.8, (float)0);Priests2flag = 2.1;if (Boatchair == 0)Boatchair = 1;checkleft[2] = 0;}if (Math.Abs(Priests2flag - 1) < 1E-6 && BoatFlag == 1 && (Boatchair == 2)){Priests2.transform.position = new Vector3((float)0, (float)-0.8, (float)0);Priests2flag = 2.1;if (Boatchair == 2)Boatchair = 3;checkleft[2] = 0;}if (Math.Abs(Priests2flag - 1) < 1E-6 && BoatFlag == 1 && Boatchair == 1){Priests2.transform.position = new Vector3((float)0, (float)-0.8, (float)1);Priests2flag = 2.3;Boatchair = 3;checkleft[2] = 0;}if (Math.Abs(Priests2flag - 4) < 1E-6 && BoatFlag == 2 && Boatchair == 0){Priests2.transform.position = new Vector3((float)0, (float)-0.8, (float)-3);Priests2flag = 3.2;Boatchair = 1;checkright[2] = 0;}if (Math.Abs(Priests2flag - 4) < 1E-6 && BoatFlag == 2 && Boatchair == 1){Priests2.transform.position = new Vector3((float)0, (float)-0.8, (float)-2);Priests2flag = 3.4;Boatchair = 3;checkright[2] = 0;}if (Math.Abs(Priests2flag - 4) < 1E-6 && BoatFlag == 2 && Boatchair == 2){Priests2.transform.position = new Vector3((float)0, (float)-0.8, (float)-3);Priests2flag = 3.2;Boatchair = 3;checkright[2] = 0;}if (Math.Abs(Priests2flag - 2.2) < 1E-6){Priests2.transform.position = new Vector3((float)-0.3, (float)-0.5, (float)2.5);//Priests2flag = 1;if (Boatchair == 3)Boatchair = 2;if (Boatchair == 1)Boatchair = 0;checkleft[2] = 1;}if (Math.Abs(Priests2flag - 2.4) < 1E-6){Priests2.transform.position = new Vector3((float)-0.3, (float)-0.5, (float)2.5);//Priests2flag = 1;if (Boatchair == 3)Boatchair = 1;if (Boatchair == 2)Boatchair = 0;checkleft[2] = 1;}if (Math.Abs(Priests2flag - 3.1) < 1E-6){Priests2.transform.position = new Vector3((float)-0.3, (float)-0.5, (float)-5.0);//Priests2flag = 4;if (Boatchair == 3)Boatchair = 2;if (Boatchair == 1)Boatchair = 0;checkright[2] = 1;}if (Math.Abs(Priests2flag - 3.3) < 1E-6){Priests2.transform.position = new Vector3((float)-0.3, (float)-0.5, (float)-5.0);//Priests2flag = 4;if (Boatchair == 3)Boatchair = 1;if (Boatchair == 2)Boatchair = 0;checkright[2] = 1;}}if (P3flag == true){if (Math.Abs(Priests3flag - 1) < 1E-6 && BoatFlag == 1 && (Boatchair == 0)){Priests3.transform.position = new Vector3((float)0, (float)-0.8, (float)0);Priests3flag = 2.1;if (Boatchair == 0)Boatchair = 1;checkleft[3] = 0;}if (Math.Abs(Priests3flag - 1) < 1E-6 && BoatFlag == 1 && (Boatchair == 2)){Priests3.transform.position = new Vector3((float)0, (float)-0.8, (float)0);Priests3flag = 2.1;if (Boatchair == 2)Boatchair = 3;checkleft[3] = 0;}if (Math.Abs(Priests3flag - 1) < 1E-6 && BoatFlag == 1 && Boatchair == 1){Priests3.transform.position = new Vector3((float)0, (float)-0.8, (float)1);Priests3flag = 2.3;Boatchair = 3;checkleft[3] = 0;}if (Math.Abs(Priests3flag - 4) < 1E-6 && BoatFlag == 2 && Boatchair == 0){Priests3.transform.position = new Vector3((float)0, (float)-0.8, (float)-3);Priests3flag = 3.2;Boatchair = 1;checkright[3] = 0;}if (Math.Abs(Priests3flag - 4) < 1E-6 && BoatFlag == 2 && Boatchair == 1){Priests3.transform.position = new Vector3((float)0, (float)-0.8, (float)-2);Priests3flag = 3.4;Boatchair = 3;checkright[3] = 0;}if (Math.Abs(Priests3flag - 4) < 1E-6 && BoatFlag == 2 && Boatchair == 2){Priests3.transform.position = new Vector3((float)0, (float)-0.8, (float)-3);Priests3flag = 3.2;Boatchair = 3;checkright[3] = 0;}if (Math.Abs(Priests3flag - 2.2) < 1E-6){Priests3.transform.position = new Vector3((float)-0.3, (float)-0.5, (float)3);//+0.5Priests3flag = 1;if (Boatchair == 3)Boatchair = 2;if (Boatchair == 1)Boatchair = 0;checkleft[3] = 1;}if (Math.Abs(Priests3flag - 2.4) < 1E-6){Priests3.transform.position = new Vector3((float)-0.3, (float)-0.5, (float)3);//+0.5Priests3flag = 1;if (Boatchair == 3)Boatchair = 1;if (Boatchair == 2)Boatchair = 0;checkleft[3] = 1;}if (Math.Abs(Priests3flag - 3.1) < 1E-6){Priests3.transform.position = new Vector3((float)-0.3, (float)-0.5, (float)-5.5);//-0.5Priests3flag = 4;if (Boatchair == 3)Boatchair = 2;if (Boatchair == 1)Boatchair = 0;checkright[3] = 1;}if (Math.Abs(Priests3flag - 3.3) < 1E-6){Priests3.transform.position = new Vector3((float)-0.3, (float)-0.5, (float)-5.5);//-0.5Priests3flag = 4;if (Boatchair == 3)Boatchair = 1;if (Boatchair == 2)Boatchair = 0;checkright[3] = 1;}}if (D1flag == true){if (Math.Abs(Devils1flag - 1) < 1E-6 && BoatFlag == 1 && (Boatchair == 0)){Devils1.transform.position = new Vector3((float)0, (float)-0.8, (float)0);Devils1flag = 2.1;if (Boatchair == 0)Boatchair = 1;checkleft[4] = 0;}if (Math.Abs(Devils1flag - 1) < 1E-6 && BoatFlag == 1 && (Boatchair == 2)){Devils1.transform.position = new Vector3((float)0, (float)-0.8, (float)0);Devils1flag = 2.1;if (Boatchair == 2)Boatchair = 3;checkleft[4] = 0;}if (Math.Abs(Devils1flag - 1) < 1E-6 && BoatFlag == 1 && Boatchair == 1){Devils1.transform.position = new Vector3((float)0, (float)-0.8, (float)1);Devils1flag = 2.3;Boatchair = 3;checkleft[4] = 0;}if (Math.Abs(Devils1flag - 4) < 1E-6 && BoatFlag == 2 && Boatchair == 0){Devils1.transform.position = new Vector3((float)0, (float)-0.8, (float)-3);Devils1flag = 3.2;Boatchair = 1;checkright[4] = 0;}if (Math.Abs(Devils1flag - 4) < 1E-6 && BoatFlag == 2 && Boatchair == 1){Devils1.transform.position = new Vector3((float)0, (float)-0.8, (float)-2);Devils1flag = 3.4;Boatchair = 3;checkright[4] = 0;}if (Math.Abs(Devils1flag - 4) < 1E-6 && BoatFlag == 2 && Boatchair == 2){Devils1.transform.position = new Vector3((float)0, (float)-0.8, (float)-3);Devils1flag = 3.2;Boatchair = 3;checkright[4] = 0;}if (Math.Abs(Devils1flag - 2.2) < 1E-6){Devils1.transform.position = new Vector3((float)-0.3, (float)-0.5, (float)3.5);//+0.5Devils1flag = 1;if (Boatchair == 3)Boatchair = 2;if (Boatchair == 1)Boatchair = 0;checkleft[4] = 2;}if (Math.Abs(Devils1flag - 2.4) < 1E-6){Devils1.transform.position = new Vector3((float)-0.3, (float)-0.5, (float)3.5);//+0.5Devils1flag = 1;if (Boatchair == 3)Boatchair = 1;if (Boatchair == 2)Boatchair = 0;checkleft[4] = 2;}if (Math.Abs(Devils1flag - 3.1) < 1E-6){Devils1.transform.position = new Vector3((float)-0.3, (float)-0.5, (float)-6.0);//-0.5Devils1flag = 4;if (Boatchair == 3)Boatchair = 2;if (Boatchair == 1)Boatchair = 0;checkright[4] = 2;}if (Math.Abs(Devils1flag - 3.3) < 1E-6){Devils1.transform.position = new Vector3((float)-0.3, (float)-0.5, (float)-6.0);//-0.5Devils1flag = 4;if (Boatchair == 3)Boatchair = 1;if (Boatchair == 2)Boatchair = 0;checkright[4] = 2;}}if (D2flag == true){if (Math.Abs(Devils2flag - 1) < 1E-6 && BoatFlag == 1 && (Boatchair == 0)){Devils2.transform.position = new Vector3((float)0, (float)-0.8, (float)0);Devils2flag = 2.1;if (Boatchair == 0)Boatchair = 1;checkleft[5] = 0;}if (Math.Abs(Devils2flag - 1) < 1E-6 && BoatFlag == 1 && (Boatchair == 2)){Devils2.transform.position = new Vector3((float)0, (float)-0.8, (float)0);Devils2flag = 2.1;if (Boatchair == 2)Boatchair = 3;checkleft[5] = 0;}if (Math.Abs(Devils2flag - 1) < 1E-6 && BoatFlag == 1 && Boatchair == 1){Devils2.transform.position = new Vector3((float)0, (float)-0.8, (float)1);Devils2flag = 2.3;Boatchair = 3;checkleft[5] = 0;}if (Math.Abs(Devils2flag - 4) < 1E-6 && BoatFlag == 2 && Boatchair == 0){Devils2.transform.position = new Vector3((float)0, (float)-0.8, (float)-3);Devils2flag = 3.2;Boatchair = 1;checkright[5] = 0;}if (Math.Abs(Devils2flag - 4) < 1E-6 && BoatFlag == 2 && Boatchair == 1){Devils2.transform.position = new Vector3((float)0, (float)-0.8, (float)-2);Devils2flag = 3.4;Boatchair = 3;checkright[5] = 0;}if (Math.Abs(Devils2flag - 4) < 1E-6 && BoatFlag == 2 && Boatchair == 2){Devils2.transform.position = new Vector3((float)0, (float)-0.8, (float)-3);Devils2flag = 3.2;Boatchair = 3;checkright[5] = 0;}if (Math.Abs(Devils2flag - 2.2) < 1E-6){Devils2.transform.position = new Vector3((float)-0.3, (float)-0.5, (float)4);//+0.5Devils2flag = 1;if (Boatchair == 3)Boatchair = 2;if (Boatchair == 1)Boatchair = 0;checkleft[5] = 2;}if (Math.Abs(Devils2flag - 2.4) < 1E-6){Devils2.transform.position = new Vector3((float)-0.3, (float)-0.5, (float)4);//+0.5Devils2flag = 1;if (Boatchair == 3)Boatchair = 1;if (Boatchair == 2)Boatchair = 0;checkleft[5] = 2;}if (Math.Abs(Devils2flag - 3.1) < 1E-6){Devils2.transform.position = new Vector3((float)-0.3, (float)-0.5, (float)-6.5);//-0.5Devils2flag = 4;if (Boatchair == 3)Boatchair = 2;if (Boatchair == 1)Boatchair = 0;checkright[5] = 2;}if (Math.Abs(Devils2flag - 3.3) < 1E-6){Devils2.transform.position = new Vector3((float)-0.3, (float)-0.5, (float)-6.5);//-0.5Devils2flag = 4;if (Boatchair == 3)Boatchair = 1;if (Boatchair == 2)Boatchair = 0;checkleft[5] = 2;}}if (D3flag == true){if (Math.Abs(Devils3flag - 1) < 1E-6 && BoatFlag == 1 && (Boatchair == 0)){Devils3.transform.position = new Vector3((float)0, (float)-0.8, (float)0);Devils3flag = 2.1;if (Boatchair == 0)Boatchair = 1;checkleft[6] = 0;}if (Math.Abs(Devils3flag - 1) < 1E-6 && BoatFlag == 1 && (Boatchair == 2)){Devils3.transform.position = new Vector3((float)0, (float)-0.8, (float)0);Devils3flag = 2.1;if (Boatchair == 2)Boatchair = 3;checkleft[6] = 0;}if (Math.Abs(Devils3flag - 1) < 1E-6 && BoatFlag == 1 && Boatchair == 1){Devils3.transform.position = new Vector3((float)0, (float)-0.8, (float)1);Devils3flag = 2.3;Boatchair = 3;checkleft[6] = 0;}if (Math.Abs(Devils3flag - 4) < 1E-6 && BoatFlag == 2 && Boatchair == 0){Devils3.transform.position = new Vector3((float)0, (float)-0.8, (float)-3);Devils3flag = 3.2;Boatchair = 1;checkright[6] = 0;}if (Math.Abs(Devils3flag - 4) < 1E-6 && BoatFlag == 2 && Boatchair == 1){Devils3.transform.position = new Vector3((float)0, (float)-0.8, (float)-2);Devils3flag = 3.4;Boatchair = 3;checkright[6] = 0;}if (Math.Abs(Devils3flag - 4) < 1E-6 && BoatFlag == 2 && Boatchair == 2){Devils3.transform.position = new Vector3((float)0, (float)-0.8, (float)-3);Devils3flag = 3.2;Boatchair = 3;checkright[6] = 0;}if (Math.Abs(Devils3flag - 2.2) < 1E-6){Devils3.transform.position = new Vector3((float)-0.3, (float)-0.5, (float)4.5);//+0.5Devils3flag = 1;if (Boatchair == 3)Boatchair = 2;if (Boatchair == 1)Boatchair = 0;checkleft[6] = 2;}if (Math.Abs(Devils3flag - 2.4) < 1E-6){Devils3.transform.position = new Vector3((float)-0.3, (float)-0.5, (float)4.5);//+0.5Devils3flag = 1;if (Boatchair == 3)Boatchair = 1;if (Boatchair == 2)Boatchair = 0;checkright[6] = 0;}if (Math.Abs(Devils3flag - 3.1) < 1E-6){Devils3.transform.position = new Vector3((float)-0.3, (float)-0.5, (float)-7.0);//-0.5Devils3flag = 4;if (Boatchair == 3)Boatchair = 2;if (Boatchair == 1)Boatchair = 0;checkright[6] = 2;}if (Math.Abs(Devils3flag - 3.3) < 1E-6){Devils3.transform.position = new Vector3((float)-0.3, (float)-0.5, (float)-7.0);//-0.5Devils3flag = 4;if (Boatchair == 3)Boatchair = 1;if (Boatchair == 2)Boatchair = 0;checkright[6] = 2;}}}else{if(state==1){GUI.Label(new Rect(350, 50, 100, 50), "YOU FAILED!");}else if(state==2){GUI.Label(new Rect(350, 50, 100, 50), "YOU SUCCEED!");}if(GUI.Button(new Rect(350,150,100,50),"ReStart")){Restart();state = 0;}}
      }

      之后判断游戏的状态,在每点击一次过河按钮时,检查两岸的牧师和魔鬼的人数检验游戏的状态

    • int state = 0;//0:continue 1:fail 2:succeedvoid checkGame(){int count1 = 0;int count2 = 0;for (int i = 1; i <= 6; i++){if (checkleft[i] == 1)count1++;if (checkleft[i] == 2)count2++;}if (count2 > count1&&count1!=0)state = 1;count1 = 0;count2 = 0;for (int i = 1; i <= 6; i++){if (checkright[i] == 1)count1++;if (checkright[i] == 2)count2++;}if (count2 > count1&&count1!=0)state = 1;if (checkright[1] == 1 && checkright[2] == 1 && checkright[3] == 1)state = 2;}

      然后编写重新开始函数,代码如下:

void Restart(){Priests1.transform.position = new Vector3(-0.3F, -0.5F, 2F);Priests2.transform.position = new Vector3(-0.3F, -0.5F, 2.5F);Priests3.transform.position = new Vector3(-0.3F, -0.5F, 3F);Devils1.transform.position = new Vector3(-0.3F, -0.5F, 3.5F);Devils2.transform.position = new Vector3(-0.3F, -0.5F, 4F);Devils3.transform.position = new Vector3(-0.3F, -0.5F, 4.5F);Boat.transform.position = new Vector3(0F, -1F, 0F);Priests1flag = 1;Priests2flag = 1;Priests3flag = 1;Devils1flag = 1;Devils2flag = 1;Devils3flag = 1;Boatchair = 0;BoatFlag = 1;checkleft[1] = checkleft[2] = checkleft[3] = 1;checkleft[4] = checkleft[5] = checkleft[6] = 2;for (int i = 1; i <= 6;i++){checkright[i] = 0;}}

以上便配置好了基本上所有的行为。

 

这篇关于3D游戏编程与设计_HW3的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/280136

相关文章

不懂推荐算法也能设计推荐系统

本文以商业化应用推荐为例,告诉我们不懂推荐算法的产品,也能从产品侧出发, 设计出一款不错的推荐系统。 相信很多新手产品,看到算法二字,多是懵圈的。 什么排序算法、最短路径等都是相对传统的算法(注:传统是指科班出身的产品都会接触过)。但对于推荐算法,多数产品对着网上搜到的资源,都会无从下手。特别当某些推荐算法 和 “AI”扯上关系后,更是加大了理解的难度。 但,不了解推荐算法,就无法做推荐系

无人叉车3d激光slam多房间建图定位异常处理方案-墙体画线地图切分方案

墙体画线地图切分方案 针对问题:墙体两侧特征混淆误匹配,导致建图和定位偏差,表现为过门跳变、外月台走歪等 ·解决思路:预期的根治方案IGICP需要较长时间完成上线,先使用切分地图的工程化方案,即墙体两侧切分为不同地图,在某一侧只使用该侧地图进行定位 方案思路 切分原理:切分地图基于关键帧位置,而非点云。 理论基础:光照是直线的,一帧点云必定只能照射到墙的一侧,无法同时照到两侧实践考虑:关

Linux 网络编程 --- 应用层

一、自定义协议和序列化反序列化 代码: 序列化反序列化实现网络版本计算器 二、HTTP协议 1、谈两个简单的预备知识 https://www.baidu.com/ --- 域名 --- 域名解析 --- IP地址 http的端口号为80端口,https的端口号为443 url为统一资源定位符。CSDNhttps://mp.csdn.net/mp_blog/creation/editor

【Python编程】Linux创建虚拟环境并配置与notebook相连接

1.创建 使用 venv 创建虚拟环境。例如,在当前目录下创建一个名为 myenv 的虚拟环境: python3 -m venv myenv 2.激活 激活虚拟环境使其成为当前终端会话的活动环境。运行: source myenv/bin/activate 3.与notebook连接 在虚拟环境中,使用 pip 安装 Jupyter 和 ipykernel: pip instal

怎么让1台电脑共享给7人同时流畅设计

在当今的创意设计与数字内容生产领域,图形工作站以其强大的计算能力、专业的图形处理能力和稳定的系统性能,成为了众多设计师、动画师、视频编辑师等创意工作者的必备工具。 设计团队面临资源有限,比如只有一台高性能电脑时,如何高效地让七人同时流畅地进行设计工作,便成为了一个亟待解决的问题。 一、硬件升级与配置 1.高性能处理器(CPU):选择多核、高线程的处理器,例如Intel的至强系列或AMD的Ry

国产游戏崛起:技术革新与文化自信的双重推动

近年来,国产游戏行业发展迅猛,技术水平和作品质量均得到了显著提升。特别是以《黑神话:悟空》为代表的一系列优秀作品,成功打破了过去中国游戏市场以手游和网游为主的局限,向全球玩家展示了中国在单机游戏领域的实力与潜力。随着中国开发者在画面渲染、物理引擎、AI 技术和服务器架构等方面取得了显著进展,国产游戏正逐步赢得国际市场的认可。然而,面对全球游戏行业的激烈竞争,国产游戏技术依然面临诸多挑战,未来的

基于51单片机的自动转向修复系统的设计与实现

文章目录 前言资料获取设计介绍功能介绍设计清单具体实现截图参考文献设计获取 前言 💗博主介绍:✌全网粉丝10W+,CSDN特邀作者、博客专家、CSDN新星计划导师,一名热衷于单片机技术探索与分享的博主、专注于 精通51/STM32/MSP430/AVR等单片机设计 主要对象是咱们电子相关专业的大学生,希望您们都共创辉煌!✌💗 👇🏻 精彩专栏 推荐订阅👇🏻 单片机

【编程底层思考】垃圾收集机制,GC算法,垃圾收集器类型概述

Java的垃圾收集(Garbage Collection,GC)机制是Java语言的一大特色,它负责自动管理内存的回收,释放不再使用的对象所占用的内存。以下是对Java垃圾收集机制的详细介绍: 一、垃圾收集机制概述: 对象存活判断:垃圾收集器定期检查堆内存中的对象,判断哪些对象是“垃圾”,即不再被任何引用链直接或间接引用的对象。内存回收:将判断为垃圾的对象占用的内存进行回收,以便重新使用。

Go Playground 在线编程环境

For all examples in this and the next chapter, we will use Go Playground. Go Playground represents a web service that can run programs written in Go. It can be opened in a web browser using the follow

深入理解RxJava:响应式编程的现代方式

在当今的软件开发世界中,异步编程和事件驱动的架构变得越来越重要。RxJava,作为响应式编程(Reactive Programming)的一个流行库,为Java和Android开发者提供了一种强大的方式来处理异步任务和事件流。本文将深入探讨RxJava的核心概念、优势以及如何在实际项目中应用它。 文章目录 💯 什么是RxJava?💯 响应式编程的优势💯 RxJava的核心概念