// Checks if the last delivery completed the over, if so the total overs are updated to the next highest round number */ public bool Check_End_Of_Over(List<Player> batList, List<Player> bowlList, List<Innings> inningsList, List<Over> overAnalysisList, List<FallOfWicket> fallOfWicketList, int inningsId, string folderName) { bool endOfOver = false; Player player = new Player(); int bowlId = player.Check_Bowler_Bowling(bowlList, inningsList[inningsId].topBowlId, inningsList[inningsId].bottomBowlId); double oversTotal = Math.Round(inningsList[inningsId].Innings_Overs, 1); double Updated_Over_Amount = oversTotal; double test_total = Math.Round((oversTotal - Math.Truncate(oversTotal)), 1); if (test_total == .6) { Updated_Over_Amount = Math.Ceiling(Updated_Over_Amount); } if (Updated_Over_Amount - Math.Truncate(Updated_Over_Amount) == 0) { bowlList[bowlId].Bowl_Overs = Math.Ceiling(bowlList[bowlId].Bowl_Overs); inningsList[inningsId].Innings_Overs = Math.Ceiling(inningsList[inningsId].Innings_Overs); // Check if completed over was a maiden, if not set maiden flag back to true for next over if (inningsList[inningsId].maiden) { // Add 1 to the innings and bowler's maidens inningsList[inningsId].Bowl_Total_Maidens = inningsList[inningsId].Bowl_Total_Maidens + 1; bowlList[bowlId].Bowl_Maidens = bowlList[bowlId].Bowl_Maidens + 1; } else { inningsList[inningsId].maiden = true; } // Convert over number from double to int to allow new line to be added to Over Analysis table inningsList[inningsId].Over_Analysis_Overs = Convert.ToInt32(inningsList[inningsId].Innings_Overs); Over over = new Over(); over.Create_Over(inningsList[inningsId].Over_Analysis_Overs, (bowlId) + 1, inningsList[inningsId].Over_Analysis_Runs, inningsList[inningsId].Over_Analysis_Wickets); overAnalysisList.Add(over); // Save the over to a new text file over.Save_Over(fallOfWicketList, batList, bowlList, inningsList, overAnalysisList, inningsId, folderName); endOfOver = true; } return endOfOver; }
// Saves all objects into separate text files to create a backup for the system public void Save_Over(List<FallOfWicket> fallOfWicketList, List<Player> batList, List<Player> bowlList, List<Innings> inningsList, List<Over> overAnalysisList, int inningsId, string folderName) { // Save player objects to file Player player = new Player(); player.Save_Batsmen(batList, inningsList[inningsId].Team_Name, folderName); player.Save_Bowlers(bowlList, inningsList[inningsId].Team_Name, folderName); // Save fall of wicket objects to file FallOfWicket fallOfWicket = new FallOfWicket(); fallOfWicket.Save_Fall_Of_Wicket_List(fallOfWicketList, inningsList[inningsId].Team_Name, folderName); // Save over analysis objects to file Save_Over_Analysis(overAnalysisList, inningsList[inningsId].Team_Name, folderName); // Save innings objects to file Innings innings = new Innings(); innings.Save_Innings(folderName, inningsId, inningsList, fallOfWicketList); }
/* When the user selects the new bowler's name and clicks the select button, * this function checks if the bowler being replaced is in the top row of the current bowlers * tables, if so the function swaps the bottom bowler details to the top row and inserts * the new bowler into the bottom row. */ private void New_Bowler_Select_Click(object sender, EventArgs e) { if (Verify_Combo_Selection(New_Bowler_Combo_Box)) { Create_Undo_Point(); Player player = new Player(); // Get new bowler name and Id. string newBowlerName = New_Bowler_Combo_Box.SelectedItem.ToString(); int newBowlerId = player.Get_Bowler_Id(BowlList, newBowlerName); if (BowlList[InningsList[Innings_Id].topBowlId].Bowl_Bowling) { New_Bowler_Change_Top_Bowler(); } if (newBowlerId > -1) { InningsList[Innings_Id].bottomBowlId = newBowlerId; } else { player.Create_Bowler((BowlList.Last().Bowl_Number) + 1, newBowlerName, true); InningsList[Innings_Id].bottomBowlId = BowlList.Last().Bowl_Number; BowlList.Add(player); } Update_Bowler_Bottom(); Current_Bowler_Number_Bottom.BackColor = Color.White; New_Bowler_Combo_Box.Text = "Select New Bowler"; } HideAllPanels(); }
/* When a wicket is taken the application updates the Last Man Out table, Fall Of Wicket table and the batting tables. * 1. Adds 1 ball to the batsman, bowler and total overs * 2. Adds 1 to bowler and total wickets if batsman is 'caught', 'bowled', 'lbw', 'stumped' or 'caught and bowled' * 3. Adds 1 to total wickets if batsman is 'run out' or 'retired' */ public void WicketTaken(string wicketType, string fielder_Name, bool crossed, int outBatId, int notOutBatId, int bowlId) { Player player = new Player(); bool newBatFacing = true; // add ball to bowler and out batsman player.Bowling_Add_Ball(BowlList, bowlId); player.Batting_Add_Ball(BatList, outBatId); //add wicket to bowler and total innings wickets if (wicketType != "runOut") { BowlList[bowlId].Bowl_Wickets = BowlList[bowlId].Bowl_Wickets + 1; } InningsList[Innings_Id].Innings_Wickets = InningsList[Innings_Id].Innings_Wickets + 1; // Used to update the last man out table in Update_Score() Last_Bat_Out = outBatId; // Get the fielder and bowler names associated with the wicket. string fielderName = player.Get_Player_Short_Name(fielder_Name); string bowlerName = player.Get_Player_Short_Name(BowlList[bowlId].Bowl_Name); // Checks if the crossed checkbox has been checked if (crossed) { Swap_Batsman(); newBatFacing = false; } else { BatList[outBatId].Bat_Facing = false; Current_Batsman_Number_Top.BackColor = Color.Transparent; Current_Batsman_Number_Bottom.BackColor = Color.White; } switch (wicketType) { case "caught": BatList[outBatId].Bat_How_Out = "Ct " + fielderName; BatList[outBatId].Bat_Out_Bwlr = bowlerName; InningsList[Innings_Id].Bowl_Total_Wickets = InningsList[Innings_Id].Bowl_Total_Wickets + 1; break; case "runOut": BatList[outBatId].Bat_How_Out = "Run Out"; BatList[outBatId].Bat_Out_Bwlr = fielderName; break; case "bowled": BatList[outBatId].Bat_How_Out = "Bowled"; BatList[outBatId].Bat_Out_Bwlr = bowlerName; InningsList[Innings_Id].Bowl_Total_Wickets = InningsList[Innings_Id].Bowl_Total_Wickets + 1; break; case "stumped": BatList[outBatId].Bat_How_Out = "Stumped"; BatList[outBatId].Bat_Out_Bwlr = bowlerName; InningsList[Innings_Id].Bowl_Total_Wickets = InningsList[Innings_Id].Bowl_Total_Wickets + 1; break; case "lbw": BatList[outBatId].Bat_How_Out = "LBW"; BatList[outBatId].Bat_Out_Bwlr = bowlerName; InningsList[Innings_Id].Bowl_Total_Wickets = InningsList[Innings_Id].Bowl_Total_Wickets + 1; break; case "caughtAndBowled": BatList[outBatId].Bat_How_Out = "Ct && Bwld"; BatList[outBatId].Bat_Out_Bwlr = bowlerName; InningsList[Innings_Id].Bowl_Total_Wickets = InningsList[Innings_Id].Bowl_Total_Wickets + 1; break; case "retired": BatList[outBatId].Bat_How_Out = "Retired"; BatList[outBatId].Bat_Out_Bwlr = "Out"; break; } FallOfWicket fallOfWicket = new FallOfWicket(); fallOfWicket.Create_Fall_Of_Wicket(InningsList, BatList, Innings_Id, outBatId, notOutBatId); FallOfWicketList.Add(fallOfWicket); fallOfWicket.Save_Fall_Of_Wicket_List(FallOfWicketList, InningsList[Innings_Id].Team_Name, this.folderName); if (InningsList[Innings_Id].Innings_Wickets < 10) { // Checks if the Current Batsman table rows need to be swapped. // Only if the batting side has wickets in hand if (outBatId < notOutBatId) { Wicket_Change_Top_Batsman(); } // Adds new batsman object into the table and list with Id one greater than the batsman on the bottom row. Player newBatsman = new Player(); newBatsman.Create_Batsman((BatList[InningsList[Innings_Id].bottomBatId].Bat_Number + 1), (Wicket_Next_Bat_Combo_Box.SelectedItem.ToString()), newBatFacing); BatList.Add(newBatsman); Update_Next_Batsman_List(newBatsman.Bat_Name); InningsList[Innings_Id].bottomBatId = InningsList[Innings_Id].bottomBatId + 1; Update_Batsman_Bottom(); InningsList[Innings_Id].Over_Analysis_Wickets = InningsList[Innings_Id].Over_Analysis_Wickets + 1; } Innings innings = new Innings(); if (innings.Check_End_Of_Innings(Innings_Id, InningsList)) { End_Of_Innings(); } }
/* When a wicket is taken, this function is called to ensure that the correct batsman is selected as out * and that the correct players from the fielding side are referenced for the wicket. */ private void WicketButtonClick(string howOut, string fielder_Name, bool crossed) { Player player = new Player(); Create_Undo_Point(); // Add one ball to total over amount InningsList[Innings_Id].Innings_Overs = InningsList[Innings_Id].Innings_Overs + 0.1; if (howOut == "runOut") { if (Radio_Run_Out_Bat_Top.Checked) { WicketTaken(howOut, fielder_Name, crossed, InningsList[Innings_Id].topBatId, InningsList[Innings_Id].bottomBatId, player.Check_Bowler_Bowling(BowlList, InningsList[Innings_Id].topBowlId, InningsList[Innings_Id].bottomBowlId)); } else if (Radio_Run_Out_Bat_Bottom.Checked) { WicketTaken(howOut, fielder_Name, crossed, InningsList[Innings_Id].bottomBatId, InningsList[Innings_Id].topBatId, player.Check_Bowler_Bowling(BowlList, InningsList[Innings_Id].topBowlId, InningsList[Innings_Id].bottomBowlId)); } } else { if (BatList[InningsList[Innings_Id].topBatId].Bat_Facing == true) { WicketTaken(howOut, fielder_Name, crossed, InningsList[Innings_Id].topBatId, InningsList[Innings_Id].bottomBatId, player.Check_Bowler_Bowling(BowlList, InningsList[Innings_Id].topBowlId, InningsList[Innings_Id].bottomBowlId)); } else { WicketTaken(howOut, fielder_Name, crossed, InningsList[Innings_Id].bottomBatId, InningsList[Innings_Id].topBatId, player.Check_Bowler_Bowling(BowlList, InningsList[Innings_Id].topBowlId, InningsList[Innings_Id].bottomBowlId)); } } // Check if delivery was last in the over, then update the FOW table and all other tables and hide all flow panels End_OF_Over_Check(); Update_Innings_Fall_Of_Wicket(); Update_Score(); HideAllPanels(); // Check end of innings. Innings innings = new Innings(); if (innings.Check_End_Of_Innings(Innings_Id, InningsList)) { End_Of_Innings(); } }
// Function to update the last man out table private void Update_Last_Man_Out_Table() { // Updates Last Man Out table, if no wickets taken then table is blank if (InningsList[Innings_Id].Innings_Wickets == 0) { Out_Batsman_Number_Value.Text = ""; Out_Batsman_Name.Text = ""; Out_Batsman_How_Out_Value.Text = ""; Out_Batsman_Bowler_Value.Text = ""; Out_Batsman_Total_Runs_Scored_Value.Text = ""; } else { Player player = new Player(); Out_Batsman_Number_Value.Text = BatList[Last_Bat_Out].Bat_Number.ToString(); Out_Batsman_Name.Text = player.Get_Player_Short_Name(BatList[Last_Bat_Out].Bat_Name); Out_Batsman_How_Out_Value.Text = BatList[Last_Bat_Out].Bat_How_Out; Out_Batsman_Bowler_Value.Text = BatList[Last_Bat_Out].Bat_Out_Bwlr; Out_Batsman_Total_Runs_Scored_Value.Text = BatList[Last_Bat_Out].Bat_Runs.ToString(); } }
// Inintialises all variables at the start of an innings private void Set_Default_Variables() { HideAllPanels(); Innings innings = new Innings(); innings.Create_Innings(MatchDetailsList, Toss_Winner_Combo_Box.SelectedItem.ToString(), Innings_Of); InningsList.Add(innings); // Gets the team name for the second innings GraphSeriesList.Add(InningsList[Innings_Id].Team_Name); Over over = new Over(); over.Create_Over(0,0,0,0); OverAnalysisList.Add(over); // Sets Extra table details Wides_Total_Value.Text = innings.Extras_Wides.ToString(); No_Balls_Total_Value.Text = innings.Extras_No_Balls.ToString(); Byes_Total_Value.Text = innings.Extras_Byes.ToString(); Leg_Byes_Total_Value.Text = innings.Extras_Leg_Byes.ToString(); Penaltys_Total_Value.Text = innings.Extras_Penaltys.ToString(); Total_Extras_Value.Text = innings.Extras_Total.ToString(); // Sets match details Scoring_Date_Value.Text = innings.Date; Scoring_Innings_Of_Value.Text = InningsList[Innings_Id].Team_Name; Scoring_Total_Value.Text = innings.Innings_Total.ToString(); Scoring_Wickets_Down_Value.Text = innings.Innings_Wickets.ToString(); Scoring_Total_Overs_Value.Text = innings.Innings_Overs.ToString(); // Initialise opening player objects Player batTop = new Player(); Player batBottom = new Player(); Player bowlTop = new Player(); Player bowlBottom = new Player(); if (Innings_Id == 0) { batTop.Create_Batsman((InningsList[0].topBatId + 1), Open_Select_Bat_1.SelectedItem.ToString(), true); batBottom.Create_Batsman((InningsList[0].bottomBatId + 1), Open_Select_Bat_2.SelectedItem.ToString(), false); bowlTop.Create_Bowler((InningsList[0].topBowlId + 1), Open_Select_Bowl_1.SelectedItem.ToString(), true); bowlBottom.Create_Bowler((InningsList[0].bottomBowlId + 1), Open_Select_Bowl_2.SelectedItem.ToString(), false); } else { batTop.Create_Batsman((InningsList[1].topBatId + 1), Open_Select_Bat_1_Inn_2.SelectedItem.ToString(), true); batBottom.Create_Batsman((InningsList[1].bottomBatId + 1), Open_Select_Bat_2_Inn_2.SelectedItem.ToString(), false); bowlTop.Create_Bowler((InningsList[1].topBowlId + 1), Open_Select_Bowl_1_Inn_2.SelectedItem.ToString(), true); bowlBottom.Create_Bowler((InningsList[1].bottomBowlId + 1), Open_Select_Bowl_2_Inn_2.SelectedItem.ToString(), false); } BatList.Add(batTop); BatList.Add(batBottom); BowlList.Add(bowlTop); BowlList.Add(bowlBottom); Update_Next_Batsman_List(batTop.Bat_Name); Update_Next_Batsman_List(batBottom.Bat_Name); Create_Graphs(); Update_Last_Man_Out_Table(); }