/// <summary>Method: deleteWholeTeam /// Delete the whole team of seleted player /// </summary> /// <param name="p"></param> private void deleteWholeTeam(Player p) { for (int i = model.PieceList.Count; i > 0; i--) { APiece ap = (APiece)model.PieceList[i - 1]; if (!(ap is Player)) { continue; } Player player = (Player)ap; if (player.IsHomeTeam == p.IsHomeTeam) { try { model.PieceList.RemoveAt(i - 1); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } } if (p.IsHomeTeam) { model.homeTeamCount = 0; } else { model.awayTeamCount = 0; } model.UpdateViews(); }
/// <summary>Method: pnlField_MouseDoubleClick /// Main Referee whistle /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void pnlField_MouseDoubleClick(object sender, MouseEventArgs e) { ArrayList pl = model.PieceList; foreach (APiece p in pl) { Point m = new Point(e.X, e.Y); if (!(p is Referee)) { continue; } Referee r = (Referee)p; if (r.Type.Equals("R")) { if (r.HitTest(m)) { r.Highlight = true; editPiece = r; model.BringToFront(r); r.Whistle(); break; } } } }
/// <summary>Method: deleteToolStripMenuItem1 /// Delete selected Referee /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void deleteToolStripMenuItem1_Click(object sender, EventArgs e) { if (editPiece != null && editPiece is Referee) { Referee r = (Referee)editPiece; if (r.Type.Equals("R")) { model.mainRefereeCount--; } else if (r.Type.Equals("A")) { model.assistantRefereeCount--; } else { Console.WriteLine("Referee Type Error."); } try { model.DeletePiece(r); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } editPiece = null; } }
/// <summary>method: DeletePiece /// Delete a piece from the views /// </summary> /// <param name="aPiece"></param> public void DeletePiece(APiece aPiece) { if (aPiece is Player) { Player p = (Player)aPiece; if (p.IsHomeTeam) { homeTeamCount--; } else { awayTeamCount--; } } else if (aPiece is Ball) { ballCount--; } else if (aPiece is Referee) { Referee r = (Referee)aPiece; if (r.Type.Equals("R")) { mainRefereeCount--; } else { assistantRefereeCount--; } } pieceList.Remove(aPiece); UpdateViews(); }
/// <summary>Method: deleteToolStripMenuItem2_Click /// Delete the ball /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void deleteToolStripMenuItem2_Click(object sender, EventArgs e) { if (editPiece != null && editPiece is Ball) { try { model.DeletePiece(editPiece); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } editPiece = null; model.ballCount = 0; } }
/// <summary>Method: deleteToolStripMenuItem_Click /// Delete selected player /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void deleteToolStripMenuItem_Click(object sender, EventArgs e) { if (editPiece != null && editPiece is Player) { Player p = (Player)editPiece; if (p.IsHomeTeam) { model.homeTeamCount--; } else { model.awayTeamCount--; } model.DeletePiece(p); editPiece = null; } }
/// <summary>Method: pnlField_MouseDown /// check if mouse is over piece and set variable to /// enable piece to be moved /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void pnlField_MouseDown(object sender, MouseEventArgs e) { currentPosition = new Point(e.X, e.Y); if (e.Button == MouseButtons.Right) { return; } if (e.Button == MouseButtons.Left) { topPiece = null; ArrayList pl = model.PieceList; for (int i = pl.Count; i > 0; i--) { APiece p = (APiece)pl[i - 1]; Point m = new Point(e.X, e.Y); if (p.HitTest(m)) { dragging = true; p.Highlight = true; topPiece = p; model.BringToFront(topPiece); break; } } try { APiece pre; if (topPiece != null) { pre = (APiece)pl[pl.Count - 2]; } else { pre = (APiece)pl[pl.Count - 1]; } pre.Highlight = false; } catch (ArgumentOutOfRangeException) { } RefreshView(); } }
/// <summary>Method: deleteAllReferees /// Delete all Referees /// </summary> private void deleteAllReferees() { for (int i = model.PieceList.Count; i > 0; i--) { APiece ap = (APiece)model.PieceList[i - 1]; if (!(ap is Referee)) { continue; } try { model.PieceList.RemoveAt(i - 1); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } model.mainRefereeCount = 0; model.assistantRefereeCount = 0; model.UpdateViews(); }
/// <summary>method: SendToBack /// method to resequence arrayList so selected piece is /// drawn first /// </summary> /// <param name="aPiece"></param> public void SendToBack(APiece aPiece) { // first Piece drawn is at the back // temp arrayList to resort Pieces so selected Piece is drawn first ArrayList sortList = new ArrayList(); // find index of Piece to be drawn first int max = pieceList.IndexOf(aPiece); // first Piece i.e. Piece to send to back sortList.Add(aPiece); // copy to sortList in correct sequence for (int i = 0; i < max; i++) { sortList.Add(pieceList[i]); } // copy sortList back to PieceList for (int i = 0; i < sortList.Count; i++) { pieceList[i] = sortList[i]; } //UpdateViews(); }
/// <summary>method: BringToFront /// method to resequence arrayList so selected piece is /// drawn last /// </summary> /// <param name="aPiece"></param> public void BringToFront(APiece aPiece) { // last Piece drawn is at the front // temp arrayList to resort Pieces so selected Piece is drawn last ArrayList sortList = new ArrayList(pieceList); // find index of Piece to be drawn last int max = pieceList.IndexOf(aPiece); // find length of PieceList array int length = pieceList.Count; // copy PieceList to sortList excluding selected Piece for (int i = max + 1; i < length; i++) { sortList[i - 1] = pieceList[i]; } // last Piece i.e. Piece to bring to front sortList[length - 1] = pieceList[max]; // copy sortList back to PieceList for (int i = 0; i < sortList.Count; i++) { pieceList[i] = sortList[i]; } //UpdateViews(); }
/// <summary>Method: pnlField_MouseClick /// Check the right click menu and set variable to edit status /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void pnlField_MouseClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { return; } if (txtNumber.Visible) { changePlayerNumber(); // A way to finish editing Number of the editPiece } if (txtName.Visible) { changePlayerName(); // A way to finish editing Name of the editPiece } if (e.Button == MouseButtons.Right) { mouseLocation = e.Location; checkMenuItems(); editPiece = null; ArrayList pl = model.PieceList; for (int i = pl.Count; i > 0; i--) { APiece p = (APiece)pl[i - 1]; Point m = new Point(e.X, e.Y); if (p.HitTest(m)) { p.Highlight = true; editPiece = p; model.BringToFront(p); break; } } try { APiece pre; if (editPiece != null) { pre = (APiece)pl[pl.Count - 2]; } else { pre = (APiece)pl[pl.Count - 1]; } pre.Highlight = false; } catch (ArgumentOutOfRangeException) { } RefreshView(); // Control the content menu Point pt = pnlField.PointToScreen(e.Location); if (editPiece == null) { pt = pnlField.PointToScreen(e.Location); cmsField.Show(pt); } else if (editPiece is Player) { checkColorChecked(); cmsPlayer.Show(pt); } else if (editPiece is Referee) { cmsReferee.Show(pt); } else if (editPiece is Ball) { checkBallTypeChecked(); cmsBall.Show(pt); } } }
/// <summary>method: UpdatePiece /// Update a piece in the views /// </summary> /// <param name="aPiece"></param> public void UpdatePiece(APiece aPiece) { UpdateViews(); }
/// <summary>method: AddPiece /// Add a piece to the views /// </summary> /// <param name="aPiece"></param> public void AddPiece(APiece aPiece) { pieceList.Add(aPiece); UpdateViews(); }