// Gets the button type, number of runs and if runs are off the bat. Calls button handler to update scores. private void General_Button_Click(string buttonTypeClicked,bool batUsed, int runs) { Create_Undo_Point(); ButtonHandler button = new ButtonHandler(); button.GeneralButtonClickHandler(BatList, BowlList, InningsList, OverAnalysisList, FallOfWicketList, Innings_Id, folderName, buttonTypeClicked, batUsed, runs); if (((buttonTypeClicked == "wide" || buttonTypeClicked == "noBall") && (runs % 2 == 0)) || ((buttonTypeClicked == "legBye" || buttonTypeClicked == "bye" || buttonTypeClicked == "runs") && (runs % 2 == 1))) { Swap_Batsman(); } // Check if delivery was last in the over if (buttonTypeClicked == "runs" || buttonTypeClicked == "bye" || buttonTypeClicked == "legBye" || buttonTypeClicked == "penalty") { End_OF_Over_Check(); } //Update tables and hide all flow panels Update_Score(); HideAllPanels(); // Check end of innings. Innings innings = new Innings(); if (innings.Check_End_Of_Innings(Innings_Id, InningsList)) { End_Of_Innings(); } }
/* 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(); } }
private void End_OF_Over_Check() { Over over = new Over(); if (over.Check_End_Of_Over(BatList, BowlList, InningsList, OverAnalysisList, FallOfWicketList, Innings_Id, folderName)) { Update_Innings_Over_Analysis(); Create_Graphs(); // Swap batsmen and bowlers for start of new over Swap_Batsman(); Swap_Bowler(); // Check if end of innings has been reached 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(); } }