/* * * * * * * * * * * * *
        * Section 7.19.5 Queues *
        * * * * * * * * * * * * */
        void UseMovementQueue()
        {
            Queue queue = new Queue();

            queue.Enqueue("First");
            queue.Enqueue("Second");
            queue.Enqueue("Third");
            Debug.Log(queue.Peek());
            // First
            Debug.Log(queue.Dequeue());
            // First
            Debug.Log(queue.Dequeue());
            // Second
            Debug.Log(queue.Dequeue());
            // Third

            GameObject capsule = GameObject.CreatePrimitive(PrimitiveType.Capsule);
            MoveQueue  mover   = capsule.AddComponent <MoveQueue>();

            mover.AddMove(Moves.None);
            mover.AddMove(Moves.Forward);
            mover.AddMove(Moves.None);
            mover.AddMove(Moves.Left);
            mover.AddMove(Moves.Right);
            mover.AddMove(Moves.None);
            mover.AddMove(Moves.Backward);
            mover.Move();
        }
        public override void Reset()
        {
            Text.WriteLine("Another attempt, eh?");
            MoveQueue.Clear();
            base.Reset();

            InitElements();
        }
Example #3
0
    /// <summary>
    /// Use this for initialization
    /// </summary>
    void Start()
    {
        _moveQueue = GetComponent <MoveQueue>();
        _animator  = GetComponent <Animator>();
        _animator.Play("PlayerRight");
        _animator.enabled = false;

        _moveQueue.DirectionChanged += OnDirectionChange;
    }
        public override bool UndoMove()
        {
            if (!base.UndoMove())
            {
                Text.WriteLine("Nothing to undo");
                return(false);
            }

            Text.WriteLine("?!?");
            MoveQueue.Clear();

            InitElements();
            return(true);
        }
        public virtual void Step(float elapsedSec)
        {
            if (MoveQueue.Any())
            {
                if (waitTime > 0)
                {
                    waitTime -= elapsedSec;
                }
                else
                {
                    LastMoveResult = base.Move(MoveQueue.Dequeue());
                    if (LastMoveResult != MoveResult.Ok)
                    {
                        Text.WriteLine(LastMoveResult.ToString());
                        if (LastMoveResult == MoveResult.Win)
                        {
                            Text.WriteLine("Congratulations");
                        }
                    }
                    waitTime = 0.1f;
                }
            }
            else
            {
                waitTime = 0;
            }

            foreach (var e in RootElements)
            {
                e.Step(elapsedSec);                             // nested steps handles by GameElement.Step()
            }
            if (ToBeRemoved.Any())
            {
                foreach (var e in ToBeRemoved)
                {
                    RemoveElement(e);
                }
                ToBeRemoved.Clear();
            }
        }
Example #6
0
    public void MouseGridCommands()
    {
        if (Input.GetMouseButtonDown(0))
        {
            RaycastHit hit;
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out hit))
            {
                GameObject objectHit = hit.transform.gameObject;

                Select(objectHit);
            }
        }

        if (Input.GetMouseButtonDown(1))
        {
            RaycastHit hit;
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out hit))
            {
                int x;
                int z;
                grid.GetXY(hit.transform.position, out x, out z);
                // Only allow this flag setting to occur if the targeted game object is a tile
                if (selected.GetComponent <Unit>())
                {
                    MetaInformation mi = selected.GetComponent <MetaInformation>();
                    Debug.Log(selected);
                    selected.GetComponent <MoveQueue>().Clear();
                    selected.GetComponent <Highlight>().RemoveFlag();
                    if (grid.pathNodes[x, z].isWalkable)
                    {
                        if (pf.FindPath(mi.x, mi.z, x, z) != null)
                        {
                            selected.GetComponent <Highlight>().PlaceFlag(x, grid.gridArray[x, z].height, z, flagPrefab);
                        }
                    }
                }
            }
        }

        foreach (var unitClone in units)
        {
            if (unitClone.GetComponent <Unit>() && unitClone.GetComponent <MoveQueue>())
            {
                MoveQueue mq = unitClone.GetComponent <MoveQueue>();
                if (unitClone.GetComponent <State>().GetState() == Constants.BUSY)
                {
                    return;
                }
                if (mq.q.Count > 0)
                {
                    return;
                }
                if (unitClone.GetComponent <Highlight>() == null)
                {
                    return;
                }
                if (unitClone.GetComponent <Highlight>().rallyPoint == null)
                {
                    return;
                }
                int             x  = unitClone.GetComponent <Highlight>().rallyPoint.x;
                int             z  = unitClone.GetComponent <Highlight>().rallyPoint.z;
                MetaInformation mi = unitClone.GetComponent <MetaInformation>();
                if (x == mi.x && z == mi.z)
                {
                    unitClone.GetComponent <Highlight>().RemoveFlag();
                }
                List <PathNode> path = pf.FindPath(mi.x, mi.z, x, z);

                if (path == null)
                {
                    Debug.Log("No route to the target!");
                }

                foreach (PathNode node in path)
                {
                    unitClone.GetComponent <MoveQueue>().AddMove(new Vector3(node.x, grid.gridArray[node.x, node.z].height, node.z));
                }
            }
        }
    }
Example #7
0
 /// <summary>
 /// Use this for initialization
 /// </summary>
 void Start()
 {
     _moveQueue = GetComponent <MoveQueue>();
 }
Example #8
0
 public void Start()
 {
     mq = gameObject.GetComponent <MoveQueue>();
     Debug.Log(mq);
 }
 public override MoveResult Move(VectorInt2 direction)
 {
     MoveQueue.Enqueue(direction);
     return(MoveResult.InQueue);
 }