+ added properties instead of class variables
x removed Typliste (integrated in Einwohner)
This commit is contained in:
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user