コード例 #1
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            try
            {
                timeleft1 = 99;
                timeleft2 = 100;
                timeleft3 = 100;
                timeleft4 = 100;
                timeleft5 = 100;
                timeleft6 = 100;
                timeleft7 = 100;

                ovalShape2.Location = new Point(400, 170);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Please enter every values given in menu");
                return;
            }


            //-------------------------phosphorus in land
            org_soil = x;
            uptake   = y;
            year     = z;
            year     = year - 2000;
            double River, Land;
            Random rand2 = new Random();
            int    land  = rand2.Next(197, 304);

            Land = (double)land / 11.0;
            Land = Math.Round(Land, 3);

            //-----------------------phosphorus in River
            Random rand3 = new Random();
            int    river = rand3.Next(790, 1329);

            River = (double)river / 100.0;
            River = Math.Round(River, 3);

            while (Land - River <= 10.0)
            {
                Random rand4 = new Random();
                river = rand4.Next(790, 1329);
                River = (double)river / 100.0;
                River = Math.Round(River, 3);
            }

            //----------------------phosphorus in organic
            double veggie, Ku, N;

            Ku = (double)uptake * 1.0;

            N = (double)org_soil * 1.0;
            Random rand5 = new Random();
            int    zr    = rand5.Next(1640, 1929);

            Double Zr;

            Zr     = (double)zr / 10.0;
            veggie = (((Ku * N * years[year] * Land * 1.0) / 0.4) / (Zr * 1.0)) / 2.0;
            veggie = Math.Round(veggie, 3);

            Double Inorg;

            Inorg = Land - veggie - River;
            Inorg = Math.Round(Inorg, 3);

            Random rand6    = new Random();
            int    sediment = rand2.Next(1000, 1999);
            double Sediment = (double)sediment / 100000;

            Sediment = Sediment * Land;
            Sediment = Math.Round(Sediment, 3);

            richTextBox1.Text = Land.ToString() + "*10 ";
            richTextBox1.Select(richTextBox1.Text.Length - 1, richTextBox1.Text.Length);
            richTextBox1.SelectionCharOffset = 7;
            richTextBox1.SelectedText        = "12";
            richTextBox1.SelectionCharOffset = 0;
            richTextBox1.AppendText(" gm");


            richTextBox2.Text = River.ToString() + "*10 ";
            richTextBox2.Select(richTextBox2.Text.Length - 1, richTextBox2.Text.Length);
            richTextBox2.SelectionCharOffset = 7;
            richTextBox2.SelectedText        = "12";
            richTextBox2.SelectionCharOffset = 0;
            richTextBox2.AppendText(" gm");

            richTextBox3.Text = veggie.ToString() + "*10 ";
            richTextBox3.Select(richTextBox3.Text.Length - 1, richTextBox3.Text.Length);
            richTextBox3.SelectionCharOffset = 7;
            richTextBox3.SelectedText        = "12";
            richTextBox3.SelectionCharOffset = 0;
            richTextBox3.AppendText(" gm");


            richTextBox4.Text = Inorg.ToString() + "*10 ";
            richTextBox4.Select(richTextBox4.Text.Length - 1, richTextBox4.Text.Length);
            richTextBox4.SelectionCharOffset = 7;
            richTextBox4.SelectedText        = "12";
            richTextBox4.SelectionCharOffset = 0;
            richTextBox4.AppendText(" gm");

            richTextBox5.Text = Sediment.ToString() + "*10 ";
            richTextBox5.Select(richTextBox5.Text.Length - 1, richTextBox5.Text.Length);
            richTextBox5.SelectionCharOffset = 7;
            richTextBox5.SelectedText        = "12";
            richTextBox5.SelectionCharOffset = 0;
            richTextBox5.AppendText(" gm");


            button2.Show();
            timer1.Start();
            ovalShape1.Location = new Point(410, 180);
            ovalShape1.Show();
            ovalShape2.Show();
            button1.Hide();
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: Infinite-Lop/mountain-crash
        private void Generation_Click(object sender, EventArgs e)
        {
            // horisontal: form width = max object width - 18
            // vertical: form height = max object height - 48
            // textBox1.Text = 3.ToString();
            //MountainNumber.Text = 1.ToString();
            //RiverNumber.Text = 1.ToString();
            //ClinicNumber.Text = 10.ToString();
            //PitNumber.Text = 10.ToString();
            //proprietorExists.Checked = true;
            //eggExists.Checked = true;
            //elfExists.Checked = true;
            //hatExists.Checked = true;
            //ozoneExists.Checked = true;
            //combatForceOptions.SelectedIndex = 1;
            //killOptions.SelectedIndex = 2;

            if (killOptions.SelectedIndex < 0)
            {
                MessageBox.Show("Please choose kill options", "Warning: No choice of kill options");
                return;
            }
            if (combatForceOptions.SelectedIndex < 0)
            {
                MessageBox.Show("Please choose combat force options", "Warning: No choice of combat options");
                return;
            }
            Random random = new Random(Guid.NewGuid().GetHashCode());

            BattleField.Top    = groupBox1.Top;
            BattleField.Left   = groupBox1.Left;
            BattleField.Width  = Width - groupBox1.Left - 10 - 10;
            BattleField.Height = Height - groupBox1.Top - 35 - 10;
            groupBox1.Visible  = false;
            //groupBox2.Visible = false;
            Result.Visible      = false;
            BattleField.Visible = true;
            Result.Visible      = false;
            Result.Rows.Clear();

            #region player initialization
            players = new PlayerGroup();
            StreamReader PlayerName;
            try
            {
                PlayerName = new StreamReader(@"./PlayerName.txt");
            }
            catch (FileNotFoundException)
            {
                MessageBox.Show(@"请确认PlayerName.txt和此程序在同一路径。", "未发现PlayerName.txt");
                CleanUp();
                return;
            }
            int    order    = 0;
            string nameTemp = "";
            while (!PlayerName.EndOfStream)
            {
                nameTemp = PlayerName.ReadToEnd();
            }
            string[] names = nameTemp.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
            if (names.Length <= 1)
            {
                MessageBox.Show("请添加至少2名玩家。", "玩家太少啦");
                CleanUp();
                return;
            }
            Player.PlayerNumber         = names.Length;
            Player.PlayerRemainedNumber = names.Length;
            foreach (var name in names)
            {
                var p = new Player(order, combatForceOptions.SelectedIndex, BattleField, (int)TeamNumber.Value)
                {
                    PlayerName = name
                };
                p.PlayerLabel.Text = $"{p.Team.ToString()} {p.PlayerName} {p.CombatForceLevel.ToString()}";
                players.AddPlayer(p);
                ++order;
            }
            PlayerName.Close();

            if (proprietorExists.Checked)
            {
                proprieter = new Proprieter(BattleField);
                players.AddPlayer(proprieter);
            }
            if (eggExists.Checked)
            {
                egg = new Egg(BattleField);
                players.AddPlayer(egg);
            }
            if (elfExists.Checked)
            {
                elf = new Elf(BattleField);
                players.AddPlayer(elf);
            }
            if (hatExists.Checked)
            {
                hat = new Hat(combatForceOptions.SelectedIndex, BattleField);
                players.AddPlayer(hat);
            }
            if (ozoneExists.Checked)
            {
                ozone = new Ozone(combatForceOptions.SelectedIndex, BattleField);
                players.AddPlayer(ozone);
            }
            #endregion

            int Temp;
            if (!int.TryParse(MountainNumber.Text, out Temp))
            {
                MessageBox.Show("Invalid mountain number");
                CleanUp();
                MountainNumber.Text = "山的数量";
                return;
            }
            else
            {
                Temp      = Temp <= 0 ? 1 : Temp;
                mountains = new Mountain[Temp];
                double switchL = 5 * (Math.Atan(-Temp / 10) / 2 + Math.PI / 4);
                for (int i = 0; i < Temp; i++)
                {
                    int rand = random.Next(5);
                    mountains[i] = new Mountain(rand, switchL, BattleField);
                }
            }// Mountain
            if (!int.TryParse(RiverNumber.Text, out Temp))
            {
                MessageBox.Show("Invalid river number");
                CleanUp();
                RiverNumber.Text = "河的数量";
                return;
            }
            else
            {
                Temp   = Temp <= 0 ? 1 : Temp;
                rivers = new River[Temp];
                double switchL = 5 * (Math.Atan(-Temp / 10) / 8 + Math.PI / 16);
                for (int i = 0; i < Temp; i++)
                {
                    rivers[i] = new River(switchL, BattleField);
                }
            }// River
            if (!int.TryParse(ClinicNumber.Text, out Temp))
            {
                MessageBox.Show("Invalid clinic number");
                CleanUp();
                ClinicNumber.Text = "医疗站数量";
                return;
            }
            else
            {
                Temp    = Temp <= 0 ? 1 : Temp;
                clinics = new Clinic[Temp];
                Clinic.NumberOfClinic = Temp;
                for (int i = 0; i < Temp; i++)
                {
                    clinics[i] = new Clinic(10, 10, BattleField);
                }
            }// Clinic
            if (!int.TryParse(PitNumber.Text, out Temp))
            {
                MessageBox.Show("Invalid pit number");
                CleanUp();
                PitNumber.Text = "坑的数量";
                return;
            }
            else
            {
                Temp = Temp <= 0 ? 1 : Temp;
                pits = new Pit[Temp];
                for (int i = 0; i < Temp; i++)
                {
                    pits[i] = new Pit(i, 10, 10, BattleField);
                }
            }// Pit

            isGenerated              = true;
            playerRemained.Text      = players.Count.ToString();
            Number.Text              = Player.PlayerNumber.ToString();
            RandomGeneration.Enabled = false;
            generation.Enabled       = false;
            start.Enabled            = true;
            clear.Enabled            = true;
        }
コード例 #3
0
        private void Generation_Click(object sender, EventArgs e)
        {
            // horisontal: form width = max object width - 18
            // vertical: form height = max object height - 48
            textBox1.Text                    = 3.ToString();
            MountainNumber.Text              = 40.ToString();
            RiverNumber.Text                 = 20.ToString();
            ClinicNumber.Text                = 10.ToString();
            PitNumber.Text                   = 10.ToString();
            proprietorExists.Checked         = true;
            eggExists.Checked                = true;
            elfExists.Checked                = true;
            hatExists.Checked                = true;
            ozoneExists.Checked              = true;
            combatForceOptions.SelectedIndex = 2;



            if (combatForceOptions.SelectedIndex < 0)
            {
                MessageBox.Show("Please choose combat force options", "Warning: No choice of combat options");
                return;
            }
            Random random = new Random(Guid.NewGuid().GetHashCode());

            BattleField.Top     = groupBox1.Top;
            BattleField.Left    = groupBox1.Left;
            BattleField.Width   = this.Width - groupBox1.Left - 10 - 10;
            BattleField.Height  = this.Height - groupBox1.Top - 35 - 10;
            groupBox1.Visible   = false;
            groupBox2.Visible   = false;
            BattleField.Visible = true;

            int Temp = 0;

            if (!int.TryParse(textBox1.Text, out Temp))
            {
                textBox1.Text = "Invalid input";
                return;
            }
            else
            {
                Player.PlayerNumber  = Temp;
                playerRemainedNumber = Temp;

                if (proprietorExists.Checked)
                {
                    proprieter = new Proprieter(BattleField);
                }
                if (eggExists.Checked)
                {
                    egg = new Egg(BattleField);
                }
                if (elfExists.Checked)
                {
                    elf = new Elf(BattleField);
                }
                if (hatExists.Checked)
                {
                    hat = new Hat(combatForceOptions.SelectedIndex, BattleField);
                }
                if (ozoneExists.Checked)
                {
                    ozone = new Ozone(combatForceOptions.SelectedIndex, BattleField);
                }

                players = new Player[Temp];
                StreamReader PlayerName = new StreamReader(@"./PlayerName.txt");
                for (int i = 0; i < Temp; i++)
                {
                    players[i] = new Player(i, combatForceOptions.SelectedIndex, BattleField);
                    players[i].PlayerLabel.Text =
                        PlayerName.ReadLine() + " " + players[i].CombatForceLevel.ToString();
                }
                PlayerName.Close();

                // Horizontal Order Sorting
                for (int i = 0; i < Player.PlayerNumber; i++)
                {
                    for (int j = 0; j < Player.PlayerNumber; j++)
                    {
                        if (players[i].PlayerLabel.Left > players[j].PlayerLabel.Left && players[i].HorizontalOrder < players[j].HorizontalOrder)
                        {
                            int temp = players[i].HorizontalOrder;
                            players[i].HorizontalOrder = players[j].HorizontalOrder;
                            players[j].HorizontalOrder = temp;
                        }
                    }
                    if (proprietorExists.Checked)
                    {
                        int temp = random.Next(14);
                        if (temp == 0)
                        {
                            switch (proprieter.FistProprieter)
                            {
                            case 0: players[i].FingerGuessState = 2; break;

                            case 1: players[i].FingerGuessState = 0; break;

                            case 2: players[i].FingerGuessState = 1; break;

                            default: break;
                            }
                        }
                        else if (temp < 4)
                        {
                            players[i].FingerGuessState = proprieter.FistProprieter;
                        }
                        else
                        {
                            switch (proprieter.FistProprieter)
                            {
                            case 0: players[i].FingerGuessState = 1; break;

                            case 1: players[i].FingerGuessState = 2; break;

                            case 2: players[i].FingerGuessState = 0; break;

                            default: break;
                            }
                        }
                    }
                }
            }// player number
            if (!int.TryParse(MountainNumber.Text, out Temp))
            {
                MountainNumber.Text = "Invalid input";
                return;
            }
            else
            {
                mountains = new Mountain[Temp];
                double switchL = 5 * (Math.Atan(-Temp / 10) / 2 + Math.PI / 4);
                for (int i = 0; i < Temp; i++)
                {
                    mountains[i] = new Mountain(Temp, switchL, players[0], BattleField);
                }
            }// Mountain
            if (!int.TryParse(RiverNumber.Text, out Temp))
            {
                RiverNumber.Text = "Invalid input";
                return;
            }
            else
            {
                rivers = new River[Temp];
                double switchL = 5 * (Math.Atan(-Temp / 10) / 8 + Math.PI / 16);
                for (int i = 0; i < Temp; i++)
                {
                    rivers[i] = new River(Temp, switchL, players[0], BattleField);
                }
            }// River
            if (!int.TryParse(ClinicNumber.Text, out Temp))
            {
                ClinicNumber.Text = "Invalid input";
                return;
            }
            else
            {
                clinics = new Clinic[Temp];
                for (int i = 0; i < Temp; i++)
                {
                    clinics[i] = new Clinic(10, 10, BattleField);
                }
            }// Clinic
            if (!int.TryParse(PitNumber.Text, out Temp))
            {
                PitNumber.Text = "Invalid input";
                return;
            }
            else
            {
                pits = new Pit[Temp];
                for (int i = 0; i < Temp; i++)
                {
                    pits[i] = new Pit(10, 10, BattleField);
                }
            }// Pit

            isGenerated         = true;
            playerRemained.Text = playerRemainedNumber.ToString();
            generation.Enabled  = false;
            start.Enabled       = true;
            clear.Enabled       = true;
        }