public static new void CheckLoadPrefab() { if (PrefabEliminator == null) { PrefabEliminator = Resources.Load <Eliminator>("Eliminator"); } }
public static async Task ResetGame() { isBuilding = true; await Say("Game canceled!"); if (Tick != null) { Tick.Stop(); } if (Eliminator != null) { Eliminator.Stop(); } if (TimeLimit != null) { TimeLimit.Stop(); } foreach (Player p in Players) { p.Vote = -1; } await RegenerateMapVoters(); await ClearGameArea(); isBuilding = false; }
public void EliminateSpaceTest() { // Arrange var obj = new Container { ContainerId = 1, ContainerName = "TEMU2934238 ", ContainerType = " Reefer " }; var expected = new Container { ContainerId = 1, ContainerName = "TEMU2934238", ContainerType = "Reefer" }; var sut = new Eliminator(); // Act var actual = sut.EliminateSpace(obj); // Assert Assert.Equal(expected.ContainerId, actual.ContainerId); Assert.Equal(expected.ContainerName, actual.ContainerName); Assert.Equal(expected.ContainerType, actual.ContainerType); }
/// <summary> /// Occurs when a player wins the game. /// </summary> public static async Task PlayerWon(Player player) { TimeSpan ts = DateTime.Now - startTime; if (PlayersInGame.FirstOrDefault(p => p.Id == player.Id) != null && !isBuilding) { if (PlayersSafe.Count == 0) // First { firstPerson = DateTime.Now; int k = Math.Max(35 - round * 5, 10); string s = $"{k} seconds left!"; await Say($"{player.Name.ToUpper()} {(PlayersInGame.Count > 2 ? "finished! " + s : "won!")}"); if (!isTrainMode && PlayersInGame.Count == 2) { Profiles[player.Name].Wins++; } Eliminator.Start(); } string elapsedTime = TimeToString(ts); PlayersSafe.Add(player, ts); //await SayCommand($"reset {player.Name}"); await SayCommand($"effect {player.Name} clear"); //await SayCommand($"tp {player.Name} {TopLeftShiftCoord.X + 16} {TopLeftShiftCoord.Y + 22}"); await SayPrivate(player, $"Your Time: {elapsedTime}s"); await UpdateSign(); Formatter[] format = { new Formatter(PlayersSafe.Count, Color.Gold), new Formatter(player.Name, Color.Green), new Formatter(elapsedTime, Color.Green), }; Console.WriteLineFormatted(" {0}. {1} in {2}", Color.Silver, format); if (!isTrainMode) { Profiles[player.Name].Rounds++; saveProfiles(); } if (2 * PlayersSafe.Count >= PlayersInGame.Count) // 50 % completed - eliminate (For 5 players: 3, For 16 players: 8; Minimum: 3 Players, wait for 2) { if (PlayersSafe.Count > 1) { await Say($"Round over! Players not finished are eliminated!"); } await ContinueGame(); } } }
public static Eliminator Spawn(Vector3 position, float angle, float speed, float lifeSpan) { CheckLoadPrefab(); Eliminator output = Instantiate(PrefabEliminator, position, Quaternion.Euler(0, 0, angle)) as Eliminator; output.speed = speed; output.angle = angle; output.lifeTime = lifeSpan; return(output); }
public void EliminateSpace_Null_Object_Test() { // Arrange Container obj = null; var sut = new Eliminator(); // Act // Assert var ex = Assert.Throws <ArgumentNullException>(() => { var actual = sut.EliminateSpace(obj); }); Assert.Contains("Null物件", ex.Message); }
/// <summary> /// Start or continue a running game process /// </summary> public static async Task ContinueGame() { try { if (!isBuilding) { isBuilding = true; isGameAborted = new CancellationTokenSource(); if (Tick != null) { Tick.Stop(); } if (Eliminator != null) { Eliminator.Stop(); } if (TimeLimit != null) { TimeLimit.Stop(); } await HideMapVoters(); await ClearGameArea(); await Task.Delay(6000, isGameAborted.Token); int maxVotes = 0; var chose = new List <MapInfo>(); foreach (MapVote mv in MapVoteSigns) { if (maxVotes < mv.Voters.Count) { maxVotes = mv.Voters.Count; chose.Clear(); chose.Add(Maps.FirstOrDefault(map => map.Id == mv.MapId)); } else if (maxVotes == mv.Voters.Count) { chose.Add(Maps.FirstOrDefault(map => map.Id == mv.MapId)); } } MapInfo newMap = Maps.ElementAt(0); if (chose.Count == 1) { newMap = chose.ElementAt(0); } else if (chose.Count > 1) { newMap = chose.ElementAt(new Random().Next(0, chose.Count)); } await PlaceSign(TopLeftShiftCoord.X + 16, TopLeftShiftCoord.Y + 22, 58, $"You'll be playing now:\n{newMap.Title}\nBy {newMap.Creator}\n[Difficulty: {newMap.Difficulty}]", 1); await BuildMap(newMap, isGameAborted.Token); await CreateExit(); { Formatter[] format = { new Formatter(newMap.Title, Color.Cyan), new Formatter(newMap.Id.ToString(), Color.Gray), new Formatter(newMap.Creator, Color.Cyan), }; Console.WriteLineFormatted(" Map {0} ({1}) By {2}", Color.Silver, format); } if (PlayersSafe.Count < 2) { round = 1; PlayersInGame = new List <Player>(); PlayersSafe = new Dictionary <Player, TimeSpan>(); foreach (Player p in Players) { if (!p.Afk) { await SayCommand($"reset {p.Name}"); await SayCommand($"tp {p.Name} {TopLeftShiftCoord.X + 16} {TopLeftShiftCoord.Y + 22}"); PlayersInGame.Add(p); } } if (PlayersInGame.Count < 4) { isTrainMode = true; await Say($"Not enough players! Traning mode is enabled! Statistics will not be updated!"); } else { isTrainMode = !isSavingData; // If you are saving data (true) then training mode is not (false), then data is saved! if (isTrainMode) { await Say($"This bot does not save players statistics."); } } foreach (Player p in Players) { if (!isTrainMode) { Profiles[p.Name].Plays++; } } Console.Write("* ", Color.Silver); Console.Write("NEW GAME! "); Console.WriteLine($"{Players.Count} in world, {PlayersInGame.Count} joined", Color.DarkGray); } else { round++; int playersBefore = PlayersInGame.Count; PlayersInGame = new List <Player>(); foreach (KeyValuePair <Player, TimeSpan> p in PlayersSafe) { PlayersInGame.Add(p.Key); } PlayersSafe = new Dictionary <Player, TimeSpan>(); Formatter[] format = { new Formatter("Round", Color.White), new Formatter(round, Color.Gold), new Formatter(PlayersInGame.Count, Color.Green), new Formatter(playersBefore - PlayersInGame.Count, Color.Green), }; Console.WriteLineFormatted(" {0} {1}! {2} joined the round, {3} eliminated", Color.Silver, format); } TimeLimit = new System.Timers.Timer(150 * 1000); TimeLimit.Elapsed += async(object s, ElapsedEventArgs e) => { await Say($"Time's over!"); await ContinueGame(); }; int k = Math.Max(35 - round * 5, 10); Eliminator = new System.Timers.Timer(k * 1000); Eliminator.Elapsed += async(object s, ElapsedEventArgs e) => { if (PlayersSafe.Count == 1) { await Say($"{PlayersSafe.ElementAt(0).Key.Name.ToUpper()} won!"); if (!isTrainMode) { Profiles[PlayersSafe.ElementAt(0).Key.Name].Wins++; } } else { await Say($"Time's over!"); } await ContinueGame(); }; await Task.Delay(5000, isGameAborted.Token); await MakeGravity(); await OpenEntrance(); await Task.Delay(500, isGameAborted.Token); await ReleasePlayers(); startTime = DateTime.Now; TimeLimit.Start(); await Task.Delay(2000, isGameAborted.Token); await CreateSafeArea(); foreach (Player p in Players) { p.Vote = -1; } await RegenerateMapVoters(); Tick.Start(); isBuilding = false; } } catch (TaskCanceledException) { await ResetGame(); } }
protected override void ExecuteSpecialX() { AudioManager.PlayClipByName("Shot2"); Eliminator.Spawn(transform.position + MathLib.FromPolar(Player.Radius, Player.TurretAngle).ToVector3(), Player.TurretAngle, eliminatorSpeed, eliminatorLifeSpan); }