예제 #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]);
        }