private Item CreateItem() { int currentX = Rand.Next(1, MapWidth); int currentY = Rand.Next(1, MapHeight); bool containsEnemy = this.characters .Any(e => e.Position.X == currentX && e.Position.Y == currentY); bool containsBeer = this.characters .Any(e => e.Position.X == currentX && e.Position.Y == currentY); while (containsEnemy) { currentX = Rand.Next(1, MapWidth); currentY = Rand.Next(1, MapHeight); containsEnemy = this.characters .Any(e => e.Position.X == currentX && e.Position.Y == currentY); containsBeer = this.characters .Any(e => e.Position.X == currentX && e.Position.Y == currentY); } int beerType = Rand.Next(0, 3); BeerSize beerSize = 0; switch (beerType) { case 0: beerSize = BeerSize.Small; break; case 1: beerSize = BeerSize.Medium; break; case 2: beerSize = BeerSize.Large; break; default: throw new ArgumentOutOfRangeException("beerType", "Invalid beer type!"); } return(new Beer(new Position(currentX, currentY), beerSize)); }
public Beer(Position position, BeerSize beerSize) : base(position, BeerSymbol) { this.BeerSize = beerSize; }