/// <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; }
/// <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)); }
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; } }
/// <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; }
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; } }); }
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); }
/// <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; }
public CaseSelectedEventArgs(Case c) { _case = c; }
public override Student CreateStudent(Case position, Player player) { return new InfoStudent(position, player); }
public CaseDecorator(Case decoratedCase) : base(decoratedCase.X, decoratedCase.Y) { this.decoratedCase = decoratedCase; }
public abstract Teacher CreateTeacher(Case position, Player player);
/// <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]; }
/// <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); }
public CaseClickedEventArgs(Case c) { _case = c; }
public void RemoveField(Case field) { Population--; _requiredFood = _requiredFood * 2 / 3; fields.Remove(field); }
private void DrawUnits(Case c, CaseDrawer drawer) { DrawStudents(c.Students, drawer); DrawTeachers(c.Teachers, drawer); }
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); }
public IronCaseDecorator(Case decoratedCase) : base(decoratedCase) { }
/// <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; }
public override void Execute(Case selectedCase) { _control.SelectCase(selectedCase); }
public MakeStudentCommand(Case c) { _case = c; }
public Teacher(Case location, Player player) : base(location, player) { }
public override bool CanExectute(Case selectedCase) { return _game.IsVisible(selectedCase); }
public abstract bool CanExectute(Case selectedCase);
public MakeHeadCommand(Case c) { _case = c; }
public abstract void Execute(Case selectedCase);
public Head(Case position, Player player) : base(position, player) { }
public override Head CreateHead(Case position, Player player) { return new InfoHead(position, player); }
public InfoHead(Case location, Player player) : base(location, player) { }
public override Teacher CreateTeacher(Case position, Player player) { return new InfoTeacher(position, player); }
/// <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]); }