From 497fd500d912fe4ddcb4908f9f2f8b1aaadd4238 Mon Sep 17 00:00:00 2001 From: Markus Birth Date: Fri, 30 Jan 2009 21:57:37 +0100 Subject: [PATCH] + added properties instead of class variables x removed Typliste (integrated in Einwohner) --- Einwohner.cs | 58 +++++++++++++++++++++++++++++------------------- Output_CLI.cs | 4 ++-- Output_GUI.cs | 19 +++++++++------- Program.cs | 14 +++++++++--- Settings.cs | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++- Spielfigur.cs | 29 +++++++++++++----------- Typliste.cs | 7 ------ Vampir.cs | 32 +++++++++++++++------------ vampi.csproj | 1 - 9 files changed, 153 insertions(+), 72 deletions(-) delete mode 100644 Typliste.cs diff --git a/Einwohner.cs b/Einwohner.cs index f87518d..fe77e88 100644 --- a/Einwohner.cs +++ b/Einwohner.cs @@ -3,40 +3,49 @@ using System; namespace vampi { class Einwohner : Spielfigur { - + public const int F_SEX = 10; + public const int SEX_MALE = 1; + public const int SEX_FEMALE = 2; + + public const int F_INFECTED = 11; + private static int count = 0; public static int Count { get { return Einwohner.count; } } - private bool infected = false; public bool Infected { - get { return this.infected; } + get { return (this.props[F_INFECTED] != 0); } } - public static int legalSexAge = Settings.humanLegalSexAge; - public static int vampireConversionRate = Settings.humanVampireConversionPercent; - public bool ismale; + public string name; public Einwohner(Spielfeld sfeld) : base(sfeld) { - this.typ = Typliste.EINWOHNER; - this.maxAge = Settings.humanMaxAge; - this.age = Program.random.Next(0, Settings.humanMaxInitAge); + this.props[F_TYPE] = TYPE_HUMAN; + this.props[F_MAXAGE] = Settings.humanMaxAge; + this.props[F_AGE] = Program.random.Next(0, Settings.humanMaxInitAge); Einwohner.count++; - if (Program.random.Next(0, 100) < 85) this.ismale = true; else this.ismale = false; + this.props[F_SEX] = (Program.random.Next(0, 100) < 85)?SEX_MALE:SEX_FEMALE; + if (this.props[F_SEX] == SEX_MALE) { + this.name = Settings.namesMale[Program.random.Next(0, Settings.namesMale.GetLength(0))]; + } else { + this.name = Settings.namesFemale[Program.random.Next(0, Settings.namesFemale.GetLength(0))]; + } + // Console.WriteLine(this.name+" is born! (" + ((this.ismale)?"m":"f") + ")"); } public void infect() { - if (this.infected) - return; - this.infected = true; - if (this.age < this.maxAge - Settings.humanInfectedMaxAge) this.age = this.maxAge - Settings.humanInfectedMaxAge; + if (this.Infected) + return; + // Console.WriteLine(this.name+" got infected!"); + this.props[F_INFECTED] = 1; + if (this.props[F_AGE] < this.props[F_MAXAGE] - Settings.humanInfectedMaxAge) this.props[F_AGE] = this.props[F_MAXAGE] - Settings.humanInfectedMaxAge; } public override void die() { Einwohner.count--; - if (this.infected) { + if (this.Infected) { int rvalue = Program.random.Next(0, 100); - if (rvalue <= Einwohner.vampireConversionRate) { + if (rvalue <= Settings.humanVampireConversionPercent) { new Vampir(this.sfeld); return; } @@ -46,8 +55,11 @@ namespace vampi public override void runStep() { base.runStep(); - - if (this.infected && !Settings.humanInfectedCanReproduceWithNormal) return; + this.tryMate(); + } + + protected void tryMate() { + if (this.Infected && !Settings.humanInfectedCanReproduceWithNormal) return; // search for constraints (empty field, partner to mate > 10 yrs) Spielfeld birthplace = null; @@ -55,10 +67,11 @@ namespace vampi for (int i = 1; i <= 8; i++) { Spielfeld neighbor = this.sfeld.getNachbarfeld(i); if (neighbor != null && neighbor.Sfigur != null) { - if (neighbor.Sfigur.Typ == Typliste.EINWOHNER) { - if (neighbor.Sfigur.Age >= Einwohner.legalSexAge && (Settings.humanNormalCanReproduceWithInfected || !((Einwohner)neighbor.Sfigur).Infected)) { - if (((Einwohner)neighbor.Sfigur).ismale != this.ismale) - mateFound = true; + if (neighbor.Sfigur.props[F_TYPE] == TYPE_HUMAN) { + if (neighbor.Sfigur.Age >= Settings.humanLegalSexAge && (Settings.humanNormalCanReproduceWithInfected || !((Einwohner)neighbor.Sfigur).Infected)) { + if (neighbor.Sfigur.props[F_SEX] != this.props[F_SEX]) { + mateFound = true; + } } } } else if (neighbor != null && neighbor.Sfigur == null) { @@ -69,7 +82,6 @@ namespace vampi if (mateFound && birthplace != null) { new Einwohner(birthplace); } - } } }//namespace diff --git a/Output_CLI.cs b/Output_CLI.cs index 79d1029..3289454 100644 --- a/Output_CLI.cs +++ b/Output_CLI.cs @@ -81,13 +81,13 @@ namespace vampi { Console.BackgroundColor = Settings.colorEmpty; else { //Spielfeld besetzt switch (sf.Typ) { - case Typliste.EINWOHNER: + case Spielfigur.TYPE_HUMAN: if (((Einwohner)sf).Infected) Console.BackgroundColor = Settings.colorHumanInfected; else Console.BackgroundColor = Settings.colorHuman; break; - case Typliste.VAMPIR: + case Spielfigur.TYPE_VAMPIRE: Console.BackgroundColor = Settings.colorVampire; break; }//switch diff --git a/Output_GUI.cs b/Output_GUI.cs index 24da230..4bffb6d 100644 --- a/Output_GUI.cs +++ b/Output_GUI.cs @@ -115,13 +115,16 @@ namespace vampi { if (sf == null) c = Settings.guiColorEmpty; //Spielfeld leer else { //Spielfeld besetzt switch (sf.Typ) { - case Typliste.EINWOHNER: + case Spielfigur.TYPE_HUMAN: if (((Einwohner)sf).Infected) c = getGradient(Settings.guiColorHumanInfected, 100-(double)(sf.Age-Settings.humanMaxAge+Settings.humanInfectedMaxAge)*100/(double)Settings.humanInfectedMaxAge); - else - c = getGradient(Settings.guiColorHuman, 100-(double)sf.Age*100/(double)Settings.humanMaxAge); + else + if (sf.props[Einwohner.F_SEX] == Einwohner.SEX_MALE) + c = getGradient(Settings.guiColorHumanMale, 100-(double)sf.Age*100/(double)Settings.humanMaxAge); + else + c = getGradient(Settings.guiColorHumanFemale, 100-(double)sf.Age*100/(double)Settings.humanMaxAge); break; - case Typliste.VAMPIR: + case Spielfigur.TYPE_VAMPIRE: c = getGradient(Settings.guiColorVampire, 100-(double)sf.Age*100/(double)Settings.vampireMaxAge); break; } @@ -144,11 +147,11 @@ namespace vampi { int Ecount = Einwohner.Count; // sflaeche.countTypeOccurrences(Typliste.EINWOHNER); int Vcount = Vampir.Count; // sflaeche.countTypeOccurrences(Typliste.VAMPIR); g.DrawString(String.Format("Step: {0:D5}", Program.AnzSimDone), Settings.guiFont, Settings.guiFontBrush, 5, 0); - g.DrawString(String.Format("T{0:N} = {1:D}/sec", Program.lastCalcTime+Program.lastStatsTime, (int)Math.Floor(1000/(Program.lastCalcTime+Program.lastStatsTime))), Settings.guiFont, Settings.guiFontBrush, 100, 0); + g.DrawString(String.Format("T{0:N} = {1:D}/sec", Program.lastOverallTime, (int)Math.Floor(1000/(Program.lastOverallTime))), Settings.guiFont, Settings.guiFontBrush, 100, 0); g.DrawString(String.Format("C{0:N} D{1:N}", Program.lastCalcTime, Program.lastStatsTime), Settings.guiFont, Settings.guiFontBrush, 200, 0); - g.DrawString(String.Format(String.Format("Einwohner: {0:D} / Vampire: {1:D}", Ecount, Vcount), Program.AnzSimDone), Settings.guiFont, Settings.guiFontBrush, 5, 1*lineSpc); - g.DrawString(String.Format(String.Format("Verhältnis Vampire/Einwohner = 1/{0:N5}", (double)Ecount / Vcount), Program.AnzSimDone), Settings.guiFont, Settings.guiFontBrush, 5, 2*lineSpc); - g.DrawString(String.Format(String.Format("Bedeckung: {0:N5} %", (double)(Ecount + Vcount) / (Settings.size*Settings.size) * 100), Program.AnzSimDone), Settings.guiFont, Settings.guiFontBrush, 5, 3*lineSpc); + g.DrawString(String.Format(String.Format("Humans: {0:D} / Vampires: {1:D}", Ecount, Vcount), Program.AnzSimDone), Settings.guiFont, Settings.guiFontBrush, 5, 1*lineSpc); + g.DrawString(String.Format(String.Format("V/H Ratio = 1/{0:N5}", (double)Ecount / Vcount), Program.AnzSimDone), Settings.guiFont, Settings.guiFontBrush, 5, 2*lineSpc); + g.DrawString(String.Format(String.Format("Coverage: {0:N5} %", (double)(Ecount + Vcount) / (Settings.size*Settings.size) * 100), Program.AnzSimDone), Settings.guiFont, Settings.guiFontBrush, 5, 3*lineSpc); g.Dispose(); g = Graphics.FromHwnd(f.Handle); g.DrawImageUnscaled(this.stats, 0, 0); diff --git a/Program.cs b/Program.cs index 9dc0b6c..d76c433 100644 --- a/Program.cs +++ b/Program.cs @@ -15,18 +15,26 @@ namespace vampi { public static Random random = new Random(); public static Spielflaeche sflaeche = new Spielflaeche(Settings.size, Settings.coveragePercent, Settings.vampireRatio); public static double lastCalcTime = 0; - public static double lastStatsTime = 0; + public static double lastStatsTime = 0; + public static double lastOverallTime = 0; static void Main(string[] args) { Output output = new Output_GUI(); Stopwatch sw = new Stopwatch(); + Stopwatch sw2 = new Stopwatch(); - for (anz_sim_done=0; anz_sim_done < anz_sim; anz_sim_done++) { + for (anz_sim_done=0; anz_sim_done < anz_sim; anz_sim_done++) { if (anz_sim_done % Settings.drawEveryNthStep == 0) { + sw2.Stop(); + Program.lastOverallTime = sw2.Elapsed.TotalMilliseconds/Settings.drawEveryNthStep; + sw2.Reset(); + sw2.Start(); sw.Reset(); sw.Start(); + Program.lastCalcTime /= Settings.drawEveryNthStep; output.doOutput(); sw.Stop(); + Program.lastCalcTime = 0; Program.lastStatsTime = sw.Elapsed.TotalMilliseconds; } if (output.requestAbort) break; @@ -34,7 +42,7 @@ namespace vampi { sw.Start(); sflaeche.simulateStep(); sw.Stop(); - Program.lastCalcTime = sw.Elapsed.TotalMilliseconds; + Program.lastCalcTime += sw.Elapsed.TotalMilliseconds; } }//Main }//class diff --git a/Settings.cs b/Settings.cs index 674cd0c..a2429ed 100644 --- a/Settings.cs +++ b/Settings.cs @@ -17,6 +17,8 @@ namespace vampi { public static Color guiColorHumanInfected = Color.DarkMagenta; public static Color guiColorVampire = Color.Red; */ public static Color[] guiColorHuman = {Color.FromArgb(0, 60, 0), Color.LimeGreen}; + public static Color[] guiColorHumanFemale = {Color.FromArgb(60, 60, 0), Color.Yellow}; + public static Color[] guiColorHumanMale = {Color.FromArgb(0, 60, 0), Color.LimeGreen}; public static Color[] guiColorHumanInfected = {Color.FromArgb(60, 0, 60), Color.DarkMagenta}; public static Color[] guiColorVampire = {Color.FromArgb(60, 0, 0), Color.Red}; public static Color guiColorEmpty = Color.Wheat; @@ -39,6 +41,63 @@ namespace vampi { public const int vampireIncreaseFillPerBite = 1; public const bool vampireInfectOnlyOneHuman = false; public const bool vampireInfectOneOrMoreHumans = false; - + + public static string[] namesMale = { + "Aaron", "Achim", "Adalger", "Adam", "Adelar", "Adrian", "Aginulf", "Agomar", "Alain", "Alarich", "Alban", "Albero", "Albert", "Alderich", "Aldo", "Alexander", "Alger", "Ali", "Allen", "Amon", "Andrew", "Antoine", "Arnaud", "Arnie", "Art", "Arwed", "Arve", "Aquarius", + "Benny", "Beowulf", "Billy", "Bobby", "Bela", "Binti", "Biko", "Bastian", "Brian", "Boris", "Bero", "Bert", "Bertil", "Bernard", "Berenger", "Benoit", "Bernd", "Baldur", "Baptist", "Baldwin", "Basil", "Björn", "Bohumil", "Brad", "Burkhard", "Brix", + "Carl", "Carlo", "Cedric", "Claude", "Claus", "Cletus", "Cestos", "Colbert", "Coleman", "Cole", "Chris", "Cajetan", "Candid", "Cassian", "Castor", "Cecil", "Clark", "Cliff", "Clive", "Clemens", "Conrad", "Cosmas", "Curt", "Cyrus", + "Damian", "Dan", "Darwin", "Dave", "David", "Denis", "Derek", "Dilbert", "Dionys", "Don", "Duras", "Diablo", "Domenic", "Dorian", "Dale", "Didier", "Diego", "Dieter", "Dietrich", "Dietwald", "Dino", "Dirk", "Dismas", "Dominik", "Donald", "Doug", "Drawo", "Duncan", + "Edmond", "Eliah", "Enki", "Eric", "Etienne", "Emmerich", "Einstein", "Encke", "Earl", "Eberhard", "Ecki", "Eddi", "Edmond", "Einar", "Elias", "Elmar", "Elmo", "Emile", "Ephraim", "Erik", "Erasmus", "Ernst", "Erwin", "Esra", "Esteban", "Eugen", "Ezzo", + "Fabrice", "Felix", "Fjodor", "Francis", "Frederic", "Fritz", "Fredegar", "Furtwängler", "Florin", "Frido", "Fabian", "Falko", "Farold", "Fides", "Flodoard", "Florian", "Franz", "Fridolin", "Friedrich", "Frowin", "Fritz", + "Gaston", "Gene", "Georges", "Gerard", "Gert", "Gilbert", "Gilles", "Gino", "Guy", "Guilio", "Ghiberti", "Gismo", "Guntbert", "Gerrik", "Ged", "Gordy", + "Heiko", "Henner", "Henri", "Hubert", "Hask", "Herluf", "Hilbert", "Han Solo", "Harrison", "Herodot", "Hinrich", "Halfred", + "Ian", "Igor", "Ibert", "Immanuel", "Indy", "Ingres", "Ingram", "Ingvar", "Ignatius", "Irving", "Ivan", "Ivar", "Isbert", "Ismael", + "Jacob", "Jake", "Jamie", "Jan", "Jason", "Jay", "Jean", "Jeannot", "Jeff", "Jeffrey", "Jeremy", "Jerome", "Jimmy", "Joel", "Jon", "Jost", "Jules", "Julien", "Jervis", "Johann", "Jodokus", + "Kolya", "Kor", "Kras", "Kurn", "Kelkad", "Kenny", "Kant", "Korbinian", "Kai", "Kalle", "Karl", "Kaspar", "Kevin", "Klaas", " Klaus", "Konrad", "Kurd", "Kurt", + "Larry", "Laurent", "Lennart", "Leon", "Leonard", "Lionel", "Louis", "Luc", "Lucien", "Linné", "Lohengrin", "Leif", "Leslie", "Lewis", "Lorenz", "Loriot", + "Malcolm", "Marc", "Marcel", "Marco", "Martial", "Marvin", "Maurice", "Maxime", "Michel", "Mike", "Miles", "Momo", "Mordok", "Morten", "Manuzai", "Milio", "Meelo", "Maurice", "Machiavelli", "Micha", + "Nicolas", "Nives", "Noel", "Norbert", "Nathan", "Nahum", "Nithard", "Nick", "Nivard", "Nando", + "Odo", "Olivier", "Odin", "Oliver", "Orion", "Orlando", "Ojoro", "Orki", "Oruio", "Otker", "Otthermann", + "Pascal", "Paul", "Pete", "Peter", "Philip", "Pierre", "Pelle", "Pilo", "Pindo", "Pisto", "Poulo", + "Quark", "Quasimodo", "Quirin", "Quintus", "Quantus", "Questo", "Quasto", "Quentin", "Quentino", + "Raoul", "Remi", "Rom", "Romeo", "Romain", "Ronny", "Rudy", "Ruprecht", "Raimo", "Rudenz", "Reinold", "Rolando", "Rowland", "Rudolf", "Rodolopho", "Ray", "Raymond", + "Sammy", "Scotty", "Severin", "Simon", "Sisko", "Spock", "Steve", "Stuart", "Sven", "Sylvain", "Serge", "Sheyel", "Stephen", "Soren", "Sordes", "Strubbel", + "Tassilo", "Theo", "Thibaut", "Tilman", "Titi", "Toby", "Tom", "Tristan", "Thomas", "Tyus", "Telly", "Thilo", + "Urban", "Urs", "Udo", + "Vince", "Vincenzo", "Vincent", "Valentin", "Vaclaw", "Victor", "Vivien", "Volker", "Volkhart", "Volkmar", "Vitus", "Vittorio", + "Willi", "Wolfgang", "Worf", "Wallenstein", "Walter", "Welf", "Wennemar", "Werther", "Wigand", "Winfried", "Wolf", "Wotan", + "Xenophanes", "Xenopoulos", "Xerxes", "Xaver", "Xavier", + "Yannick", "Yvan", "Yves", "Yvon", "Yfri", "Yorick", "Yorck", "Yul", "Yvo", + "Zenji", "Zorg", "Zeltan", "Zacharias", "Zoltan", "Zyprian" + }; + public static string[] namesFemale = { + "Adalie", "Adda", "Adeline", "Adelita", "Agnes", "Agneta", "Alexis", "Alice", "Aline", "Allison", "Almud", "Amanda", "Amelia", "Amy", "Andrea", "Anemone", "Angelica", "Anita", "Anja", "Annabel", "Anne", "Annette", "Anouk", "Antonia", "Ariana", "Aude", "Audrey", "Auguste", "Aurora", "Ayla", "Alouette", "Alyssa", "April", "Arlene", "Askama", "Auriga", + "Babette", "Baltrun", "Barbara", "Belannah", "Belinda", " Bernadette", "Bertha", "Betty", "Bibi", "Biggi", "Birte", "Blanche", "Britta", "Beekje", "Bilba", "Bonnie", "Beate", "Bovista", + "Camille", "Carine", "Carla", "Carmen", "Carola", "Caroline", "Cathy", "Celia", "Chantal", "Charlene", "Chloe", "Christina", "Cindy", "Claire", "Clemence", "Coco", "Colette", "Connie", "Corinne", "Cora", "Cynthia", "Carmina", "Columba", + "Dalia", "Dana", "Dani", "Danielle", "Darla", "Delphine", "Denise", "Desiree", "Dette", "Dina", "Doris", "Dunja", "Djalao", "Drawida", "Debra", "Dyonisia", "Domenica", "Dora", "Dalila", + "Edita", "Edith", "Eliane", "Elisa", "Elli", "Elsa", "Emilie", "Emma", "Erika", "Esmeralda", "Estelle", "Ethel", "Eve", "Euklida", "Eva Maria", "Elina", "Emmanuelle", "Erdtrud", "Emmi", "Ester", "Evita", + "Fafa", "Fanette", "Fatima", "Felicie", "Fiona", "Flora", "Florence", "Franzi", "Frauke", "Friederike", "Fia", "Frizzi", "Florina", "Fenjala", "Froane", "Fabienne", "Francine", + "Gerda", "Gesine", "Ginger", "Grausi", "Grenda", "Grilka", "Griselda", "Gundela", "Gwen", "Gerlis", "Gaia", "Gallia", "Grenouille", "Gea", "Gabrielle", "Gisela", + "Hannah", "Hannelore", "Helena", "Helga", "Heloise", "Henna", "Henrike", "Habima", "Haifa", "Halma", "Hero", "Huberta", "Hilaria", "Helke", "Henrietta", "Hidda", + "Ines", "Ingeborg", "Irene", "Iris", "Irma", "Isabelle", "Isolde", "Ilma", "Imperia", "Inka", "Irina", "Imura", "Inken", "Inka", "Ilka", "Ishtar", + "Janet", "Janina", "Jeanne", "Jeannie", "Jessica", "Jill", "Joanna", "Josette", "Julia", "Julianne", "Juliette", "Jellina", "Jovana", "Juliana", "June", "Jennifer", "Jordana", + "Kassandra", "Katja", "Kelly", "Kes", "Kim", "Kira", "Kordia", "Kendra", "Killy", "Kissy", "Kate", "Kathryn", "Karin", "Karla", "Kulka", + "Lara", "Laura", "Lea", "Leila", "Lili", "Linda", "Lis", "Lucia", "Lursa", "Lydie", "Lale", "Lisbeth", "Larissa", "Lelia", "Lidia", "Lora", "Loretta", + "Madeleine", "Mafalda", "Maia", "Makeba", "Mandy", "Manon", "Manuela", "Mara", "Marcelle", "Margo", "Marie", "Martine", "Mary", "Maryse", "Mathilda", "Meg", "Melusine", "Merita", "Micaela", "Michelle", "Minerva", "Minette", "Miriam", "Monika", "Marketta", "Molina", "Miranda", "Marthe", "Mariana", "Melissa", "Mona", "Mila", "Mizzi", "Molly", "Morgane", + "Nadege", "Nadine", "Naomi", "Nathalie", "Nina", "Noelle", "Norina", "Nilly", "Nadia", "Norma", "Nuptia", "Nadura", + "Odette", "Oona", "Oceana", "Odessa", "Ombra", "Ophra", "Ophelia", + "Paloma", "Pascale", "Pauline", "Pam", "Phila", "Paola", "Pelagia", "Punta", "Paula", "Perdita", "Pella", "Petra", "Panja", "Pasta", "Petula", + "Quantana", "Quentina", "Quirina", "Quanta", "Quesera", "Quarka", "Questa", "Quilla", + "Rachel", "Rebecca", "Robyn", "Roselyne", "Ruth", "Rahel", "Ricarda", "Raya", "Rea", "Renata", "Rasta", + "Sabine", "Sally", "Samantha", "Sandra", "Sandy", "Sarah", "Sarana", "Sieglinde", "Sina", "Solange", "Sophie", "Stacy", "Sibylle", "Sylvie", "Salina", "Seltar", "Setha", "Suleika", "Sunna", "Sasa", "Silvana", "Sonja", "Sinja", "Siska", "Sirta", "Sujin", + "Tabita", "Tamara", "Tanja", "Terri", "Tiffany", "Tilly", "Tina", "Tonja", "Troi", "Taina", "Tassila", "Thornia", "Tildy", "Tanita", + "Undine", "Ursula", "Ulla", + "Vekma", "Veronique", "Viviane", "Valentina", "Vilma", "Valentine", "Valerie", "Vanessa", "Vivien", + "Wanda", "Wendy", "Wilma", "Wally", "Willa", "Wismut", "Wulfila", "Wilgund", "Wilhelmina", "Wilrun", "Winny", "Wisgard", "Wiska", "Witta", + "Xenia", "Xanthia", "Xana", "Xanthippe", "Xandra", + "Yolande", "Yvette", "Yerba", "Yvonne", + "Zoe", "Zenja", "Zancara", "Zarah" + }; + } } diff --git a/Spielfigur.cs b/Spielfigur.cs index a4e8015..6343019 100644 --- a/Spielfigur.cs +++ b/Spielfigur.cs @@ -3,31 +3,34 @@ using System.Collections; namespace vampi { - public abstract class Spielfigur { + public abstract class Spielfigur { + public const int F_TYPE = 0; + public const int TYPE_HUMAN = 1; + public const int TYPE_VAMPIRE = 2; + + public const int F_AGE = 1; + public const int F_MAXAGE = 2; + public int[] props = new int[20]; + protected Spielfeld sfeld; - protected int typ; - protected int maxAge = 80; - protected int age = -1; public int Age { - get { return this.age; } + get { return this.props[F_AGE]; } } public int Typ { - get { return this.typ; } + get { return this.props[F_TYPE]; } } - public Spielfigur(Spielfeld sfeld) { + public Spielfigur(Spielfeld sfeld) { sfeld.Sfigur = this; - this.sfeld = sfeld; + this.sfeld = sfeld; } public virtual void runStep() { - if (this.age != -1) { - this.age++; - if (this.age >= this.maxAge) { - this.die(); - } + this.props[F_AGE]++; + if (this.props[F_AGE] >= this.props[F_MAXAGE]) { + this.die(); } } diff --git a/Typliste.cs b/Typliste.cs deleted file mode 100644 index 97ce6d3..0000000 --- a/Typliste.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace vampi -{ - public abstract class Typliste { - public const int EINWOHNER = 1; - public const int VAMPIR = 2; - } -} diff --git a/Vampir.cs b/Vampir.cs index ef13d29..9d5365b 100644 --- a/Vampir.cs +++ b/Vampir.cs @@ -3,18 +3,19 @@ using System; namespace vampi { class Vampir : Spielfigur { - + public const int F_FILLER = 10; + private static int count = 0; public static int Count { get { return Vampir.count; } } - private int filler = Settings.vampireInitialFill; public Vampir(Spielfeld sfeld) : base(sfeld) { - this.typ = Typliste.VAMPIR; - this.maxAge = Settings.vampireMaxAge; - this.age = Program.random.Next(0, Settings.vampireMaxInitAge); + this.props[F_TYPE] = TYPE_VAMPIRE; + this.props[F_MAXAGE] = Settings.vampireMaxAge; + this.props[F_AGE] = Program.random.Next(0, Settings.vampireMaxInitAge); + this.props[F_FILLER] = Settings.vampireInitialFill; Vampir.count++; } @@ -25,23 +26,26 @@ namespace vampi public override void runStep() { base.runStep(); - this.filler -= Settings.vampireDecreaseFillPerStep; - if (this.filler <= 0) { + this.props[F_FILLER] -= Settings.vampireDecreaseFillPerStep; + if (this.props[F_FILLER] <= 0) { this.die(); return; - } - + } + this.tryInfect(); + } // runStep() + + protected void tryInfect() { // count humans around me int humans = 0; for (int i = 1; i <= 8; i++) { Spielfeld neighbor = this.sfeld.getNachbarfeld(i); if (neighbor != null && neighbor.Sfigur != null) { - if (neighbor.Sfigur.Typ == Typliste.EINWOHNER) { + if (neighbor.Sfigur.props[F_TYPE] == TYPE_HUMAN) { if (Settings.vampireInfectOnlyOneHuman) { humans++; } else { ((Einwohner)neighbor.Sfigur).infect(); - this.filler += Settings.vampireIncreaseFillPerBite; + this.props[F_FILLER] += Settings.vampireIncreaseFillPerBite; // humans is still 0, so runStep() will return after this } } @@ -56,17 +60,17 @@ namespace vampi for (int i = 1; i <= 8; i++) { Spielfeld neighbor = this.sfeld.getNachbarfeld(i); - if (neighbor != null && neighbor.Sfigur != null && neighbor.Sfigur.Typ == Typliste.EINWOHNER) { + if (neighbor != null && neighbor.Sfigur != null && neighbor.Sfigur.props[F_TYPE] == TYPE_HUMAN) { if (infect == 0) { ((Einwohner)neighbor.Sfigur).infect(); - this.filler += Settings.vampireIncreaseFillPerBite; + this.props[F_FILLER] += Settings.vampireIncreaseFillPerBite; if (!Settings.vampireInfectOneOrMoreHumans) break; } else { infect--; } } } - } // runStep() + } } } \ No newline at end of file diff --git a/vampi.csproj b/vampi.csproj index 9cac808..6d9ede0 100644 --- a/vampi.csproj +++ b/vampi.csproj @@ -68,7 +68,6 @@ -