Exemplo n.º 1
0
        private static async Task spawnBulb(string[,] grid, Bulb[] bulb, int b)
        {
            bulb[b] = new Bulb(-1, -1);
            bulb[b].spawn(grid.GetUpperBound(0));
            //Console.WriteLine($"bulb {b}: {bulb[b].x},{bulb[b].y}");
            await Task.Delay(10);

            grid[bulb[b].x, bulb[b].y] = "b";
        }
Exemplo n.º 2
0
        private async void RunADay_Click(object sender, EventArgs e)
        {
            BulbsAtStart.Text = BulbsSurvived.Text;
            Status.Text       = "day has started";
            Random random = new Random();

            Day.Text        = (int.Parse(Day.Text) + 1).ToString();
            EnergyLeft.Text = EnergyAtStart.Text;
            Bulb[] bulb = new Bulb[int.Parse(this.BulbsAtStart.Text)];



            //create an array
            string[,] grid = new string[int.Parse(this.FieldSize.Text), int.Parse(this.FieldSize.Text)];
            for (int y = 0; y < int.Parse(FieldSize.Text); y++)
            {
                for (int x = 0; x < int.Parse(FieldSize.Text); x++)
                {
                    grid[x, y] = " ";
                }
            }


            //spawn bulbs
            for (int b = 0; b < int.Parse(BulbsAtStart.Text); b++)
            {
                await spawnBulb(grid, bulb, b);
            }


            //show(bulb);


            //spawn food
            for (int i = 0; i < int.Parse(FoodAtStart.Text); i++)
            {
                spawnFood(random, grid);
            }


            //run their moves
            for (int i = int.Parse(EnergyAtStart.Text); i > 0; i--)
            {
                for (int b = 0; b < int.Parse(BulbsAtStart.Text); b++)
                {
                    bulb[b].move();
                }
                await Task.Delay(3000);

                EnergyLeft.Text = (i - 1).ToString();
            }

            show(bulb);
            show(grid);


            {
                //reproduction();
            }
            Status.Text = "day is over..";
        }