예제 #1
0
        private static ICreature CreateCreatureBySymbol(char c, int x, int y)
        {
            switch (c)
            {
            case 'N':
                return(null);

            case 'W':
            {
                var creature = new Wall(new Point(x, y), "wall");
                return(creature);
            }

            case 'B':
            {
                var creature = new Box(new Point(x, y), "box");
                return(creature);
            }

            case 'D':
            {
                var creature = new Destiny(new Point(x, y), "destiny");
                return(creature);
            }

            default:
                return(null);
            }
        }
예제 #2
0
        public void Add(string name)
        {
            var rndm  = new Random();
            var x     = 0;
            var y     = 0;
            var check = true;

            while (check)
            {
                var count = aliveCreatures.Count;
                x = rndm.Next(0, MapWidth);
                y = rndm.Next(0, MapHeight);
                foreach (var s in aliveCreatures)
                {
                    var body = s.GetBody();
                    if (map[x, y] == null && !body.Contains(new Point(x, y)))
                    {
                        count--;
                    }
                }
                check = count == 0 ? false : true;
            }
            switch (name)
            {
            case "food":
            {
                map[x, y] = new Food(new Point(x, y), name);
                break;
            }

            case "destiny":
            {
                map[x, y] = new Destiny(new Point(x, y), name);
                break;
            }
            }
        }