Example #1
0
 /// <summary>
 /// Creates a new unit at the given location for the given player.
 /// </summary>
 /// <param name="location"></param>
 /// <param name="player"></param>
 public Unit(Case location, Player player)
 {
     this._location = location;
     this._player = player;
     RemainingHitPoints = HitPoints;
     RemainingMovementPoints = MovementPoints;
     HasAttacked = false;
 }
Example #2
0
File: Map.cs Project: eske/INSAWars
        /// <summary>
        /// Creates a new map with the given cases array.
        /// </summary>
        /// <param name="cases">2D array of cases.</param>
        public Map(Case[,] cases)
        {
            this.cases = cases;
            startingPositions = new Stack<Case>();

            // Initialize the player positions (up to 4 players) at the corners of the map.
            startingPositions.Push(RandomCase(cases[0, 0], 5));
            startingPositions.Push(RandomCase(cases[Size - 1, Size - 1], 5));
            startingPositions.Push(RandomCase(cases[Size - 1, 0], 5));
            startingPositions.Push(RandomCase(cases[0, Size - 1], 5));
        }
Example #3
0
 private static Case GetDecorator(int decoratorIndex, Case decoratedCase)
 {
     switch (decoratorIndex)
     {
         case (int)Decorators.IRON:
             return new IronCaseDecorator(decoratedCase);
         case (int)Decorators.FOOD:
             return new FoodCaseDecorator(decoratedCase);
         default:
             return decoratedCase;
     }
 }
Example #4
0
 /// <summary>
 /// Creates a new city on a given case.
 /// </summary>
 /// <param name="position">The position of the city.</param>
 /// <param name="player">The player to whom the city belongs.</param>
 /// <param name="name">The name of the city (defined by the player).</param>
 public City(Case position, Player player, List<Case> territory)
 {
     this.position = position;
     this.player = player;
     this.fields = new List<Case>();
     this.fields.Add(this.position);
     this.pendingProductions = new List<Unit>();
     this.territory = territory;
     this.territory = territory.OrderBy(item => item.DistanceTo(position)).ToList();
     _population = 1;
     _food = 0;
     _iron = 0;
     _requiredFood = 10;
 }
Example #5
0
        public CaseView(Game g, Case c)
        {
            _game = g;
            _case = c;

            Units = c.Units.Select(u => new UnitView(u)).ToList();
            HasCity = c.HasCity;

            if (c.City != null)
            {
                City = new CityView(c.City);
            }

            OccupantName = (c.Occupant == null) ? "Free" : c.Occupant.Name.ToString();
            Food = c.Food;
            Iron = c.Iron;
            SelectedUnitCanMove = false;
            SelectedUnitCanBuildCity = false;
            SelectedUnitCanAttack = false;
            SelectedUnitView = null;

            c.PropertyChanged += new PropertyChangedEventHandler(delegate(object sender, PropertyChangedEventArgs args)
            {
                var updatedCase = (Case)sender;

                switch (args.PropertyName)
                {
                    case "Units":
                        Units = updatedCase.Units.Select(u => new UnitView(u)).ToList();

                        break;
                    case "HasCity":
                        HasCity = updatedCase.HasCity;
                        break;
                    case "Occupant":
                        OccupantName = (updatedCase.Occupant == null) ? "Free" : updatedCase.Occupant.Name.ToString();
                        break;
                    case "City":
                        // The new city could be null, we need to update only if it's not null
                        if (updatedCase.City != null)
                        {
                            City = new CityView(updatedCase.City);
                        }
                        break;
                    default:
                        break;
                }
            });
        }
Example #6
0
        public virtual Map generate(MapConfiguration config, int size)
        {
            PerlinMapWrapper perlinMap = new PerlinMapWrapper(size, config.octaves, config.persistance, config.terrains, config.decorators);
            Case[,] cases = new Case[size, size];
            List<Case> startingPositions = new List<Case>();

            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    int terrainIndex = perlinMap.GetTerrain(i, j);
                    int decoratorIndex = perlinMap.GetDecorator(i, j);
                    cases[i, j] = MapConfiguration.GetCase(terrainIndex, decoratorIndex, i, j);
                }
            }

            return new Map(cases);
        }
Example #7
0
        /// <summary>
        /// Tells wether or not the given case is visible by the current player.
        /// Note: this should not be in this class. Refactoring needed.
        /// </summary>
        /// <param name="c">Given case</param>
        /// <returns>True if the case is in the field of view of the current player, false otherwise.</returns>
        public bool IsVisible(Case c)
        {
            foreach (Case _c in map.TerritoryAround(c, 3))
            {
                if ((_c.HasCity || _c.IsUsed) && _c.Occupant == CurrentPlayer)
                {
                    return true;
                }
            }

            foreach (Case _c in map.TerritoryAround(c, 2))
            {
                if (_c.HasUnits && _c.Occupant == CurrentPlayer)
                {
                    return true;
                }
            }

            return false;
        }
Example #8
0
 public CaseSelectedEventArgs(Case c)
 {
     _case = c;
 }
Example #9
0
 public override Student CreateStudent(Case position, Player player)
 {
     return new InfoStudent(position, player);
 }
Example #10
0
 public CaseDecorator(Case decoratedCase)
     : base(decoratedCase.X, decoratedCase.Y)
 {
     this.decoratedCase = decoratedCase;
 }
Example #11
0
 public abstract Teacher CreateTeacher(Case position, Player player);
Example #12
0
File: Map.cs Project: eske/INSAWars
 /// <summary>
 /// Returns a random case in the given region.
 /// The region is delimited by a center position a maximum distance to this position.
 /// </summary>
 /// <param name="position">Center position.</param>
 /// <param name="distance">Maximum distance.</param>
 /// <returns></returns>
 private Case RandomCase(Case position, int distance)
 {
     List<Case> cases = TerritoryAround(position, distance);
     return cases[Game.random.Next() % cases.Count];
 }
Example #13
0
 /// <summary>
 /// Returns the distance to the given case.
 /// </summary>
 /// <param name="destination"></param>
 /// <returns></returns>
 public int DistanceTo(Case destination)
 {
     return Math.Abs(destination.X - X) + Math.Abs(destination.Y - Y);
 }
Example #14
0
 public CaseClickedEventArgs(Case c)
 {
     _case = c;
 }
Example #15
0
 public CaseDecorator(Case decoratedCase)
     : base(decoratedCase.X, decoratedCase.Y)
 {
     this.decoratedCase = decoratedCase;
 }
Example #16
0
 public void RemoveField(Case field)
 {
     Population--;
     _requiredFood = _requiredFood * 2 / 3;
     fields.Remove(field);
 }
Example #17
0
 private void DrawUnits(Case c, CaseDrawer drawer)
 {
     DrawStudents(c.Students, drawer);
     DrawTeachers(c.Teachers, drawer);
 }
Example #18
0
 private void DrawCaseContent(DrawingContext context, Case c, Tuple<int, int> origin)
 {
     var drawer = new CaseDrawer(context, origin);
     DrawFood(c.Food, drawer);
     DrawIron(c.Iron, drawer);
     DrawUnits(c, drawer);
 }
Example #19
0
 public IronCaseDecorator(Case decoratedCase)
     : base(decoratedCase)
 {
 }
Example #20
0
File: Map.cs Project: eske/INSAWars
        /// <summary>
        /// Gives the cases around the given position, at the given maximum distance.
        /// </summary>
        /// <param name="position">Center position.</param>
        /// <param name="distance">Maximum distance from the center position.</param>
        /// <returns></returns>
        public List<Case> TerritoryAround(Case position, int distance)
        {
            List<Case> territory = new List<Case>();

            for (int x = Math.Max(0, position.X - distance); x <= Math.Min(Size - 1, position.X + distance); x++)
            {
                for (int y = Math.Max(0, position.Y - distance); y <= Math.Min(Size - 1, position.Y + distance); y++)
                {
                    Case c = GetCaseAt(x, y);

                    if (!(c is Water))
                    {
                        territory.Add(GetCaseAt(x, y));
                    }
                }
            }

            return territory;
        }
Example #21
0
 public override void Execute(Case selectedCase)
 {
     _control.SelectCase(selectedCase);
 }
Example #22
0
 public MakeStudentCommand(Case c)
 {
     _case = c;
 }
Example #23
0
 public Teacher(Case location, Player player)
     : base(location, player)
 {
 }
Example #24
0
 public override bool CanExectute(Case selectedCase)
 {
     return _game.IsVisible(selectedCase);
 }
Example #25
0
 public abstract bool CanExectute(Case selectedCase);
Example #26
0
 public MakeHeadCommand(Case c)
 {
     _case = c;
 }
Example #27
0
 public abstract void Execute(Case selectedCase);
Example #28
0
 public Head(Case position, Player player)
     : base(position, player)
 {
 }
Example #29
0
 public void RemoveField(Case field)
 {
     Population--;
     _requiredFood = _requiredFood * 2 / 3;
     fields.Remove(field);
 }
Example #30
0
 public override Head CreateHead(Case position, Player player)
 {
     return new InfoHead(position, player);
 }
Example #31
0
 public InfoHead(Case location, Player player)
     : base(location, player)
 {
 }
Example #32
0
 public override Teacher CreateTeacher(Case position, Player player)
 {
     return new InfoTeacher(position, player);
 }
Example #33
0
        /// <summary>
        /// Returns a random case in the given region.
        /// The region is delimited by a center position a maximum distance to this position.
        /// </summary>
        /// <param name="position">Center position.</param>
        /// <param name="distance">Maximum distance.</param>
        /// <returns></returns>
        private Case RandomCase(Case position, int distance)
        {
            List <Case> cases = TerritoryAround(position, distance);

            return(cases[Game.random.Next() % cases.Count]);
        }