Exemple #1
0
 private void Attack(Unit other)
 {
     other.hp = other.hp - this.strength;
 }
Exemple #2
0
 public void SetOccupant(Unit u)
 {
     this.occupant = u;
 }
 private void deselectUnit()
 {
     selected.Deselect();
     selected = null;
     unitSelected = false;
     foreach (Square s in map.Squares())
     {
         s.SetDistanceFrom(999);
         s.SPath().Clear();
     }
 }
        // helper function for keyboard input on the map. Here to keep update method cleaner.
        private void MapInput()
        {
            if(input.KeyPressed(Keys.W) && (int)cursor.Y != 0)
            {
                cursor.Y -= 1;
            }
            if (input.KeyPressed(Keys.S) && (int)cursor.Y != map.Rows()-1)
            {
                cursor.Y += 1;
            }
            if (input.KeyPressed(Keys.A) && (int)cursor.X != 0)
            {
                cursor.X -= 1;
            }
            if (input.KeyPressed(Keys.D) && (int)cursor.X != map.Cols()-1)
            {
                cursor.X += 1;
            }

            if(unitSelected)
            {
                if (input.KeyPressed(Keys.RightShift))
                {
                    deselectUnit();
                }
                if(input.KeyPressed(Keys.Enter) && selected.InMoveRange().Contains(map.Square((int)cursor.Y, (int)cursor.X)))
                {
                    selected.MoveTo(map.Square((int)cursor.Y, (int)cursor.X));
                    deselectUnit();
                }
            }
            else
            {
                if (input.KeyPressed(Keys.Enter) && (map.Square((int)cursor.Y, (int)cursor.X).Occupant() != null))
                {
                    map.Square((int)cursor.Y, (int)cursor.X).Occupant().Select();
                    selected = map.Square((int)cursor.Y, (int)cursor.X).Occupant();
                    unitSelected = true;
                }

            }
        }
Exemple #5
0
 public void AddUnit(Unit unit)
 {
     units.Add(unit);
 }