private void SetItems(FieldItem item) { if (item is IMovable movable) { if (movable is Player playerObj) { player = playerObj; } else { EnemyCount++; } persons.Add(movable); } else if (item is Respawn respawnObj) { RespawnPoint = respawnObj.Location; } else if (item is Coin coinObj) { CoinsLocations.Add(coinObj.Location); } else if (item is BigCoin bigCoinObj) { BigCoinsLocations.Add(bigCoinObj.Location); } }
public void Update() { var localPersons = new List <IMovable>(persons); foreach (var person in localPersons.Where(p => p != null)) { var lastPosition = person.GetLocation(); person.Move(out var collisionItem); person.Collision(collisionItem); var currentPosition = person.GetLocation(); if (lastPosition != currentPosition) { if (CoinsLocations.Contains(lastPosition)) { Field[(int)lastPosition.Y, (int)lastPosition.X] = new Coin(this, lastPosition); } else if (BigCoinsLocations.Contains(lastPosition)) { Field[(int)lastPosition.Y, (int)lastPosition.X] = new BigCoin(this, lastPosition); } } if (HealthPoints == 0 || EnemyCount == 0 || CoinsLocations.Count == 0) { IsGameOver = true; return; } } persons = persons.Where(p => p != null).ToList(); }
public void Update(MoveDirection direction) { player.SetMoveDirection(direction); foreach (var person in persons) { var lastPosition = person.GetLocation(); person.Move(out var collisionItem); person.Collision(collisionItem); var currentPosition = person.GetLocation(); if (lastPosition != currentPosition) { if (CoinsLocations.Contains(lastPosition)) { Field[(int)lastPosition.Y, (int)lastPosition.X] = new Coin(this, lastPosition); } else if (BigCoinsLocations.Contains(lastPosition)) { Field[(int)lastPosition.Y, (int)lastPosition.X] = new BigCoin(this, lastPosition); } } if (HealthPoints == 0 || EnemyCount == 0) { IsGameOver = true; return; } } }