Beispiel #1
0
 /* Removes this Entity from the grid without changing its Grid reference.
  * NOTE: Sideline is not a real list, its just an idea.
  * Useful for important Entities like Geners and Solvers that you need to keep instantiated.
  *
  * PRECONDITION: Grid is not null
  * POSTCONDITION: location == null and Grid does not contain this.
  */
 public void MoveToSideline()
 {
     if (Location != null)
     {
         Grid.Remove(Location);
     }
 }
Beispiel #2
0
 /* Moves this Entity to another Location within the Grid.
  * Removes whatever was at its original position.
  * Returns the Entity that was originally occupying that Location, null if there was nothing there.
  *
  * PRECONDITION: Grid and Location != null;
  * PARAMETER: grid.IsValid(x, y) == true;
  * POSTCONDITION: grid.Get(x, y) == this;
  * POSTCONDITION: grid.Get(oldLoc) == null;
  */
 public Entity MoveTo(int x, int y)
 {
     if (Grid.IsValid(x, y))
     {
         Grid.Remove(Location);
         this.Location = new Location(x, y);
         return(Grid.Set(this, this.Location));
     }
     else
     {
         throw new Exception("Location " + x + ", " + y + "was invalid!");
     }
 }
Beispiel #3
0
        /* At each step, all CurrentMinions spawn new Minions in all the open spots adjacent to them.
         * These new RecruitMinions then replace the CurrentMinions, and CurrentMinions become Cells
         * All cells also update their color pattern to reflect distance traveled.
         */
        private void StepWithMinions()
        {
            foreach (BFSminion m in this.CurrentMinions)
            {
                foreach (Location l in m.masterAct())
                {
                    this.addMinion(l);
                }

                Location minionLoc = m.Location;
                BFScell  bCell     = new BFScell(Grid, minionLoc, this);
                Cells.Add(bCell);
            }

            foreach (BFScell b in Cells)
            {
                b.UpdateColors();
            }

            this.killMinions();
            this.Steps++;

            if (this.CurrentMinions.Count() == 0)
            {
                if (!(Grid.Get(Target) is BFSminion || Grid.Get(Target) is BFScell))
                {
                    Grid.Reset();
                    CurrentMinions.Clear();
                    RecruitMinions.Clear();
                    Cells.Clear();
                    Phase = 1;
                    Steps = 0;
                    return;
                }
                this.Phase++;
                Grid.Remove(Location);
                MoveTo(Target);
            }
        }
Beispiel #4
0
 /* Removes all references of this object so it can be garbage collected.
  *
  * PRECONDITION: grid and location are != null;
  * POSTCONDITION: grid.Get(location) == null;
  */
 public void RemoveSelfFromGrid()
 {
     Grid.Remove(Location);
     this.ForceGridChange(null);
 }