예제 #1
0
 private void undo()
 {
     // TODO: Record an undo with logging as an event
     if (dynamicStateStack.Count <= 1)
     {
         return;
     }
     try {
         dynamicStateStack.Pop();
         DynamicState ds = dynamicStateStack.Peek();
         LoggingManager.instance.RecordEvent(LoggingManager.EventCodes.UNDO, ds.toJson());
         //int mimicIdx = 0;
         //int mirrorIdx = 0;
         List <coord> mimicCoords  = ds.mimicPositions.ToList();
         List <coord> mirrorCoords = ds.mirrorPositions.ToList();
         while (moveables.Count > 0)
         {
             MoveableScript ms = moveables[0];
             moveables.RemoveAt(0);
             if (ms is PlayerScript)
             {
                 continue;
             }
             Destroy(ms.gameObject);
         }
         player.SetCoords(ds.playerPosition.col, ds.playerPosition.row);
         player.transform.position = new Vector3(player.GetCoords().col + mapOrigin.x, player.GetCoords().row + mapOrigin.y + player.yOffset);
         moveables.Add(player);
         foreach (coord c in mimicCoords)
         {
             MimicScript m = GameObject.Instantiate(mimic);
             m.SetCoords(c.col, c.row);
             m.transform.position = new Vector3(c.col + mapOrigin.x, c.row + mapOrigin.y + m.yOffset, -0.2f);
             moveables.Add(m);
         }
         foreach (coord c in mirrorCoords)
         {
             MirrorScript m = GameObject.Instantiate(mirror);
             m.SetCoords(c.col, c.row);
             m.transform.position = new Vector3(c.col + mapOrigin.x, c.row + mapOrigin.y + m.yOffset, -0.2f);
             moveables.Add(m);
         }
         foreach (coord c in buttonCoords.Keys)
         {
             if (buttonCoords[c].laser.data.isActive != ds.activeButtons.Contains(c))
             {
                 buttonCoords[c].TogglePressed();
             }
         }
     } catch (InvalidOperationException) {
         //TODO: Actually display this to the user
         Debug.Log("Empty stack, no previous move to undo.");
     }
 }
예제 #2
0
    private void CheckSwaps()
    {
        List <MoveableScript> toDelete = new List <MoveableScript> ();
        List <MoveableScript> toAdd    = new List <MoveableScript> ();

        foreach (MoveableScript moveable in moveables)
        {
            Direction dr  = moveable.direction;
            int       row = moveable.GetCoords().row;
            int       col = moveable.GetCoords().col;
            if (moveable.shouldSwap && moveable.type == BoardCodes.MIMIC)
            {
                inputReady = false;
                boardState.board [row, col] = 24;
                // Instantiate a Mirror
                MirrorScript m = GameObject.Instantiate(mirror);
                m.SetCoords(col, row);
                m.transform.Rotate(0f, -90f, 0f);
                m.startSpin(90, false);
                toAdd.Add(m);
                toDelete.Add(moveable);
            }
            else if (moveable.shouldSwap && moveable.type == BoardCodes.MIRROR)
            {
                inputReady = false;
                boardState.board [row, col] = 23;
                // Instantiate a Mimic
                MimicScript m = GameObject.Instantiate(mimic);
                m.SetCoords(col, row);
                m.transform.Rotate(0f, -90f, 0f);
                m.startSpin(90, false);
                toAdd.Add(m);
                toDelete.Add(moveable);
            }
        }

        foreach (MoveableScript moveable in toDelete)
        {
            this.moveables.Remove(moveable);
            GameObject.Destroy(moveable.gameObject);
        }

        foreach (MoveableScript m in toAdd)
        {
            int col = m.GetCoords().col;
            int row = m.GetCoords().row;
            m.transform.position = new Vector3(col + mapOrigin.x, row + mapOrigin.y + m.yOffset, 0);
            moveables.Add(m);
        }
    }
예제 #3
0
    Level boardState; //Row, Column
                      // East col+, North row+

    /* 0 = empty
     * 1 = wall
     * 2 = player
     * 3 = mimic
     * 4 = mirror
     * 10 = goal
     */

    // Use this for initialization
    void Start()
    {
        firstStart = false;

        //load level using Melody's I/O
        boardState = IOScript.ParseLevel(levelName);

        // TODO: Below the way we get the index is DISGUSTING, this whole shitshow needs refactored
        levelNum = CreateLevelSelect.levelList.IndexOf(levelName);
        LoggingManager.instance.RecordLevelStart(levelNum, levelName);

        mapOrigin = new Vector2(-boardState.cols / 2.0f, -boardState.rows / 2.0f);
        mainCamera.orthographicSize = boardState.rows / 2.0f + 1;
        tutorial.text    = boardState.tutorial;
        tutorial.enabled = true;
        if (levelNum == 0)
        {
            tutorial1.SetActive(true);
        }
        else if (levelNum == 5)
        {
            tutorial6.SetActive(true);
        }


        int buttonCount = 0;

        //instantiate lasers based on parsed lasers
        if (boardState.lasers != null)
        {
            foreach (Laser la in boardState.lasers)
            {
                LaserScript l = GameObject.Instantiate(laser);
                l.makeLaser(la, mapOrigin);
                laserList.Add(l);
            }
        }

        //instantiate items based on board
        for (int i = 0; i < boardState.rows; i++)
        {
            for (int j = 0; j < boardState.cols; j++)
            {
                if (boardState.board[i, j] == 1)
                {
                    //wall
                    GameObject w;
                    if (i == 0 || boardState.board[i - 1, j] != 1)
                    {
                        w = GameObject.Instantiate(frontWall);
                    }
                    else
                    {
                        w = GameObject.Instantiate(wall);
                    }
                    w.transform.position = new Vector3(j + mapOrigin.x, i + mapOrigin.y, 0);
                }
                else if (boardState.board[i, j] >= 10 && boardState.board[i, j] < 20)
                {
                    // goal
                    GoalScript c = GameObject.Instantiate(goal);
                    c.transform.position = new Vector3(j + mapOrigin.x, i + mapOrigin.y, 0);
                    goalAtCoords.Add(new coord(i, j), c);
                    goalCoords.Add(new coord(i, j));
                }
                else if (boardState.board[i, j] >= 20 && boardState.board[i, j] < 30)
                {
                    // swap
                    GameObject c = GameObject.Instantiate(swap);
                    c.transform.position = new Vector3(j + mapOrigin.x, i + mapOrigin.y, 0);
                    swapCoords.Add(new coord(i, j));
                }
                else if (boardState.board[i, j] >= 30 && boardState.board[i, j] < 40)
                {
                    // button
                    ButtonToggleScript c = GameObject.Instantiate(button);
                    c.transform.position = new Vector3(j + mapOrigin.x, i + mapOrigin.y, 0);
                    c.laser = laserList[boardState.buttons[buttonCount]];
                    c.InitButton();
                    buttonCoords.Add(new coord(i, j), c);
                    buttonCount++;
                }
                else if (boardState.board[i, j] >= 50 && boardState.board[i, j] < 60)
                {
                    // portal
                    GameObject p = GameObject.Instantiate(portal);
                    p.transform.position = new Vector3(j + mapOrigin.x, i + mapOrigin.y, 0);
                    portalCoords.Add(new coord(i, j));
                }
                else
                {
                    // ground
                    GameObject g = GameObject.Instantiate(ground);
                    g.transform.position = new Vector3(j + mapOrigin.x, i + mapOrigin.y, 0);
                }

                if (boardState.board[i, j] % 10 == 2)
                {
                    // player
                    player = GameObject.Instantiate(player);
                    player.SetCoords(j, i);
                    player.transform.position = new Vector3(j + mapOrigin.x, i + mapOrigin.y + player.yOffset, -0.2f);
                    moveables.Add(player);
                }
                else if (boardState.board[i, j] % 10 == 3)
                {
                    // mimic
                    MimicScript m = GameObject.Instantiate(mimic);
                    m.SetCoords(j, i);
                    m.transform.position = new Vector3(j + mapOrigin.x, i + mapOrigin.y + m.yOffset, -0.2f);
                    moveables.Add(m);
                }
                else if (boardState.board[i, j] % 10 == 4)
                {
                    // mirror
                    MirrorScript m = GameObject.Instantiate(mirror);
                    m.SetCoords(j, i);
                    m.transform.position = new Vector3(j + mapOrigin.x, i + mapOrigin.y + m.yOffset, -0.2f);
                    moveables.Add(m);
                }
            }
        }

        if (boardState.portals != null)
        {
            for (int i = 0; i < boardState.portals.Length; i++)
            {
                portalMap.Add(portalCoords[i], portalCoords[boardState.portals[i]]);
            }
        }
    }