示例#1
0
 public CityData adjustDisease(DiseaseColor color, int adjustment)
 {
     CityData result = new CityData(this);
     int newValue = result.diseases[(int)color] + adjustment;
     Debug.Assert(newValue <= 3 && newValue >= 0);
     result.diseases[(int)color] = newValue;
     return result;
 }
示例#2
0
文件: Map.cs 项目: hewner/pandemic
        //dangerous...modifies the Map
        public Map addDisease(City c, int num = 1)
        {
            Map          result = new Map(this);
            DiseaseColor color  = c.color;

            for (int i = 0; i < num; i++)
            {
                if (result.cities[c.cityNumber].disease(color) < 3)
                {
                    result.cities[c.cityNumber] = result.cities[c.cityNumber].adjustDisease(color, 1);

                    if (result.diseaseLevel(c, color) == 3)
                    {
                        result.aboutToOutbreak = new List <City>(result.aboutToOutbreak);
                        result.aboutToOutbreak.Add(c);
                    }

                    result.numInfectionsInCities++;
                }
                else
                {
                    //outbreak
                    List <City> outbreaks = new List <City>();
                    outbreaks.Add(c);
                    List <City> toEvaluate = new List <City>();
                    toEvaluate.AddRange(c.adjacent);
                    while (toEvaluate.Count != 0)
                    {
                        City current = toEvaluate.ElementAt(0);
                        toEvaluate.RemoveAt(0);
                        if (outbreaks.Contains(current))
                        {
                            continue;
                        }
                        if (result.cities[current.cityNumber].disease(color) < 3)
                        {
                            result.cities[current.cityNumber] = result.cities[current.cityNumber].adjustDisease(color, 1);
                        }
                        else
                        {
                            toEvaluate.AddRange(current.adjacent);
                            outbreaks.Add(current);
                        }

                        result.numInfectionsInCities++;

                        if (result.diseaseLevel(current, color) == 3)
                        {
                            result.aboutToOutbreak = new List <City>(result.aboutToOutbreak);
                            result.aboutToOutbreak.Add(current);
                        }
                    }
                    result._outbreakCount += outbreaks.Count;
                }
            }
            return(result);
        }
示例#3
0
 public City(string name, DiseaseColor color, int number, float x = 0, float y = 0)
 {
     this.name  = name;
     this.color = color;
     adjacent   = new List <City>();
     relativeX  = x;
     relativeY  = y;
     cityNumber = number;
 }
示例#4
0
文件: Map.cs 项目: hewner/pandemic
            public CityData adjustDisease(DiseaseColor color, int adjustment)
            {
                CityData result   = new CityData(this);
                int      newValue = result.diseases[(int)color] + adjustment;

                Debug.Assert(newValue <= 3 && newValue >= 0);
                result.diseases[(int)color] = newValue;
                return(result);
            }
示例#5
0
        public void CityConstructorTest()
        {
            string       name   = "New York";
            DiseaseColor color  = DiseaseColor.BLACK;
            City         target = new City(name, color, 1);

            Assert.AreEqual(name, target.name);
            Assert.AreEqual(color, target.color);
        }
示例#6
0
 public City(string name, DiseaseColor color, int number, float x = 0, float y = 0)
 {
     this.name = name;
     this.color = color;
     adjacent = new List<City>();
     relativeX = x;
     relativeY = y;
     cityNumber = number;
 }
示例#7
0
 public static Color toForeColor(DiseaseColor c)
 {
     switch (c)
     {
         case DiseaseColor.YELLOW:
             return Color.Black;
         default:
             return Color.White;
     }
 }
示例#8
0
        public static Color toForeColor(DiseaseColor c)
        {
            switch (c)
            {
            case DiseaseColor.YELLOW:
                return(Color.Black);

            default:
                return(Color.White);
            }
        }
示例#9
0
        public GameState cureDisease(DiseaseColor color)
        {
            GameState result = new GameState(this);

            result.curesFound = new bool[4];
            for (int i = 0; i < 4; i++)
            {
                result.curesFound[i] = curesFound[i];
            }
            result.curesFound[(int)color] = true;
            return(result);
        }
示例#10
0
文件: Map.cs 项目: hewner/pandemic
        public List <CureCityAction> getCureActionsFor(Player player)
        {
            List <CureCityAction> cures = new List <CureCityAction>();

            for (int i = 0; i < 4; i++)
            {
                DiseaseColor color = (DiseaseColor)i;
                if (diseaseLevel(player.position, color) > 0)
                {
                    cures.Add(new CureCityAction(player.position, color));
                }
            }
            return(cures);
        }
示例#11
0
文件: Map.cs 项目: hewner/pandemic
        public Map removeDisease(City city, DiseaseColor color)
        {
            Map result = new Map(this);

            result.cities[city.cityNumber] = result.cities[city.cityNumber].adjustDisease(color, -1);

            result.numInfectionsInCities--;

            if (result.aboutToOutbreak.Contains(city) && result.diseaseLevel(city, city.color) != 3)
            {
                result.aboutToOutbreak = new List <City>(result.aboutToOutbreak);
                result.aboutToOutbreak.Remove(city);
            }

            return(result);
        }
示例#12
0
文件: Map.cs 项目: hewner/pandemic
        public City addCity(String name, DiseaseColor color, float x = 0f, float y = 0f)
        {
            City city = new City(name, color, numCities, x, y);

            numCities++;

            CityData[] newData = new CityData[numCities];
            for (int i = 0; i < numCities - 1; i++)
            {
                newData[i] = cities[i];
            }
            cities = newData;
            cities[city.cityNumber] = new CityData();
            allCities.Add(city);
            return(city);
        }
示例#13
0
 public static Color toBackColor(DiseaseColor c)
 {
     switch (c)
     {
         case DiseaseColor.YELLOW:
             return Color.Yellow;
         case DiseaseColor.BLUE:
             return Color.DarkBlue;
         case DiseaseColor.ORANGE:
             return Color.DarkOrange;
         case DiseaseColor.BLACK:
             return Color.Black;
         default:
             return Color.PaleGoldenrod;
     }
 }
示例#14
0
        public static Color toBackColor(DiseaseColor c)
        {
            switch (c)
            {
            case DiseaseColor.YELLOW:
                return(Color.Yellow);

            case DiseaseColor.BLUE:
                return(Color.DarkBlue);

            case DiseaseColor.ORANGE:
                return(Color.DarkOrange);

            case DiseaseColor.BLACK:
                return(Color.Black);

            default:
                return(Color.PaleGoldenrod);
            }
        }
示例#15
0
        public GameState recalcBestCardHolder(GameState newGs, Player playerObj, DiseaseColor card)
        {
            int player = playerObj.playernum;

            if (bestCardHolder[(int)card].Key != player)
            {
                return(newGs);
            }


            int bestColor  = -1;
            int bestPlayer = -1;

            foreach (Player p in newGs.players)
            {
                int totalColor = 0;

                foreach (City c in p.cards)
                {
                    if (c.color == card)
                    {
                        totalColor++;
                    }
                    if (totalColor > bestColor)
                    {
                        bestColor  = totalColor;
                        bestPlayer = p.playernum;
                    }
                }
            }

            KeyValuePair <int, int>[] newbestCardHolder = new KeyValuePair <int, int> [4];
            for (int i = 0; i < 4; i++)
            {
                newbestCardHolder[i] = newGs.bestCardHolder[i];
            }
            newbestCardHolder[(int)card] = new KeyValuePair <int, int>(bestPlayer, bestColor);
            newGs.bestCardHolder         = newbestCardHolder;
            return(newGs);
        }
示例#16
0
文件: Map.cs 项目: hewner/pandemic
 public int diseaseLevel(City city, DiseaseColor color)
 {
     return(cities[city.cityNumber].disease(color));
 }
示例#17
0
        public City addCity(String name, DiseaseColor color, float x = 0f, float y = 0f)
        {            
            City city = new City(name, color, numCities, x, y);
            numCities++;

            CityData[] newData = new CityData[numCities];
            for (int i = 0; i < numCities - 1; i++)
            {
                newData[i] = cities[i];
            }
            cities = newData;
            cities[city.cityNumber] = new CityData();
            allCities.Add(city);
            return city;
        }
示例#18
0
 public CureCityAction(City position, DiseaseColor color)
 {
     this.position = position;
     this.color = color;
 }
示例#19
0
 public int disease(DiseaseColor color)
 {
     return diseases[(int)color];
 }
示例#20
0
 private CureDiseaseAction(DiseaseColor color)
 {
     this.color = color;
 }
示例#21
0
 public GameState cureDisease(DiseaseColor color)
 {
     GameState result = new GameState(this);
     result.curesFound = new bool[4];
     for (int i = 0; i < 4; i++)
     {
         result.curesFound[i] = curesFound[i];
     }
     result.curesFound[(int)color] = true;
     return result;
 }
示例#22
0
        public GameState recalcBestCardHolder(GameState newGs, Player playerObj, DiseaseColor card)
        {
            int player = playerObj.playernum;
            if (bestCardHolder[(int)card].Key != player)
            {
                return newGs;
            }
            

            int bestColor = -1;
            int bestPlayer = -1;
            foreach (Player p in newGs.players)
            {
                int totalColor = 0;
                
                foreach (City c in p.cards)
                {
                    if(c.color == card) {
                        totalColor++;
                    }
                    if (totalColor > bestColor)
                    {
                        bestColor = totalColor;
                        bestPlayer = p.playernum;
                    }
                }
            }

            KeyValuePair<int, int>[] newbestCardHolder = new KeyValuePair<int, int>[4];
            for (int i = 0; i < 4; i++)
            {
                newbestCardHolder[i] = newGs.bestCardHolder[i]; 
            }
            newbestCardHolder[(int)card] = new KeyValuePair<int, int>(bestPlayer, bestColor);
            newGs.bestCardHolder = newbestCardHolder;
            return newGs;
        }
示例#23
0
文件: Map.cs 项目: hewner/pandemic
 public int disease(DiseaseColor color)
 {
     return(diseases[(int)color]);
 }
示例#24
0
 public int diseaseLevel(City city, DiseaseColor color)
 {
     return cities[city.cityNumber].disease(color);
 }
示例#25
0
 private CureDiseaseAction(DiseaseColor color)
 {
     this.color = color;
 }
示例#26
0
 public CureCityAction(City position, DiseaseColor color)
 {
     this.position = position;
     this.color    = color;
 }
示例#27
0
        public Map removeDisease(City city, DiseaseColor color)
        {
            Map result = new Map(this);
            result.cities[city.cityNumber] = result.cities[city.cityNumber].adjustDisease(color, -1);

            result.numInfectionsInCities --;

            if (result.aboutToOutbreak.Contains(city) && result.diseaseLevel(city, city.color) != 3)
            {
                result.aboutToOutbreak = new List<City>(result.aboutToOutbreak);
                result.aboutToOutbreak.Remove(city);
            }

            return result;
        }