示例#1
0
文件: Unit.cs 项目: eske/INSAWars
 /// <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;
 }
示例#2
0
文件: Map.cs 项目: 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));
        }
示例#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;
     }
 }
示例#4
0
文件: City.cs 项目: eske/INSAWars
 /// <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;
 }
示例#5
0
文件: CaseView.cs 项目: eske/INSAWars
        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;
                }
            });
        }
示例#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);
        }
示例#7
0
文件: Game.cs 项目: eske/INSAWars
        /// <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;
        }
示例#8
0
 public CaseSelectedEventArgs(Case c)
 {
     _case = c;
 }
示例#9
0
 public override Student CreateStudent(Case position, Player player)
 {
     return new InfoStudent(position, player);
 }
示例#10
0
 public CaseDecorator(Case decoratedCase)
     : base(decoratedCase.X, decoratedCase.Y)
 {
     this.decoratedCase = decoratedCase;
 }
示例#11
0
 public abstract Teacher CreateTeacher(Case position, Player player);
示例#12
0
文件: Map.cs 项目: 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];
 }
示例#13
0
文件: Case.cs 项目: eske/INSAWars
 /// <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);
 }
示例#14
0
 public CaseClickedEventArgs(Case c)
 {
     _case = c;
 }
示例#15
0
 public CaseDecorator(Case decoratedCase)
     : base(decoratedCase.X, decoratedCase.Y)
 {
     this.decoratedCase = decoratedCase;
 }
示例#16
0
 public void RemoveField(Case field)
 {
     Population--;
     _requiredFood = _requiredFood * 2 / 3;
     fields.Remove(field);
 }
示例#17
0
 private void DrawUnits(Case c, CaseDrawer drawer)
 {
     DrawStudents(c.Students, drawer);
     DrawTeachers(c.Teachers, drawer);
 }
示例#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);
 }
示例#19
0
 public IronCaseDecorator(Case decoratedCase)
     : base(decoratedCase)
 {
 }
示例#20
0
文件: Map.cs 项目: 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;
        }
示例#21
0
 public override void Execute(Case selectedCase)
 {
     _control.SelectCase(selectedCase);
 }
示例#22
0
 public MakeStudentCommand(Case c)
 {
     _case = c;
 }
示例#23
0
文件: Teacher.cs 项目: eske/INSAWars
 public Teacher(Case location, Player player)
     : base(location, player)
 {
 }
示例#24
0
 public override bool CanExectute(Case selectedCase)
 {
     return _game.IsVisible(selectedCase);
 }
示例#25
0
 public abstract bool CanExectute(Case selectedCase);
示例#26
0
 public MakeHeadCommand(Case c)
 {
     _case = c;
 }
示例#27
0
 public abstract void Execute(Case selectedCase);
示例#28
0
文件: Head.cs 项目: eske/INSAWars
 public Head(Case position, Player player)
     : base(position, player)
 {
 }
示例#29
0
文件: City.cs 项目: eske/INSAWars
 public void RemoveField(Case field)
 {
     Population--;
     _requiredFood = _requiredFood * 2 / 3;
     fields.Remove(field);
 }
示例#30
0
 public override Head CreateHead(Case position, Player player)
 {
     return new InfoHead(position, player);
 }
示例#31
0
文件: InfoHead.cs 项目: eske/INSAWars
 public InfoHead(Case location, Player player)
     : base(location, player)
 {
 }
示例#32
0
 public override Teacher CreateTeacher(Case position, Player player)
 {
     return new InfoTeacher(position, player);
 }
示例#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]);
        }