public Bullet(Battlefield battlefield, double x, double y, double heading, int speed, decimal strength, RobotRunner robotRunner) { _battlefield = battlefield; _x = x; _y = y; _heading = heading; _speed = speed; _strength = strength; _origin = robotRunner; _dead = false; }
public MainView() { _uiThread = Thread.CurrentThread; _timer = new Timer {Interval = 5}; _timer.Elapsed += TimerElapsed; Height = RunOptions.Y; Width = RunOptions.X; _battlefield = RunOptions.Battlefield; _showRadar = false; InitCanvas(); DrawFrame(); _timer.Enabled = true; }
private static void PrintOutcome(Battlefield battlefield) { var winners = battlefield.Robots.Where(robot => !robot.Dead()).ToList(); Console.WriteLine(""); if (battlefield.Robots.Count > battlefield.Teams) { var winningTeams = new List<int>(); foreach (var robot in winners.Where(robot => !winningTeams.Contains(robot.Team))) winningTeams.Add(robot.Team); foreach (var winningTeam in winningTeams) { var teamNum = "Team #" + winningTeam.ToString(CultureInfo.InvariantCulture); var teamMembers = battlefield.Robots.Where(robot => robot.Team == winningTeam).ToList(); var winningTeamNames = GetNames(teamMembers); var winningTeamEnergies = GetEnergies(teamMembers); Console.WriteLine("winner_is: { " + teamNum + ": " + winningTeamNames + "}"); Console.WriteLine("winner_energy: { " + teamNum + ": " + winningTeamEnergies + "}"); } } else { Console.WriteLine("winner_is: [" + GetNames(winners) + "]"); Console.WriteLine("winner_energy: [" + GetEnergies(winners) + "]"); } Console.WriteLine("elapsed_ticks: " + battlefield.Time); Console.WriteLine("seed : " + battlefield.Seed); Console.WriteLine(""); Console.WriteLine("robots :"); foreach (var robot in battlefield.Robots) { Console.WriteLine(" " + robot.Name + ":"); Console.WriteLine(" damage_given: " + robot.DamageGiven); Console.WriteLine(" damage_taken: " + (100 - robot.Energy)); Console.WriteLine(" kills: " + robot.Kills); } }
private static void RunOutOfGui(Battlefield battlefield) { Console.WriteLine("match ends if only 1 bot/team left or dots get here-->|"); while (!battlefield.GameOver) { battlefield.Tick(); if (Convert.ToInt32(battlefield.Time%(battlefield.Timeout/54)) == 0) Console.Write("."); } PrintOutcome(battlefield); //exit(0); }
public RunOptions(string[] args) { // look for resolution arg X = 800; Y = 800; var arguments = args.ToList(); if (arguments.Count() > 2) { if (IsNumeric(arguments[0]) && IsNumeric(arguments[1])) { X = Convert.ToInt32(args[0]); Y = Convert.ToInt32(args[1]); arguments.RemoveAt(0); arguments.RemoveAt(0); } } var seed = DateTime.Now.Ticks; var seedArgument = SearchForArgumentStartingWith("#", arguments); if (!string.IsNullOrEmpty(seedArgument)) seed = Convert.ToInt32(seedArgument); var timeout = 50000; var timeoutArgument = SearchForArgumentStartingWith("-timeout=", arguments); if (!string.IsNullOrEmpty(timeoutArgument)) timeout = Convert.ToInt32(timeoutArgument); ShowUi = true; if (ArgumentExists("-nogui", arguments)) ShowUi = false; ShowRadar = false; /* ARGV.grep( /^show_radar/ )do |item| show_radar = true ARGV.delete(item) end*/ var teams = 8; var teamsArgument = SearchForArgumentStartingWith("-teams=", arguments); if (!string.IsNullOrEmpty(teamsArgument)) teams = Convert.ToInt32(teamsArgument); if (teams < 0 || teams > 8) teams = 8; if (arguments.Count == 0 || arguments.Count > 8) { Error = true; return; } Battlefield = new Battlefield(X * 2, Y * 2, timeout, seed); var c = 0; var teamDivider = Math.Ceiling(Convert.ToDouble(arguments.Count / teams)); Error = false; foreach (var argument in arguments) { Robot robotShell = null; try { var o = Activator.CreateInstance(argument, argument + "." + argument); robotShell = (Robot)o.Unwrap(); } catch (Exception ex) { Console.WriteLine("Error loading robot: " + argument); Console.WriteLine(ex.ToString()); Error = true; } var team = (int)(c / teamDivider); c += 1; var robot = new RobotRunner(robotShell, Battlefield, team); Battlefield.Add(robot); } }