Example #1
0
        public Unit(int id, CustomGrid grid)
        {
            this.id = id;

            //Spawn unit at a random, valid location
            bool   unitSet = false;
            Random rand    = new Random();

            //Loop while unit is not set at location
            while (unitSet == false)
            {
                int x = rand.Next(grid.GetGridX());
                int y = rand.Next(grid.GetGridY());

                //If the location is valid, set unit to that location
                if (grid.GetGridPosition(x, y).GetSpaceType() == 0 && grid.GetGridPosition(x, y).GetSpaceOccupant() < 0)
                {
                    this.positionX = x;
                    this.positionY = y;
                    grid.GetGridPosition(x, y).SetSpaceOccupant(id);
                    Console.WriteLine(x + y + " OCCUPIED");
                    unitSet = true;
                }
            }
        }