Exemplo n.º 1
0
 public Result(string word, int x, int y, Grid.Direction direction)
 {
     Word      = word;
     X         = x;
     Y         = y;
     Direction = direction;
 }
Exemplo n.º 2
0
    /// <summary>
    /// Constructor
    /// </summary>
    /// <param name="x">x coordinate.</param>
    /// <param name="y">y coordinate.</param>
    /// <param name="parent">Parent object</param>
    /// <param name="dir">Direction to move in.</param>
    public Redirection(int x, int y, GameObject parent, Grid.Direction dir)
    {
        direction = dir;

        // size pulser settings
        float   r     = UnityEngine.Random.Range(0.1f, 0.9f);
        Vector2 small = new Vector2(0.95f, 0.95f);
        Vector2 big   = new Vector2(1.05f, 1.05f);

        // make Redirect
        GameObject rObject = ResourceLoader.GetSpriteGameObject(dir + "Redirect", parent, (float)x, (float)y, "Tools", 1, "Sprites/Tools/Redirect");

        pulse = rObject.AddComponent <SizePulser>();
        pulse.SetParams(true, r, small, big);

        // rotate sprite (if necessary)
        if (dir == Grid.Direction.Left)
        {
            rObject.transform.Rotate(Vector3.forward, 90.0f);
        }
        else if (dir == Grid.Direction.Right)
        {
            rObject.transform.Rotate(Vector3.forward, -90.0f);
        }
        else if (dir == Grid.Direction.Down)
        {
            rObject.transform.Rotate(Vector3.forward, 180.0f);
        }
    }
Exemplo n.º 3
0
 /// <summary>
 /// Handles player input and movement every frame.
 /// </summary>
 void Update()
 {
     // check for player movement
     if (!isMoving && canMove)   // input is ignored if player is currently moving
     {
         if (extraMove)
         {
             extraMove = false;
             CheckMovement(extraMoveDirection);
         }
         else
         {
             if (Input.GetAxisRaw("Vertical") > 0.0f)
             {
                 CheckMovement(Grid.Direction.Up);
                 lastMove = Grid.Direction.Up;
             }
             else if (Input.GetAxisRaw("Vertical") < 0.0f)
             {
                 CheckMovement(Grid.Direction.Down);
                 lastMove = Grid.Direction.Down;
             }
             else if (Input.GetAxisRaw("Horizontal") < 0.0f)
             {
                 CheckMovement(Grid.Direction.Left);
                 lastMove = Grid.Direction.Left;
             }
             else if (Input.GetAxisRaw("Horizontal") > 0.0f)
             {
                 CheckMovement(Grid.Direction.Right);
                 lastMove = Grid.Direction.Right;
             }
         }
     }
 }
Exemplo n.º 4
0
        public Result FindWord(string word)
        {
            int thisX = 1, thisY = 1;

            foreach (Grid.Row row in _grid.Rows)
            {
                foreach (char column in row.Columns)
                {
                    foreach (string name in Enum.GetNames(typeof(Grid.Direction)))
                    {
                        Grid.Direction thisDirection = (Grid.Direction)Enum.Parse(typeof(Grid.Direction), name);
                        string         test          = _grid.StringAt(thisX, thisY, word.Length, thisDirection);
                        if (test.Length == word.Length && test.ToLowerInvariant() == word.ToLowerInvariant())
                        {
                            // found it!
                            return(new Result(word, thisX, thisY, thisDirection));
                        }
                    }
                    thisX++;
                }
                thisX = 1;
                thisY++;
            }

            return(null);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Checks if the player can move in a certain direction. If they can, move them there.
 /// </summary>
 /// <param name="d">Direction the player will move in.</param>
 private void CheckMovement(Grid.Direction d)
 {
     IntVector.IntVector3 newLoc = grid.NewPlayerLocation(d);
     if (newLoc.z > 0)
     {
         isMoving = true;
         lastMove = d;
         StartCoroutine(Move(newLoc, d));
     }
 }
Exemplo n.º 6
0
 /// <summary>
 /// Initialization
 /// </summary>
 void Start()
 {
     isMoving  = false;
     colour    = ColourPicker.Colour.White;
     canMove   = true;
     eraserOn  = false;
     lastMove  = extraMoveDirection = Grid.Direction.Left;
     extraMove = false;
     reset     = false;
     paused    = false;
 }
Exemplo n.º 7
0
        public virtual void AddConnection <T>(Grid.Direction direction, T gridNode) where T : GridNode
        {
            if (connectionByDirection == null)
            {
                connectionByDirection = new Dictionary <Grid.Direction, GridNode>();
            }
            GridNode newNode = gridNode;

            connectionByDirection.Add(direction, newNode);
            connections.Add(gridNode);
        }
Exemplo n.º 8
0
    /// <summary>
    /// Smoothly moves the player to the given position.
    /// </summary>
    /// <param name="newLoc">Contains the new location for the player (x, y component) and the distance the player must travel (z component).</param>
    /// <param name="d">Direction the player is moving in.</param>
    private IEnumerator Move(IntVector.IntVector3 newLoc, Grid.Direction d)
    {
        Vector2 startPos      = transform.localPosition;                       // start location
        Vector2 endPos        = new Vector2((float)newLoc.x, (float)newLoc.y); // end location
        float   moveTimer     = 0.0f;                                          // time elapsed during move
        float   moveTimeLimit = 0.12f * ((float)newLoc.z + 1);                 // total time to finish movement
        float   ratio         = 0.0f;                                          // lerp ratio
        float   unitCounter   = 0.0f;                                          // checks if player has moved a unit

        // move player
        while (ratio < 1.0f)
        {
            if (!paused)
            {
                if (reset)      // check if reset button was pressed
                {
                    reset = false;
                    break;
                }

                float prev = ratio;
                moveTimer += Time.deltaTime;
                ratio      = moveTimer / moveTimeLimit;
                transform.localPosition = Vector2.Lerp(startPos, endPos, ratio);

                // check if we've moved a unit
                unitCounter += (ratio - prev) * ((float)newLoc.z);
                if (unitCounter >= 1.0f)
                {
                    grid.MovePlayer(d);
                    unitCounter -= 1.0f;
                }
            }

            yield return(null);
        }

        // player no longer moving
        isMoving = false;

        // check if the puzzle is completed
        if (!extraMove)
        {
            moveCount.Increment();
        }
        grid.CheckForFinishedPuzzle();
    }
Exemplo n.º 9
0
 /// <summary>
 /// Enables the player to move again after the inital move is over.
 /// </summary>
 /// <param name="d">Direction the next move will be.</param>
 public void MakeExtraMove(Grid.Direction d)
 {
     extraMove          = true;
     extraMoveDirection = d;
 }