예제 #1
0
        /*
         * 0 - empty
         * 1 - wall
         * 2 - fiend
         * 3 - skillet
         */
        public World(int x, int y, int o)
        {
            width        = x;
            height       = y;
            cell         = o;
            worldObjects = new List <WorldObjects>();
            fiends       = new List <Fiend>();
            worldmatrix  = new int[width, height];
            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    worldmatrix[i, j] = 0;
                }
            }

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    if (i == 0 || j == 0 || i == width - 1 || j == height - 1)
                    {
                        WorldObjects item = new Wall(i, j, cell);
                        worldObjects.Add(item);
                    }
                }
            }
            Fiend theFirst = new Fiend(20, 20, cell, 0);

            fiends.Add(theFirst);
        }
예제 #2
0
 public void Age()
 {
     Fiend[] fiend = new Fiend[fiends.Count];
     fiends.CopyTo(fiend);
     foreach (Fiend some in fiend)
     {
         some.Mind();
     }
 }
예제 #3
0
        public Rectangle MakeVisuality(Fiend some)
        {
            int       x    = some.X;
            int       y    = some.Y;
            int       size = some.size;
            Rectangle rect = new Rectangle(x * size + x * 1 + 1, y * size + y * 1 + 1, size, size);

            return(rect);
        }
예제 #4
0
        public bool Mitosis()
        {
            int  energycost = 50;
            bool done       = false;
            bool emptyspace = false;

            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    int x1 = X - 1 + i;
                    int y1 = Y - 1 + j;
                    if (World.worldmatrix[x1, y1] == 0)
                    {
                        emptyspace = true;
                        break;
                    }
                }
            }

            if (emptyspace)
            {
                Point newLoc = new Point(X, Y);
                int   nav;
                do
                {
                    nav = r.Next(1, 9);
                    switch (nav)
                    {
                    case 1:
                        newLoc = new Point(X - 1, Y - 1);
                        break;

                    case 2:
                        newLoc = new Point(X, Y - 1);
                        break;

                    case 3:
                        newLoc = new Point(X + 1, Y - 1);
                        break;

                    case 4:
                        newLoc = new Point(X - 1, Y);
                        break;

                    case 5:
                        newLoc = new Point(X + 1, Y);
                        break;

                    case 6:
                        newLoc = new Point(X - 1, Y + 1);
                        break;

                    case 7:
                        newLoc = new Point(X, Y + 1);
                        break;

                    case 8:
                        newLoc = new Point(X + 1, Y + 1);
                        break;
                    }

                    if (World.worldmatrix[newLoc.X, newLoc.Y] == 0)
                    {
                        Fiend newbie = new Fiend(newLoc.X, newLoc.Y, size, speed);
                        World.fiends.Add(newbie);
                        done = true;
                    }
                } while (!done);

                energy -= energycost;
            }

            return(done);
        }