Пример #1
0
        private int status_;            // 0 normal 1 sieging 2 defending

        public CArmy(List <CTroop> _troops, CCity _city, int _status)
        {
            this.troops_     = _troops;
            this.troopCount_ = this.troops_.Count;
            this.faction_    = this.troops_[0].Faction;
            this.city_       = _city;
            this.status_     = _status;
        }
Пример #2
0
        public void CreateGame(int _width, int _height)
        {
            if (_width > 0 && _height > 0)
            {
                this.gameTurn_ = 1;
                this.map_.CreateMap(_width, _height);

                int cityCount      = _width * _height;
                int factionCount   = (int)(cityCount * 0.75);
                int characterCount = cityCount * 5;

                this.cities_.Clear();
                this.factions_.Clear();
                this.characters_.Clear();

                for (int i = 0; i < factionCount; i++)
                {
                    CFaction faction = new CFaction(this.factions_.Count + 1, false);
                    this.factions_.Add(faction);

                    CCity city = new CCity(this.cities_.Count + 1, faction);
                    this.cities_.Add(city);
                    faction.AddCity(city);
                    this.map_.PlaceCity(city);

                    for (int j = 0; j < 5; j++)
                    {
                        CCharacter character = new CCharacter(this.characters_.Count + 1, faction, city);
                        character.RandomGeneration(this.traitDictionary_);
                        this.characters_.Add(character);
                        faction.AddCharacter(character);
                        city.AddCharacter(character);
                    }

                    // create big faction
                    // big faction has one more city
                    if (cityCount - this.cities_.Count > factionCount - this.factions_.Count)
                    {
                        city = new CCity(this.cities_.Count + 1, faction);
                        this.cities_.Add(city);
                        faction.AddCity(city);
                        this.map_.PlaceCity(city);

                        for (int j = 0; j < 5; j++)
                        {
                            CCharacter character = new CCharacter(this.characters_.Count + 1, faction, city);
                            character.RandomGeneration(this.traitDictionary_);
                            this.characters_.Add(character);
                            faction.AddCharacter(character);
                            city.AddCharacter(character);
                        }
                    }
                }
            }
        }
Пример #3
0
        public CCharacter(int _ID, CFaction _faction, CCity _city)
        {
            this.ID_      = _ID;
            this.faction_ = _faction;
            this.city_    = _city;

            this.traits_ = new List <CCharacterTrait>();

            this.hasMission_ = false;
            this.isDead_     = false;
        }
Пример #4
0
        public override String ToString()
        {
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < this.map_.Width; i++)
            {
                for (int j = 0; j < this.map_.Height; j++)
                {
                    CCity city = this.map_[i, j];
                    if (city != null)
                    {
                        sb.Append("|\t" + city.Faction.ID + "\t|");
                    }
                    else
                    {
                        sb.Append("|\tX\t|");
                    }
                }
                sb.AppendLine();
            }

            sb.AppendLine();

            //sb.Append("========== 回合 " + this.gameTurn_.ToString() + " ==========");
            //sb.AppendLine();

            //foreach (CCity city in this.cities_)
            //{
            //    sb.Append(city.ToString());
            //    sb.AppendLine();
            //}

            //for (int i = 0; i < this.characters_.Count; i++)
            //{
            //    CCharacter character = this.characters_[i];
            //    CFaction faction = character.Faction;
            //    CCharacter evaluator = faction.Characters[0];
            //    List<int> attributes = evaluator.Evaluate(character, this.traitDictionary_);
            //    sb.Append("势力:" + character.Faction.ID + "\t" + "统率:" + attributes[0] + "(" + character.LeaderShip + ")" + "\t" + "武力:" + attributes[1] + "(" + character.CombatSkill + ")" + "\t" + "智力:" + attributes[2] + "(" + character.Stratagem + ")" + "\t" + "政治:" + attributes[3] + "(" + character.Politics + ")" + "\t" + "相性:" + evaluator.Judgement(character, this.traitDictionary_));
            //    foreach (CCharacterTrait trait in character.Traits)
            //    {
            //        sb.Append("\t" + trait.ToString());
            //    }
            //    sb.Append("\n");
            //}

            return(sb.ToString());
        }
Пример #5
0
        public void AddCity(CCity _city)
        {
            bool canAddCity = true;

            foreach (CCity city in this.cities_)
            {
                if (city.Equals(_city))
                {
                    canAddCity = false;
                }
            }

            if (canAddCity)
            {
                this.cities_.Add(_city);
            }
        }
Пример #6
0
        public void PlaceCity(CCity _city)
        {
            List <Tuple <int, int> > emptyGrids         = new List <Tuple <int, int> >();
            List <Tuple <int, int> > emptyCandidates    = new List <Tuple <int, int> >();
            List <Tuple <int, int> > occupiedCandidates = new List <Tuple <int, int> >();

            for (int i = 0; i < this.width_; i++)
            {
                for (int j = 0; j < this.height_; j++)
                {
                    if (this.cities_[i, j] != null && this.cities_[i, j].Equals(_city))
                    {
                        return;
                    }
                    if (this.cities_[i, j] == null)
                    {
                        int sameFactionCount = 0;
                        if (i > 0)
                        {
                            if (this.cities_[i - 1, j] != null && this.cities_[i - 1, j].Faction.ID == _city.Faction.ID)
                            {
                                sameFactionCount++;
                            }
                        }
                        if (i < this.width_ - 1)
                        {
                            if (this.cities_[i + 1, j] != null && this.cities_[i + 1, j].Faction.ID == _city.Faction.ID)
                            {
                                sameFactionCount++;
                            }
                        }
                        if (j > 0)
                        {
                            if (this.cities_[i, j - 1] != null && this.cities_[i, j - 1].Faction.ID == _city.Faction.ID)
                            {
                                sameFactionCount++;
                            }
                        }
                        if (j < this.height_ - 1)
                        {
                            if (this.cities_[i, j + 1] != null && this.cities_[i, j + 1].Faction.ID == _city.Faction.ID)
                            {
                                sameFactionCount++;
                            }
                        }
                        if (sameFactionCount > 0)
                        {
                            emptyCandidates.Add(Tuple.Create(i, j));
                        }
                        else
                        {
                            emptyGrids.Add(Tuple.Create(i, j));
                        }
                    }
                    if (this.cities_[i, j] != null && this.cities_[i, j].Faction.ID != _city.Faction.ID)
                    {
                        int sameFactionCount = 0;
                        if (i > 0)
                        {
                            if (this.cities_[i - 1, j] != null && this.cities_[i - 1, j].Faction.ID == _city.Faction.ID)
                            {
                                sameFactionCount++;
                            }
                        }
                        if (i < this.width_ - 1)
                        {
                            if (this.cities_[i + 1, j] != null && this.cities_[i + 1, j].Faction.ID == _city.Faction.ID)
                            {
                                sameFactionCount++;
                            }
                        }
                        if (j > 0)
                        {
                            if (this.cities_[i, j - 1] != null && this.cities_[i, j - 1].Faction.ID == _city.Faction.ID)
                            {
                                sameFactionCount++;
                            }
                        }
                        if (j < this.height_ - 1)
                        {
                            if (this.cities_[i, j + 1] != null && this.cities_[i, j + 1].Faction.ID == _city.Faction.ID)
                            {
                                sameFactionCount++;
                            }
                        }
                        if (sameFactionCount > 0)
                        {
                            occupiedCandidates.Add(Tuple.Create(i, j));
                        }
                    }
                }
            }

            if (emptyGrids.Count == 0 && emptyCandidates.Count == 0 && occupiedCandidates.Count == 0)
            {
                return;
            }
            else if (emptyCandidates.Count > 0)
            {
                int index = rand_.Next(emptyCandidates.Count);
                Tuple <int, int> position = emptyCandidates[index];
                this.cities_[position.Item1, position.Item2] = _city;
                _city.MapCoordX = position.Item1;
                _city.MapCoordY = position.Item2;
            }
            else if (occupiedCandidates.Count > 0)
            {
                int index = rand_.Next(occupiedCandidates.Count);
                Tuple <int, int> position = occupiedCandidates[index];
                CCity            city     = this.cities_[position.Item1, position.Item2];
                this.cities_[position.Item1, position.Item2] = _city;
                _city.MapCoordX = position.Item1;
                _city.MapCoordY = position.Item2;
                PlaceCity(city);
            }
            else
            {
                int index = rand_.Next(emptyGrids.Count);
                Tuple <int, int> position = emptyGrids[index];
                this.cities_[position.Item1, position.Item2] = _city;
                _city.MapCoordX = position.Item1;
                _city.MapCoordY = position.Item2;
            }
        }
Пример #7
0
 public void RemoveCity(CCity _city)
 {
     this.cities_.Remove(_city);
 }