Exemple #1
0
        public Field(int size, Random seed, int percentNearWall, int percentDistractWall)
        {
            wasLight = new List <List <GroundPlate> >();
            stack    = new List <Point>();
            path     = new List <Point>();
            everWas  = new List <Point>();
            ground   = new List <List <GroundPlate> >();
            for (int i = 0; i < size; i++)
            {
                ground.Add(new List <GroundPlate>());
                for (int j = 0; j < size; j++)
                {
                    GroundType gt = GroundType.ground;
                    ground[i].Add(new GroundPlate(gt, i, j));
                }
            }
            int x = size / 2, y = size / 2;

            for (int i = 0; i < size * size / 4; i++)
            {
                bool common = seed.Next(101) < percentNearWall;

                while ((x >= 0 && y >= 0 && x < ground.Count && y < ground[x].Count) && ground[x][y].PathBlocking())
                {
                    if (seed.Next(2) == 0)
                    {
                        x += seed.Next(2) * 2 - 1;
                    }
                    else
                    {
                        y += seed.Next(2) * 2 - 1;
                    }
                }

                if (!common)
                {
                    x = seed.Next(ground.Count - 2) + 1; y = seed.Next(ground[x].Count - 2) + 1;
                }

                if (common || seed.Next(101) < percentDistractWall)                  // || (seed.Next(101) < percentNearWall && AnyWallsIn(Near(x, y, 1))))
                {
                    if (x >= 0 && y >= 0 && x < ground.Count && y < ground[x].Count) //try
                    {
                        GroundPlate gp = ground[x][y];
                        gp.type      = (seed.Next(101) > 5) ? GroundType.wall : GroundType.door;
                        ground[x][y] = gp;
                    }
                }
                //catch (Exception E) { }
            }

            Trace();
        }
Exemple #2
0
 void TurnOffLightProbe(bool AlsoTurnOff)
 {
     for (int i = 0; i < ground.Count; i++)
     {
         for (int j = 0; j < ground[i].Count; j++)
         {
             if (ground[i][j].wasLighted[0] == 'y')
             {
                 GroundPlate lgp = ground[i][j];
                 lgp.wasLighted = "n" + lgp.wasLighted.Substring(1);
                 if (AlsoTurnOff)
                 {
                     lgp.light = 0;
                 }
                 ground[i][j] = lgp;
             }
         }
     }
 }
Exemple #3
0
        void LightIn(int x, int y, int rad)
        {
            TurnOffLightProbe(false);
            double step = Math.PI / (rad * 2);

            for (double ang = 0; ang < Math.PI * 2; ang += step)
            {
                bool mov = false;
                for (float dist = 0; dist <= rad; dist += .1f)
                {
                    int xl = (int)(Math.Cos(ang) * dist + x),
                        yl = (int)(Math.Sin(ang) * dist + y);

                    if (xl < 0 || yl < 0 || xl >= ground.Count || yl >= ground[xl].Count)
                    {
                        break;
                    }

                    GroundPlate lgp = ground[xl][yl];

                    if (lgp.LightBlocking())
                    {
                        break;
                    }

                    if (lgp.wasLighted[0] == 'n')
                    {
                        lgp.light      = Math.Min(2, lgp.light + ((dist < rad / 2) ? 2 : 1));
                        lgp.wasLighted = "yy" + lgp.wasLighted.Substring(2);
                        ground[xl][yl] = lgp;
                    }
                }
                if (mov)
                {
                    ang += 3 * step;
                }
            }
        }
Exemple #4
0
 void LightIn(GroundPlate gp)
 {
     Console.SetCursorPosition(gp.point.Y, gp.point.X);
     Console.BackgroundColor = GroundPlate.groundColor[gp.light];
     Console.Write((gp.type == GroundType.ground) ? ((gp.wasLighted[1] == 'y') ? ' ' : '.') : gp.Symbol);
 }