// Added by LiYoubing 20110515 /// <summary> /// 处理某支队伍在己方半场的犯规情况2 /// </summary> /// <param name="team">待处理的仿真使命参与队伍(仿真机器鱼为具体使命的仿真机器鱼)</param> /// <param name="bIsLeftHalfCourt">待判断的是否左球门true判断左球门false判断右球门</param> private void FoulType2Handler(ref Team <Fish1V1> team, bool bIsLeftHalfCourt) { // 犯规的仿真机器鱼在队伍中的索引 List <int> arrFishIndexFouled = new List <int>(); for (int j = 0; j < team.Fishes.Count; j++) { if (IsRoboFishInGoal(team.Fishes[j], bIsLeftHalfCourt)) {// 仿真机器鱼在己方球门内 team.Fishes[j].CountInOwnGoalArea++; } else {// 仿真机器鱼不在己方球门内 team.Fishes[j].CountInOwnGoalArea = 0; } if (team.Fishes[j].CountInOwnGoalArea > CyclesInGoalWhileFouled) {// 仿真机器鱼在己方球门停留一定周期数以上 arrFishIndexFouled.Add(j); } } if (arrFishIndexFouled.Count >= 1) {// 犯规情况2提示 for (int i = 0; i < arrFishIndexFouled.Count; i++) { team.Fishes[arrFishIndexFouled[i]].FoulFlag = FoulType.FOUl2; team.Fishes[arrFishIndexFouled[i]].CountCyclesFouled = 0; team.Fishes[arrFishIndexFouled[i]].CountInOwnGoalArea = 0; MatchHelper.MissionMessageBox(ref MyMission.Instance().MissionRef, string.Format("FoulType2:\n【{0}】Fish {1} Fouled!\n", team.Para.Name, arrFishIndexFouled[i] + 1), "Confirming", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }
// Added by LiYoubing 20110515 /// <summary> /// 处理某支队伍进球的情况 /// </summary> /// <param name="team">待处理的仿真使命参与队伍(仿真机器鱼为具体使命的仿真机器鱼)</param> /// <param name="bIsLeftHalfCourt">待判断的是否左球门true判断左球门false判断右球门</param> private void GoalHandler(ref Team <Fish1V1> team, bool bIsLeftHalfCourt) { MatchHelper.MissionMessageBox(ref MyMission.Instance().MissionRef, string.Format("Congradulations! \nGoaled:【{0}】 in 【{1}】\n", team.Para.Name, team.Para.MyHalfCourt), "Confirming", MessageBoxButtons.OK, MessageBoxIcon.Warning); for (int i = 0; i < CommonPara.TeamCount; i++) {// 解除犯规状态 for (int j = 0; j < CommonPara.FishCntPerTeam; j++) { team.Fishes[j].FoulFlag = FoulType.NONE; team.Fishes[j].CountCyclesFouled = 0; team.Fishes[j].CountInOwnGoalArea = 0; } } if (CommonPara.IsRunning == true) { // 仿真使命运行完毕后Restart之前可以重复按Pause/Continue按钮弹出提示对话框但不必重复计分 team.Para.Score++; // 累积得分 } if (CompetitionPeriod == (int)MatchHelper.CompetitionPeriod.ClutchShotTime || CompetitionPeriod == (int)MatchHelper.CompetitionPeriod.PenaltyKickTime) {// 在点球大战和制胜球阶段进球,比赛结束 CommonPara.IsRunning = false; MessageBox.Show(string.Format("Congradulations!\nCompetition is completed.\nWinner:【{0}】 in 【{1}】\n", team.Para.Name, team.Para.MyHalfCourt), "Confirming", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else {// 恢复默认场景 ResetTeamsAndFishes(); ResetBalls(); ResetSomeLocomotionPara(); } }
/// <summary> /// 防守机器鱼在禁区内犯规时最大停留时间(单位:毫秒) /// </summary> #endregion #region 对抗赛5VS5仿真使命控制规则具体处理过程 #region 进球判断及处理 // Added by renjing 20110310 Modified by LiYoubing 20110515 /// <summary> /// 进球处理 /// </summary> private void GoalHandler() { MyMission mymission = MyMission.Instance(); int j; if (CommonPara.IsExchangedHalfCourt == false) { RoboFish f1 = Teams[0].Fishes[0]; for (j = 1; j < 4; j++) { RoboFish f2 = Teams[1].Fishes[j]; CollisionDetectionResult result = new CollisionDetectionResult(); result = CollisionDetection.DetectCollisionBetweenTwoFishes(ref f1, ref f2); if (result.Intersect == true && gool[j - 1] == 0) { Teams[0].Para.Score++; gool[j - 1] = 1; string strMsg = ""; int Shootouttime = CommonPara.TotalSeconds * 1000 - CommonPara.RemainingCycles * mymission.ParasRef.MsPerCycle; int ShootouttimeSec = Shootouttime / 1000; ltime = Shootouttime; strMsg += string.Format("Congradulations!shootouttime is: {1:00}:{2:00}:{3:00}.", Teams[0].Para.Score, ShootouttimeSec / 60, ShootouttimeSec % 60, Shootouttime % 1000); MatchHelper.MissionMessageBox(ref MyMission.Instance().MissionRef, strMsg, "Confirming", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } else { RoboFish f1 = Teams[1].Fishes[0]; for (j = 1; j < 4; j++) { RoboFish f2 = Teams[0].Fishes[j]; CollisionDetectionResult result = new CollisionDetectionResult(); result = CollisionDetection.DetectCollisionBetweenTwoFishes(ref f1, ref f2); if (result.Intersect == true && goor[j - 1] == 0) { Teams[1].Para.Score++; goor[j - 1] = 1; string strMsg = ""; int Shootouttime = CommonPara.TotalSeconds * 1000 / 2 - CommonPara.RemainingCycles * mymission.ParasRef.MsPerCycle; int ShootouttimeSec = Shootouttime / 1000; rtime = Shootouttime; strMsg += string.Format("Congradulations!shootouttime is: {1:00}:{2:00}:{3:00}.", Teams[0].Para.Score, ShootouttimeSec / 60, ShootouttimeSec % 60, Shootouttime % 1000); MatchHelper.MissionMessageBox(ref MyMission.Instance().MissionRef, strMsg, "Confirming", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } if (CommonPara.IsExchangedHalfCourt == false && Teams[0].Para.Score == 3) { CommonPara.RemainingCycles = CommonPara.TotalSeconds * 1000 / CommonPara.MsPerCycle / 2; } else if (CommonPara.IsExchangedHalfCourt == true && Teams[1].Para.Score == 3) { CommonPara.RemainingCycles = 0; } }
// added by liushu 20110314 Modified by LiYoubing 20110516 /// <summary> /// 处理半场交换任务 /// 交换半场的基础及思想: /// 1.仿真使命基类对象的通用队伍列表成员实际指向具体仿真使命类对象的具体队伍列表成员 /// 2.策略调用及与客户端通信所用的temId为Mission.TeamsRef各成员的索引 /// 3.策略调用及与客户端通信时左/右半场队伍分别为Mission.TeamsRef[0]/[1] /// 4.交换半场前后TeamsRef[0]/[1]始终代表左/右半场队伍 /// 5.交换半场前Mission.TeamsRef[0]/[1]分别指向Match3V3.Teams[0]/[1] /// 6.交换半场后Mission.TeamsRef[0]/[1]分别指向Match3V3.Teams[1]/[0] /// 7.ResetTeamsAndFishes方法中对半场标志及各队伍仿真机器鱼初始位姿的设置 /// 必须针对Mission.TeamsRef[0]/[1]而非Match3V3.Teams[0]/[1] /// 8.Mission.CommonPara中设置一个标志量IsExchangedHalfCourt表示是否交换过半场 /// 9.处理进球/犯规等情况必须根据半场交换标志量来确定目标队伍 /// 10.在界面Restart按钮的响应中对标志量进行复位 /// </summary> private void HalfCourtExchangeHandler() { MyMission myMission = MyMission.Instance(); if (CommonPara.RemainingCycles == CommonPara.TotalSeconds * 1000 / CommonPara.MsPerCycle / 2) { //CommonPara.IsExchangedHalfCourt = true; // LiYoubing 20110702 // 制胜球阶段也有可能需要交换半场 对交换半场的标志量取反而不是直接赋值可以满足这个要求 CommonPara.IsExchangedHalfCourt = !CommonPara.IsExchangedHalfCourt; MatchHelper.MissionMessageBox(ref MyMission.Instance().MissionRef, "Time to Exchange Half-Court.", "Confirming", MessageBoxButtons.OK, MessageBoxIcon.Warning); // 交换半场前TeamsRef[0]/[1]分别指向Teams[0]/[1] // 交换半场使用List<Team<RoboFish>>的Reverse方法将TeamsRef[0]/[1]的指向对调 // 交换半场前后TeamsRef[0]/[1]始终代表左/右半场队伍 myMission.TeamsRef.Reverse(); // 重置仿真障碍物状态实现构成上下球门的障碍物边框颜色交换 LiYoubing 20110726 ResetObstacles(); ResetTeamsAndFishes(); ResetSomeLocomotionPara(); for (int i = 0; i < Env.Balls.Count; i++) {// 把所有仿真水球的位置沿原点翻转 Env.Balls[i].PositionMm.Z = -Env.Balls[i].PositionMm.Z; Env.Balls[i].PositionMm.X = -Env.Balls[i].PositionMm.X; } } }
// Added by LiYoubing 20110518 /// <summary> /// 处理得分即每个球门里仿真水球个数统计任务 /// </summary> private void ScoreCalculationHandler() { MyMission myMission = MyMission.Instance(); for (int i = 0; i < 6; i++) { if (IsBallInHole(i) && scores[i] == 0) { scores[i] = 1; ustime[i] = CommonPara.RemainingCycles; string strMsg = ""; int Shootouttime = CommonPara.TotalSeconds * 1000 - CommonPara.RemainingCycles * myMission.ParasRef.MsPerCycle; int ShootouttimeSec = Shootouttime / 1000; strMsg += string.Format("Congradulations!Goal time is: {1:00}:{2:00}:{3:00}.", Teams[0].Para.Score, ShootouttimeSec / 60, ShootouttimeSec % 60, Shootouttime % 1000); MatchHelper.MissionMessageBox(ref MyMission.Instance().MissionRef, strMsg, "Confirming", MessageBoxButtons.OK, MessageBoxIcon.Warning); lasttime = ustime[i]; } } int count = 0; for (int i = 0; i < 6; i++) { if (scores[i] == 1) { count++; } } for (int i = 0; i < myMission.TeamsRef.Count; i++) {// 更新左/右半场队伍的得分 myMission.TeamsRef[i].Para.Score = count; } }
/// <summary> /// 犯规处理函数2 added by zhangbo 20111227 /// 各个单程内,水球只能通过指定通道。 /// </summary> private void FoulType2Handler() { Field f = Field.Instance(); Ball b = Env.Balls[0]; if (FinishedSingleTripCount == 1 || FinishedSingleTripCount == 3) {//第二、四个单程,球进入上方通道,则犯规。 if (Math.Abs(Env.Balls[0].PositionMm.X) < (f.RightMm - f.GoalDepthMm - 1.5 * f.GoalWidthMm - Env.Balls[0].RadiusMm) && Env.Balls[0].PositionMm.Z < f.TopMm + f.GoalWidthMm - Env.Balls[0].RadiusMm) { Env.Balls[0].PositionMm.X = f.GoalWidthMm / 2 + b.RadiusMm + 10.0f; Env.Balls[0].PositionMm.Z = Convert.ToSingle(f.TopMm + f.GoalWidthMm + f.GoalDepthMm * 1.5 + b.RadiusMm); MatchHelper.MissionMessageBox(ref MyMission.Instance().MissionRef, string.Format("Ball should be pushed through the other channel:\n【{0}】Fish {1} Fouled!\n", Teams[0].Para.Name, 1), "Confirming", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } if (FinishedSingleTripCount == 2) { //第三个单程,球进入下方通道,则犯规。 if (Math.Abs(Env.Balls[0].PositionMm.X) < (f.RightMm - f.GoalDepthMm - 1.5 * f.GoalWidthMm - Env.Balls[0].RadiusMm) && Env.Balls[0].PositionMm.Z > f.BottomMm - f.GoalWidthMm + Env.Balls[0].RadiusMm) { Env.Balls[0].PositionMm.X = -f.GoalWidthMm / 2 - b.RadiusMm - 10.0f; Env.Balls[0].PositionMm.Z = Convert.ToSingle(f.TopMm + f.GoalWidthMm + f.GoalDepthMm * 1.5 + b.RadiusMm); MatchHelper.MissionMessageBox(ref MyMission.Instance().MissionRef, string.Format("Ball should be pushed through the other channel:\n【{0}】Fish {1} Fouled!\n", Teams[0].Para.Name, 2), "Confirming", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }
/// <summary> /// 犯规处理函数1 added by zhangbo 20111220 /// 规定1号机器鱼只能通过上面通道,机器鱼2只能通过下面通道。 /// </summary> private void FoulType1Handler() { Field f = Field.Instance(); //1号鱼进入下方通道,则犯规。将1号机器鱼置于初始位置。 if (Math.Abs(Teams[0].Fishes[0].PositionMm.X) < (f.RightMm - f.GoalDepthMm - 1.5 * f.GoalWidthMm - Env.Balls[0].RadiusMm) && Teams[0].Fishes[0].PositionMm.Z > f.BottomMm - f.GoalWidthMm + Env.Balls[0].RadiusMm) { Teams[0].Fishes[0].PositionMm = new xna.Vector3(f.LeftMm + Teams[0].Fishes[0].BodyLength * 2, 0, 0); Teams[0].Fishes[0].BodyDirectionRad = 0; MatchHelper.MissionMessageBox(ref MyMission.Instance().MissionRef, string.Format("Enter the Channel Not Allowed:\n【{0}】Fish {1} Fouled!\n", Teams[0].Para.Name, 1), "Confirming", MessageBoxButtons.OK, MessageBoxIcon.Warning); } //2号鱼进入上方通道,则犯规。将2号机器鱼置于初始位置。 if (Math.Abs(Teams[0].Fishes[1].PositionMm.X) < (f.RightMm - f.GoalDepthMm - 1.5 * f.GoalWidthMm - Env.Balls[0].RadiusMm) && Teams[0].Fishes[1].PositionMm.Z < f.TopMm + f.GoalWidthMm - Env.Balls[0].RadiusMm) { Teams[0].Fishes[1].PositionMm = new xna.Vector3(f.RightMm - Teams[0].Fishes[1].BodyLength * 2, 0, 0); Teams[0].Fishes[1].BodyDirectionRad = (float)Math.PI; MatchHelper.MissionMessageBox(ref MyMission.Instance().MissionRef, string.Format("Enter the Channel Not Allowed:\n【{0}】Fish {1} Fouled!\n", Teams[0].Para.Name, 2), "Confirming", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void HalfCourtExchangeHandler() { MyMission myMission = MyMission.Instance(); if (CommonPara.RemainingCycles == CommonPara.TotalSeconds * 1000 / CommonPara.MsPerCycle / 2) { //CommonPara.IsExchangedHalfCourt = true; // LiYoubing 20110702 // 制胜球阶段也有可能需要交换半场 对交换半场的标志量取反而不是直接赋值可以满足这个要求 CommonPara.IsExchangedHalfCourt = !CommonPara.IsExchangedHalfCourt; MatchHelper.MissionMessageBox(ref MyMission.Instance().MissionRef, "Time to Exchange Half-Court.", "Confirming", MessageBoxButtons.OK, MessageBoxIcon.Warning); // exchScore(); // 交换半场前TeamsRef[0]/[1]分别指向Teams[0]/[1] // 交换半场使用List<Team<RoboFish>>的Reverse方法将TeamsRef[0]/[1]的指向对调 // 交换半场前后TeamsRef[0]/[1]始终代表左/右半场队伍 myMission.TeamsRef.Reverse(); ResetTeamsAndFishes(); ResetBalls(); ResetSomeLocomotionPara(); } }
/// <summary> /// 处理倒计时递减到0比赛结束判断提示和响应任务 /// </summary> private void GameOverHandler() { if (CommonPara.RemainingCycles > 0) { return; } // 比赛时间耗完才接着处理 string strMsg = "Time Over!"; //MessageBox.Show(strMsg, "Confirming", MessageBoxButtons.OK, MessageBoxIcon.Warning); MatchHelper.MissionMessageBox(ref MyMission.Instance().MissionRef, strMsg, "Confirming", MessageBoxButtons.OK, MessageBoxIcon.Warning); }
// Added by renjing 20110310 Modified by LiYoubing 20110515 /// <summary> /// 处理倒计时递减到0比赛结束判断提示和响应任务 /// </summary> private void GameOverHandler() { if (CommonPara.RemainingCycles > 0) { return; } CommonPara.IsRunning = false; string strMsg = string.Format("Competition finished.\n"); MatchHelper.MissionMessageBox(ref MyMission.Instance().MissionRef, strMsg, "Confirming", MessageBoxButtons.OK, MessageBoxIcon.Warning); /* * // 比赛时间耗完才接着处理 * string strMsg = ""; * if (Teams[0].Para.Score != Teams[1].Para.Score) * {// 双方得分不同,决出胜负 * CommonPara.IsRunning = false;//比赛停止 * int winner = (Teams[0].Para.Score > Teams[1].Para.Score) ? 0 : 1; * strMsg = string.Format("Congradulations!\nCompetition is completed.\nWinner:【{0}】 in 【{1}】\n", * Teams[winner].Para.Name, Teams[winner].Para.MyHalfCourt); * } * else * { * CommonPara.IsRunning = false; * if (ltime < rtime) * { * int winner = 0; * strMsg = string.Format("Congradulations!\nCompetition is completed.\nWinner:【{0}】 in 【{1}】\n", * Teams[winner].Para.Name, Teams[winner].Para.MyHalfCourt); * } * else if (ltime > rtime) * { * int winner = 1; * strMsg = string.Format("Congradulations!\nCompetition is completed.\nWinner:【{0}】 in 【{1}】\n", * Teams[winner].Para.Name, Teams[winner].Para.MyHalfCourt); * } * else * { * strMsg = string.Format("Competition is tied.\n"); * } * } * * MatchHelper.MissionMessageBox(ref MyMission.Instance().MissionRef, strMsg, * "Confirming", MessageBoxButtons.OK, MessageBoxIcon.Warning); */ }
// Added by renjing 20110310 Modified by LiYoubing 20110515 /// <summary> /// 处理倒计时递减到0比赛结束判断提示和响应任务 /// </summary> private void GameOverHandler() { if (CommonPara.RemainingCycles > 0) { return; } // 比赛时间耗完才接着处理 string strMsg = ""; if (Teams[0].Para.Score != Teams[1].Para.Score) { // 双方得分不同,决出胜负 CommonPara.IsRunning = false; //比赛停止 int winner = (Teams[0].Para.Score > Teams[1].Para.Score) ? 0 : 1; strMsg = string.Format("Congradulations!\nCompetition is completed.\nWinner:【{0}】 in 【{1}】\n", Teams[winner].Para.Name, Teams[winner].Para.MyHalfCourt); } else { bool flag = false; for (int jj = 2; jj >= 0 && !flag; jj--) { CommonPara.IsRunning = false; if (ltime[jj] < rtime[jj]) { flag = true; int winner = 0; strMsg = string.Format("Congradulations!\nCompetition is completed.\nWinner:【{0}】 in 【{1}】\n", Teams[winner].Para.Name, Teams[winner].Para.MyHalfCourt); } else if (ltime[jj] > rtime[jj]) { flag = true; int winner = 1; strMsg = string.Format("Congradulations!\nCompetition is completed.\nWinner:【{0}】 in 【{1}】\n", Teams[winner].Para.Name, Teams[winner].Para.MyHalfCourt); } } if (!flag) { strMsg = string.Format("Competition is tied.\n"); } } MatchHelper.MissionMessageBox(ref MyMission.Instance().MissionRef, strMsg, "Confirming", MessageBoxButtons.OK, MessageBoxIcon.Warning); }
// Added by renjing 20110310 Modified by LiYoubing 20110515 /// <summary> /// 处理倒计时递减到0比赛结束判断提示和响应任务 /// </summary> private void GameOverHandler() { if (CommonPara.RemainingCycles > 0) { return; } // 比赛时间耗完才接着处理 string strMsg = ""; if (Teams[0].Para.Score != Teams[1].Para.Score) { // 双方得分不同,决出胜负 CommonPara.IsRunning = false; //比赛停止 int winner = (Teams[0].Para.Score > Teams[1].Para.Score) ? 0 : 1; strMsg = string.Format("Congradulations!\nCompetition is completed.\nWinner:【{0}】 in 【{1}】\n", Teams[winner].Para.Name, Teams[winner].Para.MyHalfCourt); } else { // 双方得分相同 if (CompetitionPeriod == (int)MatchHelper.CompetitionPeriod.NormalTime) { // 开始制胜球 strMsg = "Normal time competition is over.\nClutch shot time followed.\n"; for (int i = 0; i < CommonPara.TeamCount; i++) {// 解除犯规状态 for (int j = 0; j < CommonPara.FishCntPerTeam; j++) { Teams[i].Fishes[j].FoulFlag = FoulType.NONE; Teams[i].Fishes[j].CountCyclesFouled = 0; Teams[i].Fishes[j].CountInOwnGoalArea = 0; } } CompetitionPeriod = (int)MatchHelper.CompetitionPeriod.ClutchShotTime;//开始制胜球 HandleClutchShotTime(); } else { CommonPara.IsRunning = false; strMsg = "Competition is tied.\n"; } } //MessageBox.Show(strMsg, "Confirming", MessageBoxButtons.OK, MessageBoxIcon.Warning); MatchHelper.MissionMessageBox(ref MyMission.Instance().MissionRef, strMsg, "Confirming", MessageBoxButtons.OK, MessageBoxIcon.Warning); }
// Added by renjing 20110310 Modified by LiYoubing 20110515 /// <summary> /// 处理倒计时递减到0比赛结束判断提示和响应任务 /// </summary> private void GameOverHandler() { if (CommonPara.RemainingCycles > 0) { return; } // 比赛时间耗完或才接着处理 string strMsg = ""; if (Teams[0].Para.Score != Teams[1].Para.Score) { //双方得分不同,决出胜负 CommonPara.IsRunning = false; //比赛停止 int winner = (Teams[0].Para.Score > Teams[1].Para.Score) ? 0 : 1; strMsg = string.Format("Congradulations!\nCompetition is completed.\nWinner:【{0}】 in 【{1}】\n", Teams[winner].Para.Name, Teams[winner].Para.MyHalfCourt); } else { // 双方得分相同 if (Teams[0].Para.Score != 0) { // 开始制胜球 // strMsg = "Normal time competition is over.\nClutch shot time followed.\n"; CommonPara.IsRunning = false; //比赛停止 int winner = (countl > countr) ? 0 : 1; strMsg = string.Format("Normal time competition is over. Congradulations!\n Competition is completed.\nWinner:【{0}】 in 【{1}】\nFirst Goal Time:\n{2} :{3}.{4} s.\n{5} :{6}.{7} s.\n", Teams[winner].Para.Name, Teams[winner].Para.MyHalfCourt, Teams[0].Para.Name, countr / 10, countr % 10, Teams[1].Para.Name, countl / 10, countl % 10);; /* ClearRecord(); * CompetitionPeriod = (int)MatchHelper.CompetitionPeriod.ClutchShotTime;//开始制胜球 * HandleClutchShotTime();*/ } else {// 制胜球阶段结束 CommonPara.IsRunning = false; strMsg = "Competition is tied.\n"; } } //MessageBox.Show(strMsg, "Confirming", MessageBoxButtons.OK, MessageBoxIcon.Warning); MatchHelper.MissionMessageBox(ref MyMission.Instance().MissionRef, strMsg, "Confirming", MessageBoxButtons.OK, MessageBoxIcon.Warning); }
// Added by LiYoubing 20110518 /// <summary> /// 判断仿真水球是否完全进入上/下障碍物围成的特殊球门区域 /// </summary> /// <param name="ball">仿真水球</param> /// <param name="bIsLeftHalfCourt">待判断的是否上球门true判断上球门false判断下球门</param> /// <returns>仿真水球位于障碍物围成的特殊球门内返回true否则返回false</returns> #endregion #region 比赛结束判断及处理 // Added by renjing 20110310 Modified by LiYoubing 20110515 /// <summary> /// 处理倒计时递减到0比赛结束判断提示和响应任务 /// </summary> private void GameOverHandler() { MyMission myMission = MyMission.Instance(); if (CommonPara.RemainingCycles == 0) { string strMsg = ""; int Shootouttime = CommonPara.TotalSeconds * 1000 - lasttime * myMission.ParasRef.MsPerCycle; int ShootouttimeSec = Shootouttime / 1000; strMsg += string.Format("Time Over!Last Goal time is: {1:00}:{2:00}:{3:00}.", Teams[0].Para.Score, ShootouttimeSec / 60, ShootouttimeSec % 60, Shootouttime % 1000); MatchHelper.MissionMessageBox(ref MyMission.Instance().MissionRef, strMsg, "Confirming", MessageBoxButtons.OK, MessageBoxIcon.Warning); } if (Teams[0].Para.Score == 6) { string strMsg = ""; int Shootouttime = CommonPara.TotalSeconds * 1000 - lasttime * myMission.ParasRef.MsPerCycle; int ShootouttimeSec = Shootouttime / 1000; strMsg += string.Format("Congratulations!Last Goal time is: {1:00}:{2:00}:{3:00}.", Teams[0].Para.Score, ShootouttimeSec / 60, ShootouttimeSec % 60, Shootouttime % 1000); MatchHelper.MissionMessageBox(ref MyMission.Instance().MissionRef, strMsg, "Confirming", MessageBoxButtons.OK, MessageBoxIcon.Warning); CommonPara.RemainingCycles = 0; } if (CommonPara.RemainingCycles > 0) { return; } // 比赛时间耗完或才接着处理 }
/// <summary> /// 防守机器鱼在禁区内犯规时最大停留时间(单位:毫秒) /// </summary> #endregion #region 对抗赛5VS5仿真使命控制规则具体处理过程 #region 进球判断及处理 // Added by renjing 20110310 Modified by LiYoubing 20110515 /// <summary> /// 进球处理 /// </summary> private void GoalHandler() { MyMission mymission = MyMission.Instance(); String strMsg = ""; bool pauseFlag = false; if (touch[0] == 0) { RoboFish fish = Teams[0].Fishes[0]; Ball thisball = Env.Balls[0]; CollisionDetectionResult result = CollisionDetection.DetectCollisionBetweenFishAndBall(ref fish, ref thisball); if (result.Intersect == true) { pauseFlag = true; touch[0] = 1; int Shootouttime = CommonPara.TotalSeconds * 1000 - CommonPara.RemainingCycles * mymission.ParasRef.MsPerCycle; int ShootouttimeSec = Shootouttime / 1000; strMsg += string.Format("Congradulations!The first touching time is: {1:00}:{2:00}:{3:00}.", Teams[0].Para.Score, ShootouttimeSec / 60, ShootouttimeSec % 60, Shootouttime % 1000); } } else if (touch[0] == 1 && goal[0] == 0) { Ball thisball = Env.Balls[0]; double distance = (thisball.PositionMm.X - 1900) * (thisball.PositionMm.X - 1900) + (thisball.PositionMm.Z + 1200) * (thisball.PositionMm.Z + 1200); if (distance <= 484.00) { pauseFlag = true; goal[0] = 1; int Shootouttime = CommonPara.TotalSeconds * 1000 - CommonPara.RemainingCycles * mymission.ParasRef.MsPerCycle; int ShootouttimeSec = Shootouttime / 1000; strMsg += string.Format("Congradulations!The first goal time is: {1:00}:{2:00}:{3:00}.", Teams[0].Para.Score, ShootouttimeSec / 60, ShootouttimeSec % 60, Shootouttime % 1000); } } else if (goal[0] == 1 && touch[1] == 0) { RoboFish fish = Teams[0].Fishes[0]; Ball thisball = Env.Balls[1]; CollisionDetectionResult result = CollisionDetection.DetectCollisionBetweenFishAndBall(ref fish, ref thisball); if (result.Intersect == true) { pauseFlag = true; touch[1] = 1; int Shootouttime = CommonPara.TotalSeconds * 1000 - CommonPara.RemainingCycles * mymission.ParasRef.MsPerCycle; int ShootouttimeSec = Shootouttime / 1000; strMsg += string.Format("Congradulations!The first touching time is: {1:00}:{2:00}:{3:00}.", Teams[0].Para.Score, ShootouttimeSec / 60, ShootouttimeSec % 60, Shootouttime % 1000); } } else if (touch[1] == 1 && goal[1] == 0) { Ball thisball = Env.Balls[1]; double distance = (thisball.PositionMm.X - 1900) * (thisball.PositionMm.X - 1900) + (thisball.PositionMm.Z - 1200) * (thisball.PositionMm.Z - 1200); if (distance <= 484.00) { pauseFlag = true; goal[1] = 1; int Shootouttime = CommonPara.TotalSeconds * 1000 - CommonPara.RemainingCycles * mymission.ParasRef.MsPerCycle; int ShootouttimeSec = Shootouttime / 1000; strMsg += string.Format("Congradulations!The first goal time is: {1:00}:{2:00}:{3:00}.", Teams[0].Para.Score, ShootouttimeSec / 60, ShootouttimeSec % 60, Shootouttime % 1000); } } if (pauseFlag) { MatchHelper.MissionMessageBox(ref MyMission.Instance().MissionRef, strMsg, "Confirming", MessageBoxButtons.OK, MessageBoxIcon.Warning); } if (goal[1] == 1) { CommonPara.RemainingCycles = 0; } }
/// <summary> /// 防守机器鱼在禁区内犯规时最大停留时间(单位:毫秒) /// </summary> #endregion #region 对抗赛5VS5仿真使命控制规则具体处理过程 #region 进球判断及处理 // Added by renjing 20110310 Modified by LiYoubing 20110515 /// <summary> /// 进球处理 /// </summary> private void GoalHandler() { MyMission mymission = MyMission.Instance(); int j; if (CommonPara.IsExchangedHalfCourt == false) { for (j = 0; j < 2; j++) { RoboFish f11; Ball f22; CollisionDetectionResult result; for (int i = 0; i < 2; i++) { f11 = Teams[0].Fishes[i]; f22 = Env.Balls[j]; result = new CollisionDetectionResult(); result = CollisionDetection.DetectCollisionBetweenFishAndBall(ref f11, ref f22); if (result.Intersect == true && touchL == false) { int Shootouttime = CommonPara.TotalSeconds * 1000 - CommonPara.RemainingCycles * mymission.ParasRef.MsPerCycle; int ShootouttimeSec = Shootouttime / 1000; touchL = true; ltime[0] = Shootouttime; string strMsg = ""; strMsg += string.Format("First Touch!Touch Time is: {1:00}:{2:00}:{3:00}.", Teams[0].Para.Score, ShootouttimeSec / 60, ShootouttimeSec % 60, Shootouttime % 1000); MatchHelper.MissionMessageBox(ref MyMission.Instance().MissionRef, strMsg, "Confirming", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } if (Env.Balls[j].PositionMm.X >= 1850 && Env.Balls[j].PositionMm.X <= 2250 && Env.Balls[j].PositionMm.Z >= -500 && Env.Balls[j].PositionMm.Z <= 500 && gool[j] == 0) { Teams[0].Para.Score++; gool[j] = 1; string strMsg = ""; int Shootouttime = CommonPara.TotalSeconds * 1000 - CommonPara.RemainingCycles * mymission.ParasRef.MsPerCycle; int ShootouttimeSec = Shootouttime / 1000; ltime[Teams[0].Para.Score] = Shootouttime; strMsg += string.Format("Congradulations!Rescue Time is: {1:00}:{2:00}:{3:00}.", Teams[0].Para.Score, ShootouttimeSec / 60, ShootouttimeSec % 60, Shootouttime % 1000); MatchHelper.MissionMessageBox(ref MyMission.Instance().MissionRef, strMsg, "Confirming", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } /* for (j = 1; j < 4; j++) * { * RoboFish f2 = Teams[1].Fishes[j]; * CollisionDetectionResult result = new CollisionDetectionResult(); * result = CollisionDetection.DetectCollisionBetweenTwoFishes(ref f1, ref f2); * if (result.Intersect == true && gool[j - 1] == 0) * { * Teams[0].Para.Score++; * gool[j - 1] = 1; * string strMsg = ""; * int Shootouttime = CommonPara.TotalSeconds * 1000 - CommonPara.RemainingCycles * mymission.ParasRef.MsPerCycle; * int ShootouttimeSec = Shootouttime / 1000; * ltime = Shootouttime; * strMsg += string.Format("Congradulations!shootouttime is: {1:00}:{2:00}:{3:00}.", * Teams[0].Para.Score, ShootouttimeSec / 60, ShootouttimeSec % 60, Shootouttime % 1000); * MatchHelper.MissionMessageBox(ref MyMission.Instance().MissionRef, strMsg, * "Confirming", MessageBoxButtons.OK, MessageBoxIcon.Warning); * } * }*/ } else { for (j = 0; j < 2; j++) { RoboFish f11; Ball f22; CollisionDetectionResult result; for (int i = 0; i < 2; i++) { f11 = Teams[1].Fishes[i]; f22 = Env.Balls[j]; result = new CollisionDetectionResult(); result = CollisionDetection.DetectCollisionBetweenFishAndBall(ref f11, ref f22); if (result.Intersect == true && touchR == false) { int Shootouttime = CommonPara.TotalSeconds * 1000 / 2 - CommonPara.RemainingCycles * mymission.ParasRef.MsPerCycle; int ShootouttimeSec = Shootouttime / 1000; touchR = true; rtime[0] = Shootouttime; string strMsg = ""; strMsg += string.Format("First Touch!Touch Time is: {1:00}:{2:00}:{3:00}.", Teams[0].Para.Score, ShootouttimeSec / 60, ShootouttimeSec % 60, Shootouttime % 1000); MatchHelper.MissionMessageBox(ref MyMission.Instance().MissionRef, strMsg, "Confirming", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } if (Env.Balls[j].PositionMm.X >= 1850 && Env.Balls[j].PositionMm.X <= 2250 && Env.Balls[j].PositionMm.Z >= -500 && Env.Balls[j].PositionMm.Z <= 500 && goor[j] == 0) { Teams[1].Para.Score++; goor[j] = 1; string strMsg = ""; int Shootouttime = CommonPara.TotalSeconds * 1000 / 2 - CommonPara.RemainingCycles * mymission.ParasRef.MsPerCycle; int ShootouttimeSec = Shootouttime / 1000; rtime[Teams[1].Para.Score] = Shootouttime; strMsg += string.Format("Congradulations!Rescue Time is: {1:00}:{2:00}:{3:00}.", Teams[0].Para.Score, ShootouttimeSec / 60, ShootouttimeSec % 60, Shootouttime % 1000); MatchHelper.MissionMessageBox(ref MyMission.Instance().MissionRef, strMsg, "Confirming", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } /* for (j = 1; j < 4; j++) * { * RoboFish f2 = Teams[0].Fishes[j]; * CollisionDetectionResult result = new CollisionDetectionResult(); * result = CollisionDetection.DetectCollisionBetweenTwoFishes(ref f1, ref f2); * if (result.Intersect == true && goor[j - 1] == 0) * { * Teams[1].Para.Score++; * goor[j - 1] = 1; * string strMsg = ""; * int Shootouttime = CommonPara.TotalSeconds * 1000 / 2 - CommonPara.RemainingCycles * mymission.ParasRef.MsPerCycle; * int ShootouttimeSec = Shootouttime / 1000; * rtime = Shootouttime; * strMsg += string.Format("Congradulations!shootouttime is: {1:00}:{2:00}:{3:00}.", * Teams[0].Para.Score, ShootouttimeSec / 60, ShootouttimeSec % 60, Shootouttime % 1000); * MatchHelper.MissionMessageBox(ref MyMission.Instance().MissionRef, strMsg, * "Confirming", MessageBoxButtons.OK, MessageBoxIcon.Warning); * } * }*/ } if (CommonPara.IsExchangedHalfCourt == false && Teams[0].Para.Score == 2) { CommonPara.RemainingCycles = CommonPara.TotalSeconds * 1000 / CommonPara.MsPerCycle / 2; } else if (CommonPara.IsExchangedHalfCourt == true && Teams[1].Para.Score == 2) { CommonPara.RemainingCycles = 0; } }
// Added by renjing 20110310 Modified by LiYoubing 20110515 /// <summary> /// 死球状态后,场上机器鱼的处理 /// </summary> private void DeadBallHandler() { if (IsDeadBall()) { MatchHelper.MissionMessageBox(ref MyMission.Instance().MissionRef, "DeadBall Now!", "Comfirming", MessageBoxButtons.OK, MessageBoxIcon.Warning); //左上争球点 Point pointFreeKickoff1 = new Point(Env.FieldInfo.LeftMm / 2, Env.FieldInfo.TopMm / 2); //左下争球点 Point pointFreeKickoff2 = new Point(Env.FieldInfo.LeftMm / 2, Env.FieldInfo.BottomMm / 2); //右上争球点 Point pointFreeKickoff3 = new Point(Env.FieldInfo.RightMm / 2, Env.FieldInfo.TopMm / 2); //右下争球点 Point pointFreeKickoff4 = new Point(Env.FieldInfo.RightMm / 2, Env.FieldInfo.BottomMm / 2); //临时变量保存争球点 Point pointFreeKickoff = pointFreeKickoff1; double pointFreeKickoffToBall; pointFreeKickoffToBall = Math.Sqrt((pointFreeKickoff.X - Env.Balls[0].PositionMm.X) * (pointFreeKickoff.X - Env.Balls[0].PositionMm.X) + (pointFreeKickoff.Y - Env.Balls[0].PositionMm.Z) * (pointFreeKickoff.Y - Env.Balls[0].PositionMm.Z)); //左上争球点到球的距离 double pointFreeKickoff1ToBall; pointFreeKickoff1ToBall = Math.Sqrt((pointFreeKickoff1.X - Env.Balls[0].PositionMm.X) * (pointFreeKickoff1.X - Env.Balls[0].PositionMm.X) + (pointFreeKickoff1.Y - Env.Balls[0].PositionMm.Z) * (pointFreeKickoff1.Y - Env.Balls[0].PositionMm.Z)); //左下争球点到球的距离 double pointFreeKickoff2ToBall; pointFreeKickoff2ToBall = Math.Sqrt((pointFreeKickoff2.X - Env.Balls[0].PositionMm.X) * (pointFreeKickoff2.X - Env.Balls[0].PositionMm.X) + (pointFreeKickoff2.Y - Env.Balls[0].PositionMm.Z) * (pointFreeKickoff2.Y - Env.Balls[0].PositionMm.Z)); //右上争球点到球的距离 double pointFreeKickoff3ToBall; pointFreeKickoff3ToBall = Math.Sqrt((pointFreeKickoff3.X - Env.Balls[0].PositionMm.X) * (pointFreeKickoff3.X - Env.Balls[0].PositionMm.X) + (pointFreeKickoff3.Y - Env.Balls[0].PositionMm.Z) * (pointFreeKickoff3.Y - Env.Balls[0].PositionMm.Z)); //右下争球点到球的距离 double pointFreeKickoff4ToBall; pointFreeKickoff4ToBall = Math.Sqrt((pointFreeKickoff4.X - Env.Balls[0].PositionMm.X) * (pointFreeKickoff4.X - Env.Balls[0].PositionMm.X) + (pointFreeKickoff4.Y - Env.Balls[0].PositionMm.Z) * (pointFreeKickoff4.Y - Env.Balls[0].PositionMm.Z)); if (pointFreeKickoff2ToBall < pointFreeKickoffToBall) { pointFreeKickoff = pointFreeKickoff2; pointFreeKickoffToBall = pointFreeKickoff2ToBall; } if (pointFreeKickoff3ToBall < pointFreeKickoffToBall) { pointFreeKickoff = pointFreeKickoff3; pointFreeKickoffToBall = pointFreeKickoff3ToBall; } if (pointFreeKickoff4ToBall < pointFreeKickoffToBall) { pointFreeKickoff = pointFreeKickoff4; } // 仿真水球速度置为0 Env.Balls[0].VelocityMmPs = 0; Env.Balls[0].VelocityDirectionRad = 0; // 将仿真水球的中心坐标置成所选出的争球点的坐标 Env.Balls[0].PositionMm.X = pointFreeKickoff.X; Env.Balls[0].PositionMm.Z = pointFreeKickoff.Y; #region 仿真机器鱼的位姿设置 // 交换半场前/后左半场的队伍分别为第0/1支队伍 Team <Fish1V1> teamLeft = (CommonPara.IsExchangedHalfCourt == true) ? Teams[1] : Teams[0]; // 交换半场前/后右半场的队伍分别为第1/0支队伍 Team <Fish1V1> teamRight = (CommonPara.IsExchangedHalfCourt == true) ? Teams[0] : Teams[1]; for (int j = 0; j < CommonPara.FishCntPerTeam; j++) {// 将两支队伍的仿真机器鱼对称置于争球点左右 用相对距离 不用绝对数字 teamLeft.Fishes[j].PositionMm.X = pointFreeKickoff.X - teamLeft.Fishes[j].BodyLength - Env.Balls[0].RadiusMm; teamRight.Fishes[j].PositionMm.X = pointFreeKickoff.X + teamRight.Fishes[j].BodyLength + Env.Balls[0].RadiusMm; teamLeft.Fishes[j].PositionMm.Z = pointFreeKickoff.Y + 3 * teamLeft.Fishes[j].BodyWidth * (j - 1); teamRight.Fishes[j].PositionMm.Z = pointFreeKickoff.Y + 3 * teamRight.Fishes[j].BodyWidth * (j - 1); teamLeft.Fishes[j].BodyDirectionRad = 0; teamRight.Fishes[j].BodyDirectionRad = (float)Math.PI; } #endregion } }