Пример #1
0
        public void Sick(mybutton b, int NOS)
        {
            double NotInfectionRatio = 1 - float.Parse(this.diseaseNUM.Text.ToString());
            int    sickchan          = Convert.ToInt32(Math.Pow(NotInfectionRatio, NOS) * 100);

            if (rnd.Next(0, 100) >= sickchan)
            {
                SickNumber++;
                b.BackColor      = System.Drawing.Color.Red;
                b.ClickCountStat = ClickCounter;
                b.IsInfected     = 1;
            }
        }
Пример #2
0
        private void ClickB(object sender, EventArgs e)
        {
            mybutton b = (mybutton)sender;

            if (b.IsAlive == 0)
            {
                b.IsAlive    = 1;
                b.IsVaccine  = 0;
                b.IsInfected = 0;
                b.BackColor  = System.Drawing.Color.White;
            }
            else
            {
                if (b.IsInfected == 0 && b.IsVaccine == 0)
                {
                    b.IsInfected = 1;
                    SickNumber++;
                    b.BackColor      = System.Drawing.Color.Red;
                    b.ClickCountStat = ClickCounter;
                }
                else
                {
                    if (b.IsInfected == 1)
                    {
                        SickNumber--;
                        NormalPopulation++;
                        VaccineNumber++;
                        b.IsInfected = 0;
                        b.IsVaccine  = 1;
                        b.BackColor  = System.Drawing.Color.Blue;
                    }
                    else
                    {
                        if (b.IsVaccine == 1)
                        {
                            NormalPopulation++;
                            VaccineNumber--;
                            b.IsVaccine  = 0;
                            b.IsInfected = 0;
                            b.IsAlive    = 1;
                            b.BackColor  = System.Drawing.Color.White;
                        }
                    }
                }
            }
        }
Пример #3
0
        private void InitializeComponent()
        {
            this.AllMyButtns      = new mybutton[90, 45];
            this.startB           = new mybutton();
            this.startB.BackColor = System.Drawing.Color.White;
            this.startB.Size      = new System.Drawing.Size(38, 20);
            this.startB.Location  = new System.Drawing.Point(5 * 15, 3);
            this.startB.UseVisualStyleBackColor = true;
            System.Windows.Forms.ToolTip ToolTip2 = new System.Windows.Forms.ToolTip();
            ToolTip2.InitialDelay = 100;
            ToolTip2.SetToolTip(this.startB, "Simulate period of time");
            this.startB.Text           = "Play";
            this.startB.infactionRatio = 0.4;


            this.resetB           = new mybutton();
            this.resetB.BackColor = System.Drawing.Color.White;
            this.resetB.Size      = new System.Drawing.Size(45, 20);
            this.resetB.Location  = new System.Drawing.Point(15, 3);
            this.resetB.UseVisualStyleBackColor = true;
            this.resetB.Text = "Reset";

            this.diseaseNUM          = new TextBox();
            this.diseaseNUM.Location = new System.Drawing.Point(8 * 15, 3);
            this.diseaseNUM.Size     = new System.Drawing.Size(40, 20);
            this.diseaseNUM.Text     = "0.5";
            System.Windows.Forms.ToolTip ToolTip1 = new System.Windows.Forms.ToolTip();
            ToolTip1.InitialDelay = 100;
            ToolTip1.SetToolTip(this.diseaseNUM, "Infection coefficient (from 1 to 0)");


            this.Lethality          = new NumericUpDown();
            this.Lethality.Location = new System.Drawing.Point(12 * 15, 3);
            this.Lethality.Size     = new System.Drawing.Size(40, 20);
            this.Lethality.Value    = 50;
            this.Lethality.Maximum  = 100;
            this.Lethality.Minimum  = 0;
            System.Windows.Forms.ToolTip ToolTip3 = new System.Windows.Forms.ToolTip();
            ToolTip3.InitialDelay = 100;
            ToolTip3.SetToolTip(this.Lethality, "Lethality (percentage)");



            Random rnd = new Random();

            for (int i = 0; i < 90; i++)
            {
                for (int j = 0; j < 45; j++)
                {
                    AllMyButtns[i, j]          = new mybutton();
                    AllMyButtns[i, j].Size     = new System.Drawing.Size(15, 15);
                    AllMyButtns[i, j].Location = new System.Drawing.Point(i * 15 + 10, j * 15 + 25);
                    AllMyButtns[i, j].UseVisualStyleBackColor = true;
                    AllMyButtns[i, j].X          = i;
                    AllMyButtns[i, j].Y          = j;
                    AllMyButtns[i, j].IsInfected = 0;
                    AllMyButtns[i, j].IsAlive    = 1;
                    AllMyButtns[i, j].IsVaccine  = 0;
                    AllMyButtns[i, j].BackColor  = System.Drawing.Color.White;
                }
            }

            this.SuspendLayout();

            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode       = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize          = new System.Drawing.Size(450, 475);

            //this.WindowState = FormWindowState.Maximized;

            for (int i = 0; i < 90; i++)
            {
                for (int j = 0; j < 45; j++)
                {
                    this.Controls.Add(AllMyButtns[i, j]);
                    AllMyButtns[i, j].Click += new System.EventHandler(ClickB);
                }
            }
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));


            this.ClientSize = new System.Drawing.Size(284, 261);
            this.Icon       = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.Controls.Add(startB);
            this.Controls.Add(resetB);
            this.Controls.Add(diseaseNUM);
            this.Controls.Add(Lethality);
            startB.Click += new System.EventHandler(startBClick);
            resetB.Click += new System.EventHandler(resetBClick);
            this.Name     = "Form1";
            this.Text     = "Corona Simulator by Arie Ravad";
            this.ResumeLayout(false);
        }
Пример #4
0
        public void InfactionFunction(object O)
        {
            mybutton b = (mybutton)O;

            double NotInfectionRatio = 1 - float.Parse(this.diseaseNUM.Text.ToString());

            if (b.IsAlive == 1)
            {
                if (b.IsInfected == 0)
                {
                    if (b.IsVaccine == 0)
                    {
                        if (b.Y > 0 && b.Y < 44)
                        {
                            if (b.X > 0 && b.X < 89)
                            {
                                int numOfSICKS = AllMyButtns[b.X - 1, b.Y - 1].IsInfected +
                                                 AllMyButtns[b.X - 1, b.Y].IsInfected +
                                                 AllMyButtns[b.X - 1, b.Y + 1].IsInfected +
                                                 AllMyButtns[b.X, b.Y - 1].IsInfected +
                                                 AllMyButtns[b.X + 1, b.Y - 1].IsInfected +
                                                 AllMyButtns[b.X + 1, b.Y].IsInfected +
                                                 AllMyButtns[b.X, b.Y + 1].IsInfected +
                                                 AllMyButtns[b.X + 1, b.Y + 1].IsInfected;


                                int sickchan = Convert.ToInt32(Math.Pow(NotInfectionRatio, numOfSICKS) * 100);

                                Sick(b, numOfSICKS);
                            }
                            else if (b.X == 0)
                            {
                                int numOfSICKS = AllMyButtns[b.X, b.Y - 1].IsInfected +
                                                 AllMyButtns[b.X + 1, b.Y - 1].IsInfected +
                                                 AllMyButtns[b.X + 1, b.Y].IsInfected +
                                                 AllMyButtns[b.X, b.Y + 1].IsInfected +
                                                 AllMyButtns[b.X + 1, b.Y + 1].IsInfected;

                                int sickchan = Convert.ToInt32(Math.Pow(NotInfectionRatio, numOfSICKS) * 100);

                                Sick(b, numOfSICKS);
                            }

                            else if (b.X == 89)
                            {
                                int numOfSICKS = AllMyButtns[b.X - 1, b.Y - 1].IsInfected +
                                                 AllMyButtns[b.X - 1, b.Y].IsInfected +
                                                 AllMyButtns[b.X - 1, b.Y + 1].IsInfected +
                                                 AllMyButtns[b.X, b.Y - 1].IsInfected +
                                                 AllMyButtns[b.X, b.Y + 1].IsInfected;
                                int sickchan = Convert.ToInt32(Math.Pow(NotInfectionRatio, numOfSICKS) * 100);

                                Sick(b, numOfSICKS);
                            }
                        }
                        else if (b.Y == 0)
                        {
                            if (b.X > 0 && b.X < 89)
                            {
                                int numOfSICKS =
                                    AllMyButtns[b.X - 1, b.Y].IsInfected +
                                    AllMyButtns[b.X - 1, b.Y + 1].IsInfected +
                                    AllMyButtns[b.X + 1, b.Y].IsInfected +
                                    AllMyButtns[b.X, b.Y + 1].IsInfected +
                                    AllMyButtns[b.X + 1, b.Y + 1].IsInfected;
                                int sickchan = Convert.ToInt32(Math.Pow(NotInfectionRatio, numOfSICKS) * 100);

                                Sick(b, numOfSICKS);
                            }
                            else if (b.X == 0)
                            {
                                int numOfSICKS = AllMyButtns[b.X + 1, b.Y].IsInfected +
                                                 AllMyButtns[b.X, b.Y + 1].IsInfected +
                                                 AllMyButtns[b.X + 1, b.Y + 1].IsInfected;
                                int sickchan = Convert.ToInt32(Math.Pow(NotInfectionRatio, numOfSICKS) * 100);

                                Sick(b, numOfSICKS);
                            }
                            else if (b.X == 89)
                            {
                                int numOfSICKS = AllMyButtns[b.X - 1, b.Y].IsInfected +
                                                 AllMyButtns[b.X - 1, b.Y + 1].IsInfected +
                                                 AllMyButtns[b.X, b.Y + 1].IsInfected;

                                int sickchan = Convert.ToInt32(Math.Pow(NotInfectionRatio, numOfSICKS) * 100);

                                Sick(b, numOfSICKS);
                            }
                        }
                        else if (b.Y == 44)
                        {
                            if (b.X > 0 && b.X < 89)
                            {
                                int numOfSICKS = AllMyButtns[b.X - 1, b.Y - 1].IsInfected +
                                                 AllMyButtns[b.X - 1, b.Y].IsInfected +
                                                 AllMyButtns[b.X, b.Y - 1].IsInfected +
                                                 AllMyButtns[b.X + 1, b.Y - 1].IsInfected +
                                                 AllMyButtns[b.X + 1, b.Y].IsInfected;
                                int sickchan = Convert.ToInt32(Math.Pow(NotInfectionRatio, numOfSICKS) * 100);

                                Sick(b, numOfSICKS);
                            }
                            else if (b.X == 0)
                            {
                                int numOfSICKS = AllMyButtns[b.X, b.Y - 1].IsInfected +
                                                 AllMyButtns[b.X + 1, b.Y - 1].IsInfected +
                                                 AllMyButtns[b.X + 1, b.Y].IsInfected;
                                int sickchan = Convert.ToInt32(Math.Pow(NotInfectionRatio, numOfSICKS) * 100);

                                Sick(b, numOfSICKS);
                            }
                            else if (b.X == 89)
                            {
                                int numOfSICKS = AllMyButtns[b.X - 1, b.Y - 1].IsInfected +
                                                 AllMyButtns[b.X - 1, b.Y].IsInfected +
                                                 AllMyButtns[b.X, b.Y - 1].IsInfected;
                                int sickchan = Convert.ToInt32(Math.Pow(NotInfectionRatio, numOfSICKS) * 100);

                                Sick(b, numOfSICKS);
                            }
                        }
                    }
                }
                else
                {
                    if (ClickCounter >= (b.ClickCountStat + 4))
                    {
                        if (rnd.Next(0, 100) <= Lethality.Value)
                        {
                            NormalPopulation--;
                            b.IsAlive    = 0;
                            b.BackColor  = System.Drawing.Color.Black;
                            b.IsInfected = 0;
                        }
                        else
                        {
                            NormalPopulation--;
                            b.IsInfected = 0;
                            b.IsVaccine  = 1;
                            b.BackColor  = System.Drawing.Color.Blue;
                        }
                    }
                }
            }
        }