public void AddPlayer(BattleEngine.Player.Player player) { this.players.Add(player.Name, player); this.Console.ConsoleWriteLine(player.Summarize()); }
public void RemovePlayer(BattleEngine.Player.Player player) { this.players.Remove(player.Name); this.Console.ConsoleWriteLine(player.Summarize() + " removed"); }
public void Battle() { this.round = 0; if (this.players.Count < 2) { throw new Exception("Need at least 2 players to battle, add more players."); } this.Console.ConsoleWriteLine("=========================="); this.Console.ConsoleWriteLine("= THE BATTLE BEGINS! ="); this.Console.ConsoleWriteLine("=========================="); // initial targetting this.place_players_on_map(); foreach (BattleEngine.Player.Player p in this.players.Values) { p.Reset(); } foreach (BattleEngine.Player.Player p in this.players.Values) { p.Target = this.pick_target_by_shortest_distance(p); this.Console.ConsoleWriteLine(string.Format("\"{0}\" targets \"{1}\"", p.Name, p.Target.Name)); } BattleEngine.Player.Player winner = null; while (this.PlayersLeftStanding() > 1) { this.Console.ConsoleWriteLine(""); this.Console.ConsoleWriteLine("ROUND " + this.round.ToString()); this.BattleGui.DoEvents(); foreach (BattleEngine.Player.Player p in this.players.Values) { if (!p.IsDead()) { if (!p.Target.IsDead()) { this.attack(p, p.Target); } else if (this.PlayersLeftStanding() > 1) { p.Target = this.pick_target_by_shortest_distance(p); } } } // show current stats foreach (BattleEngine.Player.Player p in this.players.Values) { if (!p.IsDead()) { this.Console.ConsoleWriteLine(p.SummarizeHealth()); } } this.round++; if (this.round > 1000) { this.Console.ConsoleWriteLine("Battle has lasted too long"); winner = null; break; } } foreach (BattleEngine.Player.Player p in this.players.Values) { if (!p.IsDead()) { winner = p; } } this.Console.ConsoleWriteLine("=========================="); this.Console.ConsoleWriteLine("= THE BATTLE ENDS! ="); this.Console.ConsoleWriteLine("=========================="); if (winner != null) { this.Console.ConsoleWriteLine(string.Format("\"{0}\" wins the battle in {1} rounds!", winner.Name, this.round)); this.Console.ConsoleWriteLine(winner.Summarize()); } else { this.Console.ConsoleWriteLine("Its a draw"); } }