public PhaseOverEventArgs(Phase oldPhase, Phase newPhase) { this.oldPhase = oldPhase; this.newPhase = newPhase; }
void NextPhase() { Log.Debug("Determining next phase"); PhaseType initialPhase = phase.Type; do { switch(phase.Type) { case PhaseType.Day: phase = new Phase(this, PhaseType.Twilight); break; case PhaseType.Twilight: phase = new Phase(this, PhaseType.Night); break; case PhaseType.Night: phase = new Phase(this, PhaseType.Dawn); break; case PhaseType.Dawn: phase = new Phase(this, PhaseType.Day); break; case PhaseType.Night0: phase = new Phase(this, PhaseType.Dawn); break; } if(phase.Type == initialPhase) { throw new MafiaException("No valid phase found!"); } } while (!Members.Any(m => m.Powers.Any(p => p.CanExecute(this) && !p.Phases.Any(ph => ph == PhaseType.Any))) && !Factions.Any(f => f.Powers.Any(p => p.CanExecute(this) && !p.Phases.Any(ph => ph == PhaseType.Any)))); if(phase.Type == PhaseType.Day) { Outside.AllowTalking(true); } else { Outside.AllowTalking(false); } Log.Debug("Next phase found: " + phase.Type.ToString()); }
void OnPhaseOver(object sender, EventArgs e) { Phase oldPhase = phase; Outside.SendMessage(phase.Type.ToString() + " is over."); List<Faction> winningFactions = GetWinningFactions(); if (winningFactions.Count > 0) { Log.Debug("Game is over."); string winMessage = GetWinMessage(winningFactions); Outside.SendMessage(winMessage); phase = new Phase(this, PhaseType.Over); if (GameOver != null) { GameOver(this, new GameOverEventArgs(winningFactions, winMessage)); } return; } NextPhase(); phase.PhaseOver += new EventHandler(OnPhaseOver); foreach (VillageMember member in Members) { member.Turn(); } foreach (Faction faction in Factions) { faction.Turn(); } Outside.SendMessage("It is now " + phase.Type.ToString()); if(PhaseOver != null) { PhaseOver(this, new PhaseOverEventArgs(oldPhase, phase)); } }
public void Start() { phase = new Phase(this, Rules.InitialPhase); phase.PhaseOver += new EventHandler(OnPhaseOver); Outside.SendMessage("It is now " + phase.Type.ToString()); if (Rules.InitialPhase == PhaseType.Day) { Outside.AllowTalking(true); } Log.Debug("Game started (Initial Phase: " + phase.Type.ToString() + ")"); }