public void AddPlayer(Player player) { playersWaitingForNextRound.Add(player); PlayerAdded playerAddedGameEvent = new PlayerAdded(player.Id); OnGameEventOccured?.Invoke(this, new GameEventOccuredEventArgs(playerAddedGameEvent, player.Id)); }
private void OnPlayerDied(object sender, PlayerDiedEventArgs eventArgs) { playersWaitingForNextRound.Add(eventArgs.DeadPlayer); players.Remove(eventArgs.DeadPlayer); PlayerDied playerDiedGameEvent = new PlayerDied(eventArgs.DeadPlayer.Id); OnGameEventOccured?.Invoke(this, new GameEventOccuredEventArgs(playerDiedGameEvent, eventArgs.DeadPlayer.Id)); }
public void StopGame() { if (IsGameRunning) { IsGameRunning = false; } RoundOver roundOverGameEvent = new RoundOver(players); OnGameEventOccured?.Invoke(this, new GameEventOccuredEventArgs(roundOverGameEvent)); }
private void UpdateEatenObjects() { Console.BackgroundColor = ConsoleColor.Black; List <EatPair <Circle> > eatPairsCircles = new List <EatPair <Circle> >(); List <EatPair <Food> > eatPairsFood = new List <EatPair <Food> >(); for (int playerInd1 = 0; playerInd1 < players.Count; playerInd1++) { for (int playerInd2 = playerInd1 + 1; playerInd2 < players.Count; playerInd2++) { eatPairsCircles.AddRange(players[playerInd1].CalculateCirclesEatPairs(players[playerInd2])); eatPairsCircles.AddRange(players[playerInd2].CalculateCirclesEatPairs(players[playerInd1])); } foreach (Food foodItem in food) { eatPairsFood.AddRange(players[playerInd1].CalculateFoodEatPairs(foodItem)); } } if (eatPairsCircles.Count > 0) { CirclesRemoved circlesRemovedGameEvent = new CirclesRemoved(eatPairsCircles.ConvertAll <int>(eatPair => eatPair.Eaten.Id)); OnGameEventOccured?.Invoke(this, new GameEventOccuredEventArgs(circlesRemovedGameEvent)); } if (eatPairsFood.Count > 0) { FoodRemoved foodRemovedGameEvent = new FoodRemoved(eatPairsFood.ConvertAll <int>(eatPair => eatPair.Eaten.Id)); OnGameEventOccured?.Invoke(this, new GameEventOccuredEventArgs(foodRemovedGameEvent)); } foreach (EatPair <Circle> pair in eatPairsCircles) { pair.Eater.EatObject(pair.Eaten); } foreach (EatPair <Food> pair in eatPairsFood) { pair.Eater.EatObject(pair.Eaten); food.Remove(pair.Eaten); } }
private void RefreshRoom() { players.AddRange(playersWaitingForNextRound); playersWaitingForNextRound.Clear(); food.Clear(); ClearAllCells(); foreach (Player player in players) { SubscribeOnPlayerEvents(player); } GenerateplayersFirstCircles(); Console.WriteLine("Round started"); RoundStarted roundStartedGameEvent = new RoundStarted(players); OnGameEventOccured?.Invoke(this, new GameEventOccuredEventArgs(roundStartedGameEvent)); GenerateFood(FOOD_AMOUNT_ON_START); }
private void GenerateFood(int amount) { Random rand = new Random(); List <Food> newFood = new List <Food>(); for (int i = 0; i < amount; i++) { Point newFoodPoint = GetRandomPointInRoom(); Food newFoodItem = new Food(newFoodPoint); newFood.Add(newFoodItem); int cellX = Math.Min((int)(newFoodItem.Position.X / Cell.WIDTH), cells.Count); int cellY = Math.Min((int)(newFoodItem.Position.Y / Cell.HEIGHT), cells.Count); cells[cellX][cellY].AddFood(newFoodItem); } food.AddRange(newFood); FoodAdded foodAddedGameEvent = new FoodAdded(newFood); OnGameEventOccured?.Invoke(this, new GameEventOccuredEventArgs(foodAddedGameEvent)); }
private void Update() { // TODO delete Console.WriteLine("Update"); // TODO delete if (!IsGameRunning) { return; } UpdatePositions(); UpdateEatenObjects(); players.Sort(); CirclesFrameUpdate positionsUpdatedGameEvent = new CirclesFrameUpdate(players); OnGameEventOccured?.Invoke(this, new GameEventOccuredEventArgs(positionsUpdatedGameEvent)); GenerateFood(FOOD_AMOUNT_PER_UPDATE); if (IsRoundOver()) { StopGame(); } UpdateAllCells(); // TODO delete foreach (Player player in players) { Console.WriteLine("Player {0}: ({1:0.00}; {2:0.00}) | {3}", player.Id, player.PlayerCircles[0].Position.X, player.PlayerCircles[0].Position.Y, player.PlayerCircles[0].Radius); } // TODO delete }
private void OnPlayerCirclesAdded(object sender, PlayerCirclesAddedEventArgs eventArgs) { CirclesAdded circlesAddedGameEvent = new CirclesAdded(eventArgs.NewCircles, eventArgs.PlayerId); OnGameEventOccured?.Invoke(this, new GameEventOccuredEventArgs(circlesAddedGameEvent)); }
private void OnPlayerCirclesRemoved(object sender, PlayerCirclesRemovedEventArgs eventArgs) { CirclesRemoved circlesRemovedGameEvent = new CirclesRemoved(eventArgs.NewCircles.ConvertAll(circle => circle.Id)); OnGameEventOccured?.Invoke(this, new GameEventOccuredEventArgs(circlesRemovedGameEvent)); }