/// <summary>Method: homeTeamToolStripMenuItem1
        /// Change the color of home team
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void homeTeamToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            model.homeTeamCount++;
            int xp = 0;
            int yp = 0;

            if (mouseLocation != null)
            {
                xp = mouseLocation.X - (model.pieceW / 2);
                yp = mouseLocation.Y - (model.pieceH / 2);
            }
            Color  c      = model.homeTeamColor;
            string n      = "player" + model.homeTeamCount.ToString();
            Player player = new Player(n, xp, yp, model.pieceW, model.pieceH, c, model.homeTeamCount, true);

            model.AddPiece(player);
        }
Esempio n. 2
0
        /// <summary>Method: btnCreate_Click
        /// Create piece to piecelist
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCreate_Click(object sender, EventArgs e)
        {
            string o             = string.Empty;
            var    checkedButton = Controls.OfType <RadioButton>()
                                   .FirstOrDefault(r => r.Checked);

            if (checkedButton == null)
            {
                MessageBox.Show("Please select the object first");
                return;
            }
            string obj = checkedButton.Text;

            if (txbX.Text.Equals(o) || txbY.Text.Equals(o))
            {
                MessageBox.Show("Please type in the position of X and Y");
                return;
            }
            int x = Convert.ToInt32(txbX.Text);
            int y = Convert.ToInt32(txbY.Text);

            if (x > max_X || y > max_Y)
            {
                MessageBox.Show("Maximum value for X is " + max_X
                                + "\r\n" + "Maximum value for Y is " + max_Y + "\r\n",
                                "Please Check the Values Entered",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (obj.Equals("Player"))
            {
                string side = cbbPlayerType.Text;
                string name = txbName.Text;
                if (!cbbColor.Text.Equals(o))
                {
                    if (side.Equals("Home"))
                    {
                        model.homeTeamColor = Color.FromName(cbbColor.Text);
                    }
                    else
                    {
                        model.awayTeamColor = Color.FromName(cbbColor.Text);
                    }
                }
                if (side.Equals(o) || name.Equals(o) || txbNumber.Text.Equals(o))
                {
                    MessageBox.Show("Please select side and type in a number and a name.");
                    return;
                }
                int   number = Convert.ToInt32(txbNumber.Text);
                Color c;
                bool  type;
                if (side.Equals("Home"))
                {
                    if (model.checkExceedMax("home team"))
                    {
                        MessageBox.Show("The maximum of a team is " + model.max_team_players + ". You cannot add any more.");
                        return;
                    }
                    c    = model.homeTeamColor;
                    type = true;
                    model.homeTeamCount++;
                }
                else
                {
                    if (model.checkExceedMax("away team"))
                    {
                        MessageBox.Show("The maximum of a team is " + model.max_team_players + ". You cannot add any more.");
                        return;
                    }
                    c    = model.awayTeamColor;
                    type = false;
                    model.awayTeamCount++;
                }
                Player player = new Player(name, x, y, model.pieceW, model.pieceH, c, number, type);
                model.AddPiece(player);
            }
            else if (obj.Equals("Ball"))
            {
                if (cbbBallType.Text.Equals(o))
                {
                    MessageBox.Show("Please type in the type of ball");
                    return;
                }
                if (model.checkExceedMax("ball"))
                {
                    MessageBox.Show("The maximum of ball is " + model.max_ball + ". You cannot add any more.");
                    return;
                }
                string name = "Ball";
                model.ballCount++;
                Ball.ImageType type = (cbbBallType.Text.Equals("White")) ? Ball.ImageType.White : Ball.ImageType.Orange;
                Ball           ball = new Ball(name, x, y, model.pieceW, model.pieceH, type);
                model.AddPiece(ball);
            }
            else if (obj.Equals("Referee"))
            {
                if (cbbRefereeType.Text.Equals(o))
                {
                    MessageBox.Show("Please type in the type of referee");
                    return;
                }
                string name;
                string ref_type;
                if (cbbRefereeType.Text.Equals("Main"))
                {
                    if (model.checkExceedMax("main referee"))
                    {
                        MessageBox.Show("The maximum of main referee is " + model.max_main_referee + ". You cannot add any more.");
                        return;
                    }
                    model.mainRefereeCount++;
                    name     = "Referee";
                    ref_type = "R";
                }
                else
                {
                    if (model.checkExceedMax("assistant referee"))
                    {
                        MessageBox.Show("The maximum of assistant referee is " + model.max_assistant_referee + ". You cannot add any more.");
                        return;
                    }
                    model.assistantRefereeCount++;
                    name     = "Assistant Referee " + model.assistantRefereeCount;
                    ref_type = "A";
                }
                Color   c       = Color.Black;
                Referee referee = new Referee(name, x, y, model.pieceW, model.pieceH, c, ref_type);
                model.AddPiece(referee);
            }
        }