예제 #1
0
        public List <Grain> InitializeBoard(int boardWidth, int boardHeight, int penColors)
        {
            Random random = new Random();

            for (int i = 0; i < penColors; i++)
            {
                Pen color = new Pen(Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 255)));
                PenColors.Add(color);
            }

            for (int i = 0; i < boardWidth; i++)
            {
                for (int j = 0; j < boardHeight; j++)
                {
                    Point position   = new Point(i, j);
                    int   colorIndex = random.Next(PenColors.Count);
                    Grain grain      = new Grain(position, PenColors[colorIndex]);
                    grain.SetGrainAlive();

                    Grains.Add(grain);
                }
            }
            return(Grains);
        }
예제 #2
0
파일: Form1.cs 프로젝트: sehta7/Ziarna
        private void ChangeGrainEnergy(List <Grain> energies)
        {
            Random rand = new Random();

            for (int i = 0; i < Int32.Parse(textBox11.Text); i++)
            {
                int randIndex = rand.Next(0, energies.Count - 1);

                for (int j = 0; j < pictureBox1.Size.Width - 1; j++)
                {
                    for (int k = 0; k < pictureBox1.Size.Height - 1; k++)
                    {
                        if (j == energies[randIndex].Position.X && k == energies[randIndex].Position.Y)
                        {
                            Grain tempGrain = new Grain(new Point(j, k), new Pen(Color.FromArgb(rand.Next(0, 255), 0, 0)));
                            tempGrain.H = 0;

                            board.GrainsInPreviousStep[j, k] = tempGrain;
                        }
                    }
                }
                energies.Remove(energies[randIndex]);
            }
        }
예제 #3
0
 public void Reviev(Grain aliveNeighbour)
 {
     this.Alive    = true;
     this.PenColor = aliveNeighbour.PenColor;
 }
예제 #4
0
파일: Board.cs 프로젝트: sehta7/Ziarna
 private void SaveGrainInArrays(int xPosition, int yPosition, Grain grain)
 {
     GrainsInPreviousStep[xPosition, yPosition] = grain;
     GrainsInCurrentStep[xPosition, yPosition]  = grain;
 }