/// <summary>Method: checkMenuItems /// According to the Number of Pieces to set the correct Menu Item status /// </summary> private void checkMenuItems() { /// The number of a team is from 0 to 18 ///////////// /// The number of main referee is only 1 or 0 //////// /// The number of assistant referee is from 0 to 4 /// /// The number of ball is only 1 or 0 //////////////// // create player : home team homeTeamToolStripMenuItem1.Enabled = model.checkExceedMax("home team") ? false : true; // create player : away team awayTeamToolStripMenuItem1.Enabled = model.checkExceedMax("away team") ? false : true; // Parent item: playerToolStripMenuItem.Enabled = (homeTeamToolStripMenuItem1.Enabled || awayTeamToolStripMenuItem1.Enabled) ? true : false; // create home team homeTeamToolStripMenuItem.Enabled = (model.homeTeamCount < 1) ? true : false; // create away team awayTeamToolStripMenuItem.Enabled = (model.awayTeamCount < 1) ? true : false; // Parent item: teamToolStripMenuItem.Enabled = (homeTeamToolStripMenuItem.Enabled || awayTeamToolStripMenuItem.Enabled) ? true : false; // create main referee mainRefereeToolStripMenuItem.Enabled = model.checkExceedMax("main referee") ? false : true; // create assistant referee assistantRefereeToolStripMenuItem.Enabled = model.checkExceedMax("assistant referee") ? false : true; // Parent item: refereeToolStripMenuItem.Enabled = (mainRefereeToolStripMenuItem.Enabled || assistantRefereeToolStripMenuItem.Enabled) ? true : false; // creat ball ballToolStripMenuItem.Enabled = model.checkExceedMax("ball") ? false : true; }
/// <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); } }