Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
 public Beer(Position position, BeerSize beerSize)
     : base(position, BeerSymbol)
 {
     this.BeerSize = beerSize;
 }
Exemplo n.º 3
0
 public Beer(Position position, BeerSize beerSize)
     : base(position, BeerSymbol)
 {
     this.BeerSize = beerSize;
 }