Exemplo n.º 1
0
    /// <summary>
    /// Restores the state of the game
    /// </summary>
    public void RestoreFromSave(MazeData maze, GameObject localPlayer, ScoreManager score)
    {
        Debug.Log("Restoring game state...");

        // restore enemy states
        for (int i = 0; i < maze.enemies.Count; i++)
        {
            Enemy     enemy     = maze.enemies[i];
            EnemySave enemySave = currentSave.enemies[i];

            enemy.GetComponent <NavMeshAgent>().Warp(enemySave.position);
            enemy.transform.position = enemySave.position;

            if (enemySave.dead)
            {
                enemy.Die();
            }
        }

        // set player position
        localPlayer.transform.position = currentSave.player.position;

        // set score
        score.SetScore(currentSave.score);
    }
Exemplo n.º 2
0
    public static void ParseData(string content, string fileName)
    {
        if (fileName.Contains("Element"))
        {
            MazeElement element = new MazeElement();
            element.elementId_ = int.Parse(fileName.Substring(fileName.LastIndexOf("_") + 1, fileName.IndexOf(".xml") - 1 - fileName.LastIndexOf("_")));
            MazeElement.ParseXML(content, element);
            mazeElements_.Add(element.elementId_, element);
        }
        else
        {
            MazeData data = new MazeData();
            data.mazeFileId_ = int.Parse(fileName.Substring(fileName.LastIndexOf("_") + 1, fileName.IndexOf(".xml") - 1 - fileName.LastIndexOf("_")));
            data.Init();

            ParseXML(content, data);

            if (metaData_.ContainsKey(data.id_))
            {
                ClientLog.Instance.LogError("Same id in SceneData :" + data.id_);
                return;
            }
            metaData_.Add(data.mazeFileId_, data);
        }
    }
Exemplo n.º 3
0
 public void BuildTree(MazeData maze, int scale)
 {
     _maze  = maze;
     _scale = scale;
     dict   = new Dictionary <int, List <int> >();
     for (int i = 0; i < maze.Used.Count - 1; i++)
     {
         int cur  = maze.Used[i];
         int next = maze.Used[i + 1];
         if (cur < 0 || next < 0)
         {
             continue;
         }
         if (!dict.TryGetValue(cur, out List <int> list))
         {
             list = new List <int>();
             dict.Add(cur, list);
         }
         if (!list.Contains(next))
         {
             list.Add(next);
         }
         if (!dict.TryGetValue(next, out list))
         {
             list = new List <int>();
             dict.Add(next, list);
         }
         if (!list.Contains(cur))
         {
             list.Add(cur);
         }
     }
 }
Exemplo n.º 4
0
    Vector3 getExitLocation(MazeData maze, Vector3 offset)
    {
        float   totalWidth    = mazeWidth * cellWidth;
        Vector3 startingPoint = new Vector3((totalWidth / 2) - (cellWidth / 2), 0.0f, (totalWidth / 2) - (cellWidth / 2));

        return(startingPoint + (Vector3.back * cellWidth) * (maze.m_exitConnectorIdx % mazeWidth) + (Vector3.left * cellWidth) * (maze.m_exitConnectorIdx / mazeWidth) + (offset * cellWidth));
    }
Exemplo n.º 5
0
 void InitAll(MazeData maze)
 {
     Debug.Log("Maze: " + maze);
     if (maze != null)
     {
         Maze = new Coordinate[MazeWidth, MazeHeight];
         for (int w = 0; w < MazeWidth; w++)
         {
             for (int h = 0; h < MazeHeight; h++)
             {
                 Maze[w, h] = new Coordinate(maze.Maze[w, h]);
             }
         }
         MazeStart  = new Coordinate(maze.MazeStart);
         MazeEnd    = new Coordinate(maze.MazeEnd);
         MazeWidth  = maze.MazeWidth;
         MazeHeight = maze.MazeHeight;
         DrawMaze();
         DataHandler.GameData.Coordinate player = DataHandler.instance.data.player;
         DataHandler.GameData.Coordinate enemy  = DataHandler.instance.data.enemy;
         InitPlayers(new Vector3(player.x, player.y, player.z), new Vector3(enemy.x, enemy.y, enemy.z));
     }
     else
     {
         InitMaze();
         CreateMazeBranches();
         DrawMaze();
         InitPlayers(new Vector3(0, -200, 0), new Vector3(0, -200, 0));
         DataHandler.instance.data.maze = createMazeData();
         DataHandler.instance.saveData();
         Debug.Log("MAZE NOW: " + DataHandler.instance.data.maze);
     }
 }
Exemplo n.º 6
0
    // This method saves the current created blocks
    private void saveBlocks()
    {
        //if (File.Exists(Application.persistentDataPath + "/userMazeData.data"))
        //{
        // Load the save file for details
        //BinaryFormatter bf = new BinaryFormatter();
        //FileStream file = File.Open(Application.persistentDataPath + "/userMazeData.data", FileMode.Open);
        //UserMazeData userMazeData = (UserMazeData)bf.Deserialize(file);
        //MazeCollection mazeCollection = userMazeData.getMazeByUsername(username);
        //file.Close();

        // Change the new data to be saved
        //MazeData mazeData = new MazeData();
        //mazeData.createdBlockData = blockData.gameData;

        //mazeCollection.saveMazeDataByTitle(mazeData, mazeTitle);
        //userMazeData.saveMazeCollectionByUsername(mazeCollection, username);

        // Save the data into the file
        //saveFile(userMazeData);
        //}

        MazeData mazeData = new MazeData();

        mazeData.createdBlockData = blockData.gameData;
        database.writeNewUserData(mazeData, userId, mazeTitle);
    }
Exemplo n.º 7
0
    public void loadBlocks(List <CreatedBlock> createdBlockData, bool buildMode, bool playMode)
    {
        if (buildMode)
        {
            Debug.Log("SAVING BLOCKS");

            // Change the new data to be saved
            MazeData mazeData = new MazeData();
            mazeData.createdBlockData = createdBlockData;

            // Save the data into the file
            saveFile(mazeData);

            Debug.Log("SAVING BLOCKS DONE");
            SceneManager.LoadScene(1);
        }

        if (playMode)
        {
            Debug.Log("SAVING BLOCKS");

            // Change the new data to be saved
            MazeData mazeData = new MazeData();
            mazeData.createdBlockData = createdBlockData;

            // Save the data into the file
            saveFile(mazeData);

            Debug.Log("SAVING BLOCKS DONE");
            SceneManager.LoadScene(2);
        }
    }
Exemplo n.º 8
0
    public void writeNewUserData(MazeData data, string userId, string mazeTitle)
    {
        databaseReference = FirebaseDatabase.DefaultInstance.RootReference;
        string json = JsonUtility.ToJson(data);

        databaseReference.Child("users").Child(userId).Child(mazeTitle).SetRawJsonValueAsync(json);
    }
Exemplo n.º 9
0
    // This method creates a new file or updates and overwrite the current saved file
    private void saveFile(MazeData mazeData)
    {
        BinaryFormatter bf   = new BinaryFormatter();
        FileStream      file = File.Create(Application.persistentDataPath + "/mazeData.data");

        bf.Serialize(file, mazeData);
        file.Close();
    }
Exemplo n.º 10
0
    // Use this for initialization
    void Start()
    {
        List <List <int> > mazeData = MazeData.Mazeref();

        for (int i = 0; i < 25; i = i + 1)
        {
            List <Floor> row = new List <Floor>();
            floorTiles.Add(row);
            for (int j = 0; j < 25; j = j + 1)
            {
                currentFloor = Instantiate(floor, new Vector3(j, 0, i), Quaternion.identity);

                Floor floorObject = new Floor(currentFloor);

                row.Add(floorObject);
                mMaterial = currentFloor.GetComponent <Renderer>().material;



                if (mazeData[j][mazeData.Count - i - 1] == 1)
                {
                    mMaterial.color = Color.blue;
                    floorObject.setWall(true);
                    for (int k = 1; k < 10; k++)
                    {
                        Instantiate(floor, new Vector3(j, k, i), Quaternion.identity);
                    }
                }
                else
                {
                    mMaterial.color = Color.white;
                }
            }
        }

        Vector3 wallPositionCenter = gameObject.transform.position;

        GameObject frontWall = Instantiate(wall, new Vector3(wallPositionCenter.x, wallPositionCenter.y, wallPositionCenter.z + 0.5f), Quaternion.identity);
        GameObject backWall  = Instantiate(wall, new Vector3(wallPositionCenter.x, wallPositionCenter.y, wallPositionCenter.z - 0.5f), Quaternion.identity);
        GameObject leftWall  = Instantiate(wall, new Vector3(wallPositionCenter.x - 0.5f, wallPositionCenter.y, wallPositionCenter.z), Quaternion.Euler(0, 90, 0));
        GameObject rightWall = Instantiate(wall, new Vector3(wallPositionCenter.x + 0.5f, wallPositionCenter.y, wallPositionCenter.z), Quaternion.Euler(0, -90, 0));

        frontWall.name = "Front";
        backWall.name  = "Back";
        leftWall.name  = "Left";
        rightWall.name = "Right";

        //frontWall.GetComponent<Renderer>().material.color = Color.green;
        //backWall.GetComponent<Renderer>().material.color = Color.red;
        //leftWall.GetComponent<Renderer>().material.color = Color.blue;
        //rightWall.GetComponent<Renderer>().material.color = Color.yellow;


        Coordinate c = new Coordinate(1, 1);

        controller = new Mover(frontWall, backWall, leftWall, rightWall, c);
    }
Exemplo n.º 11
0
        private void MakeMazeData()
        {
            string str = speaker.Get_Reply();
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            MultiplayerData      multiData  = serializer.Deserialize <MultiplayerData>(str);

            data = multiData.Other;
            DoTheThing();
        }
Exemplo n.º 12
0
    // TODO: get the options from an options file
    private void GetGameOptions()
    {
        MazeData mazeData = MazeModel.MazeData;

        mazeData.CellSideLength    = 10.0f;
        mazeData.Width             = 5;
        mazeData.Height            = 5;
        mazeData.CellWallThickness = 0.1f;
    }
Exemplo n.º 13
0
    // Use this for initialization
    void Start()
    {
        gameManager = GetComponent <GameManager>();

        _FileLocation = Application.dataPath;
        _FileName     = "Game Data/SaveData.xml";

        mazeData = new MazeData();
    }
 void Awake()
 {
     data = new int[, ]
     {
         { 1, 1, 1 },
         { 1, 0, 1 },
         { 1, 1, 1 }
     };
     mazeData = new MazeData(settings.CurrentDifficulty.Complexity, settings.CurrentDifficulty.SafePathDistance);
 }
Exemplo n.º 15
0
    public void SaveCompletionStats(GameManager manager)
    {
        string fileName;
        string dataPath;
        bool   betterTime;

        //Create new MazeData variable and set relevant information
        MazeData mData = new MazeData();

        mData.size   = manager.mazeSize;
        mData.minute = manager.minute;
        mData.second = manager.second;

        //Set the fileName, adding .json at the end
        fileName = mData.size + ".json";

        //Set the value of betterTime by calling the CheckPlayerTime method
        betterTime = manager.CheckPlayerTime(fileName, mData);

        //Check if betterTime is true
        if (betterTime)
        {
            //If it is then do this

            //Set dataPath depending on what game is being run on
            #if UNITY_EDITOR
            dataPath = "Assets/Resources/";
            #elif UNITY_ANDROID && !UNITY_EDITOR
            dataPath = Application.persistentDataPath + "/";
            #elif UNITY_STANDALONE && !UNITY_EDITOR
            dataPath = Application.persistentDataPath + "/";
            #endif

            //Generate JSON representation of the fields of mData
            string mazeCompletionData = JsonUtility.ToJson(mData);

            using (FileStream fs = new FileStream(dataPath + fileName, FileMode.Create))
            {
                using (StreamWriter writer = new StreamWriter(fs))
                {
                    writer.Write(mazeCompletionData);
                }
            }

            //Show message saying that a new best time has been achieved
            bestTimeText.gameObject.SetActive(true);
            bestTimeText.text = "A new best time for a " + mData.size + " maze has been recorded.";
        }
        else
        {
            //If it isn't then set the baseTimeText gameObject to inactive
            bestTimeText.gameObject.SetActive(false);
        }
    }
Exemplo n.º 16
0
    void generateMaze()
    {
        Debug.Log("Generating Maze");
        MazeData maze = new MazeData(mazeWidth);

        maze.generateMaze();

        for (int j = 0; j < mazeWidth; j++)
        {
            for (int i = 0; i < mazeWidth; i++)
            {
                if (i == Mathf.Floor(mazeWidth / 2) && j == Mathf.Floor(mazeWidth / 2))
                {
                    continue;
                }
                else
                {
                    generateRoom(maze.m_maze[i + (j * mazeWidth)], getRoomLocation(i, j));
                }
            }
        }
        // Instantiate Exit
        Vector3 exitOffset;
        float   exitRotation;

        switch (maze.m_exitDirection)
        {
        case MazeData.Direction.North:
            exitOffset   = new Vector3(1.0f, 0.0f, 0.0f);
            exitRotation = -90.0f;
            break;

        case MazeData.Direction.South:
            exitOffset   = new Vector3(-1.0f, 0.0f, 0.0f);
            exitRotation = 90.0f;
            break;

        case MazeData.Direction.East:
            exitOffset   = new Vector3(0.0f, 0.0f, -1.0f);
            exitRotation = 0.0f;
            break;

        case MazeData.Direction.West:
            exitOffset   = new Vector3(0.0f, 0.0f, 1.0f);
            exitRotation = 180.0f;
            break;

        default:
            throw new System.Exception("No maze exit found");
        }
        Instantiate(exit, getExitLocation(maze, exitOffset), Quaternion.Euler(0.0f, exitRotation, 0.0f), mazeObj.transform);

        Debug.Log("Done");
    }
Exemplo n.º 17
0
 public MazeManager()
 {
     _data           = null;
     _mazeGameObject = null;
     _curSG          = 0;
     _prvSG          = 0;
     _curPO          = 0;
     _prvPO          = 0;
     _pickups        = new List <PickupBehaviour>();
     CanDoPickup     = false;
 }
Exemplo n.º 18
0
    public void Savegame(MazeGen mg, string name)
    {
        BinaryFormatter bf = new BinaryFormatter();

        string     path = Application.dataPath + "/Levels/" + name + ".oof";
        FileStream fs   = new FileStream(path, FileMode.Create);

        MazeData m = new MazeData(mg);

        bf.Serialize(fs, m);
        fs.Close();
    }
Exemplo n.º 19
0
    public MazeGenerator(MazeData data, MazeCellData mcData)
    {
        _data   = data;
        _mcData = mcData;
        ROWS    = _data.numberOfRows;
        COLS    = _data.numberOfColumns;
        LAYS    = _data.numberOfLayers;

        _maze = new Maze(ROWS, COLS, LAYS, mcData);

        _cellStack = new Stack <MazeCell>();
    }
Exemplo n.º 20
0
    void Start()
    {
        whiteTex = new Texture2D(1, 4);
        whiteTex.SetPixel(1, 1, Color.grey);
        whiteTex.SetPixel(1, 2, Color.white);
        whiteTex.SetPixel(1, 3, Color.grey);
        whiteTex.SetPixel(1, 4, Color.grey);
        whiteTex.Apply();

        maze = GameObject.Find("aMaze").GetComponent <MazeData> ();

        CreateNewMaze(3, 1, 3);
    }
Exemplo n.º 21
0
    public BasicMaze(int R, int C)
    {
        this.R = R;
        this.C = C;

        blocks = new List <List <bool> >();
        // +2 because of the border on both side
        for (int r = 0; r < R + 2; r++)
        {
            blocks.Add(new List <bool>());
            for (int c = 0; c < C + 2; c++)
            {
                blocks[r].Add(false);
            }
        }

        startPoint = new Point();
        endPoint   = new Point();

        string mazeData = MazeData.getRandomMazeData(R, C, GameState.difficulty);

        if (mazeData != null)
        {
            string[] token = mazeData.Split();

            startPoint.r = Convert.ToInt32(token[0]);
            startPoint.c = Convert.ToInt32(token[1]);

            // +2 because of the border on both side
            for (int r = 0; r < R + 2; r++)
            {
                for (int c = 0; c < C + 2; c++)
                {
                    blocks[r][c] = (token[2][r * (C + 2) + c] == '0') ? false : true;
                }
            }
        }
        else
        {
            // Set random value on each block
            for (int r = 1; r <= R; r++)
            {
                for (int c = 1; c <= C; c++)
                {
                    blocks[r][c] = (random.Next(2) == 0) ? false : true;
                }
            }
        }

        setFitness();
    }
Exemplo n.º 22
0
    public static void BuildLabyrinth(MazeData mazeData)
    {
        MazeRoomPrefab[] roomPrefabs = mazeData.roomPrefabList.prefabs;
        // Initialize room bounds
        Bounds maxBounds = new Bounds(Vector3.zero, Vector3.zero);

        for (int i = 0; i < roomPrefabs.Length; i++)
        {
            maxBounds = MazeRoomUtility.GetMaxBounds(maxBounds, roomPrefabs [i]);
        }
        //
        GameObject      theCube = mazeData.gameObject;
        MazeDescription maze    = mazeData.maze;

        // Remove all rooms (children of the maze game object)
        if (!RemoveMazeChildren(theCube))
        {
            return;
        }

        for (int i = 0; i < maze.Rooms.Count; i++)
        {
            MazeRoom mazeRoom       = maze.Rooms [i];
            Vector3  prefabPosition = new Vector3(mazeRoom.coords.x * maxBounds.size.x, mazeRoom.coords.y * maxBounds.size.y, mazeRoom.coords.z * maxBounds.size.z);

            if (mazeRoom != null && roomPrefabs != null && roomPrefabs.Length > mazeRoom.OpenedWays && roomPrefabs [mazeRoom.OpenedWays] != null && roomPrefabs [mazeRoom.OpenedWays].rooms != null && roomPrefabs [mazeRoom.OpenedWays].rooms.Count > 0)
            {
                GameObject myMazeRoom = CreateMazeRoom(mazeRoom.coords, theCube, roomPrefabs [mazeRoom.OpenedWays].rooms [0], prefabPosition);
                mazeRoom.roomObject = myMazeRoom;
                // Send a signal to the room so it can handle its state if needed (ex: teleporter, scripts as ScatterMonster, ScatterCrates)
                myMazeRoom.BroadcastMessage("OnMazeUpdate", mazeRoom, SendMessageOptions.DontRequireReceiver);
            }
            else
            {
                if (roomPrefabs.Length > mazeRoom.OpenedWays)
                {
                    Debug.LogWarning("No prefab for Room(" + i + ") " + mazeRoom.OpenedWays);
                }
                else if (mazeRoom == null)
                {
                    Debug.LogError("Found a null Room@ " + i + " !");
                }
                else
                {
                    Debug.LogWarning("Wrong prefab request@" + i + " " + mazeRoom.coords + " :" + mazeRoom.OpenedWays);
                }
            }
        }
        // Send the end signal to all rooms
        mazeData.BroadcastMessage("OnMazeDone", mazeData, SendMessageOptions.DontRequireReceiver);
    }
Exemplo n.º 23
0
 // This method loads the previously saved blocks
 private void loadBlocks()
 {
     Debug.Log("LOAD TRIGGED");
     if (File.Exists(Application.persistentDataPath + "/mazeData.data"))
     {
         BinaryFormatter bf           = new BinaryFormatter();
         FileStream      file         = File.Open(Application.persistentDataPath + "/mazeData.data", FileMode.Open);
         MazeData        userMazeData = (MazeData)bf.Deserialize(file);
         file.Close();
         blockData.gameData.Clear(); // Clear the current blocks
         blockData.gameData = userMazeData.createdBlockData;
     }
     placeLoadedBlocks();
 }
Exemplo n.º 24
0
    void Start()
    {
        Debug.Log(GameState.difficulty);

        GameState.state = GameState.PLAYING;
        Time.timeScale  = 1;

        for (int h = 0; h < MAZE_H; h++)
        {
            if (MazeData.getRandomMazeData(MAZE_R, MAZE_C, GameState.difficulty) != null)
            {
                // Offline
                basicMazes.Add(new BasicMaze(MAZE_R, MAZE_C));
            }
            else
            {
                // Online
                // Online assume difficuty = 0
                generateBasicMaze();
            }

            if (isDebugging)
            {
                basicMazes[h].log();
            }
        }

        instantiateMaze();

        allocateItem();

        initialRandomEvent();

        generatePlayer();

        generateBoss();

        switch (GameMode.mode)
        {
        case GameMode.ESCAPING:
            EscapingState.state = EscapingState.BEGINNING;
            TargetMenu.addTarget("Find the exit.");
            break;

        case GameMode.INFINITE:
            TargetMenu.addTarget("Try to survive!");
            break;
        }
    }
Exemplo n.º 25
0
 public void OnMazeDone(MazeData mazeData)
 {
     if (firstRoom != null)
     {
         // Place the player at the center of the first room
         if (GameObject.FindGameObjectWithTag("Player") != null)
         {
             Transform playerT = GameObject.FindGameObjectWithTag("Player").transform;
             if (playerT != null)
             {
                 playerT.position = Vector3.Scale(mazeData.roomSize, firstRoom.coords) + playerT.localScale.y * 0.5f * Vector3.up;
             }
         }
     }
 }
 public IEnumerator CreateMaze()
 {
     if (seed == 0)
     {
         seed = System.DateTime.Now.Millisecond;
     }
     data = GetComponent <MazeData>();
     CreateGrid(1);
     Random.InitState(seed);
     for (int i = 0; i < data.numLayers; i++)
     {
         StartCoroutine(GenerateMaze(i));
     }
     yield return(null);
 }
Exemplo n.º 27
0
    int _scale;             //缩放
    public void BuildMesh(MazeData maze, int scale)
    {
        _scale    = scale;
        _maze     = maze;
        mesh      = new Mesh();
        _vertex   = new List <Vector3>();
        _triangle = new List <int>();
        _uv       = new List <Vector2>();
        BuildFullMesh();
        CullTriangle();

        mesh.SetVertices(_vertex);
        mesh.SetTriangles(_triangle, 0);
        mesh.SetUVs(0, _uv);
    }
Exemplo n.º 28
0
        private void MakeMazeData()
        {
            string str = speaker.Get_Reply();
            JavaScriptSerializer serializer = new JavaScriptSerializer();

            if (isMulti == false)
            {
                data = serializer.Deserialize <MazeData>(str);
            }
            else
            {
                MultiplayerData multiData = serializer.Deserialize <MultiplayerData>(str);
                data = multiData.You;
            }
            DoTheThing();
        }
Exemplo n.º 29
0
    /// <summary>
    /// Creates a maze
    /// </summary>
    /// <returns></returns>
    private IEnumerator CreateMaze(string seed = null)
    {
        working = true;

        if (seed == null)
        {
            random = new System.Random();
        }
        else
        {
            random = new System.Random(seed.GetHashCode());
        }

        currentMaze = Instantiate(mazeParentPrefab).GetComponent <MazeData>();

        currentMaze.seed = seed;

        currentMaze.tilesArray = new MazeTile[mazeSize, mazeSize];

        // Create the maze
        FillMaze();
        GeneratePath();

        // Starting and exit points
        currentMaze.tilesArray[0, 0].walls[2].GetComponent <Renderer>().enabled = false;
        currentMaze.tilesArray[mazeSize - 1, mazeSize - 1].walls[0].GetComponent <Renderer>().enabled = false;

        // wait 1 frame for colliders to update
        yield return(new WaitForEndOfFrame());

        // build nav mesh
        currentMaze.GetComponent <NavMeshSurface>().BuildNavMesh();

        // place door
        PlaceDoor();

        // spawn enemies in
        SpawnEnemies();

        // trigger event
        if (OnGeneratingComplete != null)
        {
            OnGeneratingComplete(currentMaze);
        }

        working = false;
    }
Exemplo n.º 30
0
    public void OnResumeClick()
    {
        if (GameManager.gameState == GameState.Menu)
        {
            // Load UserData into myData
            LoadXML();

            // Check if data has been loaded
            if (_data.ToString() != "")
            {
                // Cast to type (UserData) so returned object is converted to correct type
                mazeData = (MazeData)DeserializeObject(_data);

                gameManager.MazeInstance   = Instantiate(savedMaze.gameObject) as Maze;
                gameManager.PlayerInstance = Instantiate(gameManager.playerPrefab) as Player;
                gameManager.PlayerInstance.transform.position = new Vector3(mazeData.playerPosition.x, mazeData.playerPosition.y, mazeData.playerPosition.z);
                gameManager.EndInstance = Instantiate(gameManager.endPrefab) as End;
                gameManager.EndInstance.transform.position = new Vector3(mazeData.endPosition.x, mazeData.endPosition.y, mazeData.endPosition.z);
                gameManager.TrapsInstance = Instantiate(gameManager.trapPrefab) as Traps;
                gameManager.TrapsInstance.transform.position = new Vector3(mazeData.trapPosition.x, mazeData.trapPosition.y, mazeData.trapPosition.z);
                gameManager.CupInstance = Instantiate(gameManager.cupPrefab) as Cup;
                gameManager.CupInstance.transform.position = new Vector3(mazeData.cupPosition.x, mazeData.cupPosition.y, mazeData.cupPosition.z);
                gameManager.CheeseInstance[0] = Instantiate(gameManager.cheesePrefab) as Cheese;
                gameManager.CheeseInstance[0].transform.position = new Vector3(mazeData.cheesePosition.one.x, mazeData.cheesePosition.one.y, mazeData.cheesePosition.one.z);
                gameManager.CheeseInstance[1] = Instantiate(gameManager.cheesePrefab) as Cheese;
                gameManager.CheeseInstance[1].transform.position = new Vector3(mazeData.cheesePosition.two.x, mazeData.cheesePosition.two.y, mazeData.cheesePosition.two.z);
                gameManager.CheeseInstance[2] = Instantiate(gameManager.cheesePrefab) as Cheese;
                gameManager.CheeseInstance[2].transform.position = new Vector3(mazeData.cheesePosition.three.x, mazeData.cheesePosition.three.y, mazeData.cheesePosition.three.z);
                gameManager.CheeseInstance[3] = Instantiate(gameManager.cheesePrefab) as Cheese;
                gameManager.CheeseInstance[3].transform.position = new Vector3(mazeData.cheesePosition.four.x, mazeData.cheesePosition.four.y, mazeData.cheesePosition.four.z);
                gameManager.CheeseInstance[4] = Instantiate(gameManager.cheesePrefab) as Cheese;
                gameManager.CheeseInstance[4].transform.position = new Vector3(mazeData.cheesePosition.five.x, mazeData.cheesePosition.five.y, mazeData.cheesePosition.five.z);
                gameManager.BombInstance[0] = Instantiate(gameManager.bombPrefab) as Bombs;
                gameManager.BombInstance[0].transform.position = new Vector3(mazeData.bombPosition.one.x, mazeData.bombPosition.one.y, mazeData.bombPosition.one.z);
                gameManager.BombInstance[1] = Instantiate(gameManager.bombPrefab) as Bombs;
                gameManager.BombInstance[1].transform.position = new Vector3(mazeData.bombPosition.two.x, mazeData.bombPosition.two.y, mazeData.bombPosition.two.z);
                gameManager.BombInstance[2] = Instantiate(gameManager.bombPrefab) as Bombs;
                gameManager.BombInstance[2].transform.position = new Vector3(mazeData.bombPosition.three.x, mazeData.bombPosition.three.y, mazeData.bombPosition.three.z);
                gameManager.BombInstance[3] = Instantiate(gameManager.bombPrefab) as Bombs;
                gameManager.BombInstance[3].transform.position = new Vector3(mazeData.bombPosition.four.x, mazeData.bombPosition.four.y, mazeData.bombPosition.four.z);

                Destroy(gameManager.MenuCanvasInstance.gameObject);
                gameManager.InGameCanvasInstance = Instantiate(gameManager.inGameCanvasPrefab) as Canvas;
                GameManager.gameState            = GameState.ResumePlay;
            }
        }
    }
Exemplo n.º 31
0
 public Maze()
 {
     m_mazeData = new MazeData();
 }
Exemplo n.º 32
0
        public override MazeState Step(MazeData md)
        {
            if (!this.initialized)
            {
                Point start = md.startCoords;
                if (md.TestCellInMaze(start))
                {
                    NukeFunc(new Rect(md.startCoords, new Point(md.tunnelWidth, md.tunnelWidth)));
                    visitedCells.Add(start);
                    md.tunnelling.Add(start);
                    initialized = true;
                    return new MazeState(1, String.Format("New maze initiated at ({0},{1})", start.X, start.Y));
                }
                else
                {
                    return new MazeState(-1, String.Format("Starting point ({0},{1}) not within maze boundary.", start.X, start.Y));
                }
            } // end initialization block

            if (visitedCells.Count <= 0)
            {
                return new MazeState(8, "Maze completed.");
            }
            else
            {
                Point p;
                switch (md.variant)
                {
                    default:
                        p = visitedCells.Last();
                        break;
                }

                md.lastCell = p;

                List<int> rndDirs = new List<int>(new int[] { 0, 1, 2, 3 });
                MazeTools.Shuffle(rndDirs, md.rng);

                foreach (int d in rndDirs)
                {
                    Point p2 = MazeTools.MoveCell(p, md.dirs[d]);
                    if (md.TestCellInMaze(p2))
                    {
                        if (this.PeekFunc(p2))
                        {
                            Rect rect = md.MakeOffset(p2, d);
                            this.NukeFunc(rect);
                            visitedCells.Add(p2);
                            md.tunnelling.Add(p2);
                            md.lastCell = p2;
                            return new MazeState(4, String.Format("Maze in progress; currently at ({0},{1}).", p2.X, p2.Y));
                        }
                        else
                        {
                            double randomChance = 0.01; // 0.1 = 10% chance
                            double dice = md.rng.NextDouble();
                            if (dice <= randomChance)
                            {
                                Rect rect = md.MakeOffset(p2, d);
                                this.NukeFunc(rect);
                                visitedCells.Add(p2);
                                md.tunnelling.Add(p2);
                                md.lastCell = p2;
                                return new MazeState(4, String.Format("Maze in progress; currently at ({0},{1}).", p2.X, p2.Y));
                            }
                            else if (d == rndDirs.Last()) // if no directions were tunnel-able
                            {
                                visitedCells.Remove(p); // remove this cell from the list
                                break; // shouldn't matter but just in case
                            }
                        }
                    }
                    else
                    {

                    }
                } //end directions foreach loop

                return new MazeState(2, String.Format("Maze in progress; currently at ({0},{1}).", p.X, p.Y));
            }
        }
Exemplo n.º 33
0
 public abstract MazeState Step(MazeData md);