Skip to content
This repository was archived by the owner on Sep 7, 2023. It is now read-only.

Commit b6894c5

Browse files
committed
fix: fix some bugs
1 parent cee3048 commit b6894c5

File tree

1 file changed

+88
-81
lines changed

1 file changed

+88
-81
lines changed

Source/MainWindow.cs

Lines changed: 88 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -275,103 +275,107 @@ public MainWindow()
275275
/// </summary>
276276
private void RefreshAll()
277277
{
278-
try {
279-
// Show default image if the camera is changing.
280-
if (this._camera == null)
278+
try
281279
{
282-
this.ShowBackgroundImage();
283-
return;
284-
}
280+
// Show default image if the camera is changing.
281+
if (this._camera == null)
282+
{
283+
this.ShowBackgroundImage();
284+
return;
285+
}
285286

286-
this.ProcessCameraFrame();
287+
this.ProcessCameraFrame();
287288

288-
// Refresh the game.
289-
this._game.Refresh();
289+
// Refresh the game.
290+
this._game.Refresh();
290291

291-
if (this._game.GameState == GameStatusType.Unstarted)
292-
{
293-
this.buttonFoul.Enabled = false;
294-
if (this._calibrationClickCount >= 4)
292+
if (this._game.GameState == GameStatusType.Unstarted)
295293
{
296-
this.buttonCalibration.Enabled = true;
294+
this.buttonFoul.Enabled = false;
295+
if (this._calibrationClickCount >= 4)
296+
{
297+
this.buttonCalibration.Enabled = true;
298+
}
299+
this.buttonSettings.Enabled = true;
300+
this.buttonStart.Enabled = true;
301+
this.buttonPause.Enabled = false;
302+
this.buttonContinue.Enabled = false;
303+
this.buttonEnd.Enabled = false;
297304
}
298-
this.buttonSettings.Enabled = true;
299-
this.buttonStart.Enabled = true;
300-
this.buttonPause.Enabled = false;
301-
this.buttonContinue.Enabled = false;
302-
this.buttonEnd.Enabled = false;
303-
}
304-
else if (this._game.GameState == GameStatusType.Running)
305-
{
306-
if (this._game.GameTime == null)
305+
else if (this._game.GameState == GameStatusType.Running)
307306
{
308-
throw new Exception("The game time is null.");
309-
}
307+
if (this._game.GameTime == null)
308+
{
309+
throw new Exception("The game time is null.");
310+
}
310311

311-
if (this._locatorDict[(CampType)this._game.Camp].TargetPosition != null)
312-
{
313-
// Update the position of the vehicle of the current camp.
314-
this._game.Vehicle[(CampType)this._game.Camp].UpdatePosition(
315-
new Dot((Point2i)this._coordinateConverter.CameraToCourt(
316-
(Point2f)this._locatorDict[(CampType)this._game.Camp].TargetPosition
317-
)),
318-
(long)this._game.GameTime
319-
);
320-
}
312+
if (this._locatorDict[(CampType)this._game.Camp].TargetPosition != null)
313+
{
314+
// Update the position of the vehicle of the current camp.
315+
this._game.Vehicle[(CampType)this._game.Camp].UpdatePosition(
316+
new Dot((Point2i)this._coordinateConverter.CameraToCourt(
317+
(Point2f)this._locatorDict[(CampType)this._game.Camp].TargetPosition
318+
)),
319+
(long)this._game.GameTime
320+
);
321+
}
321322

322-
this.buttonFoul.Enabled = true;
323-
this.buttonCalibration.Enabled = false;
324-
this.buttonSettings.Enabled = false;
325-
this.buttonStart.Enabled = false;
326-
this.buttonPause.Enabled = true;
327-
this.buttonContinue.Enabled = false;
328-
this.buttonEnd.Enabled = true;
329-
330-
this.labelScoreVehicleA.Text = this._game.Score[CampType.A].ToString("0.000");
331-
this.labelScoreVehicleB.Text = this._game.Score[CampType.B].ToString("0.000");
332-
this.labelGameTime.Text = Math.Max((decimal)(this._game.RemainingTime) / 1000, (decimal)0).ToString("0.00");
333-
this.progressBarRemainingPowerRatio.Value = (int)(this._game.Vehicle[(CampType)this._game.Camp].RemainingPowerRatio * 100);
334-
}
335-
else if (this._game.GameState == GameStatusType.Paused)
336-
{
337-
this.buttonFoul.Enabled = true;
338-
if (this._calibrationClickCount >= 4)
339-
{
340-
this.buttonCalibration.Enabled = true;
323+
this.buttonFoul.Enabled = true;
324+
this.buttonCalibration.Enabled = false;
325+
this.buttonSettings.Enabled = false;
326+
this.buttonStart.Enabled = false;
327+
this.buttonPause.Enabled = true;
328+
this.buttonContinue.Enabled = false;
329+
this.buttonEnd.Enabled = true;
330+
331+
this.labelScoreVehicleA.Text = this._game.Score[CampType.A].ToString("0.000");
332+
this.labelScoreVehicleB.Text = this._game.Score[CampType.B].ToString("0.000");
333+
this.labelGameTime.Text = Math.Max((decimal)(this._game.RemainingTime) / 1000, (decimal)0).ToString("0.00");
334+
this.progressBarRemainingPowerRatio.Value = (int)(this._game.Vehicle[(CampType)this._game.Camp].RemainingPowerRatio * 100);
341335
}
342-
this.buttonSettings.Enabled = false;
343-
this.buttonStart.Enabled = false;
344-
this.buttonPause.Enabled = false;
345-
this.buttonContinue.Enabled = true;
346-
this.buttonEnd.Enabled = true;
347-
}
348-
else if (this._game.GameState == GameStatusType.Ended)
349-
{
350-
this.buttonFoul.Enabled = false;
351-
if (this._calibrationClickCount >= 4)
352-
{
353-
this.buttonCalibration.Enabled = true;
354-
}
355-
this.buttonSettings.Enabled = false;
356-
if (
357-
this._game.GameStage == GameStageType.SecondHalf &&
358-
this._game.Camp == CampType.B
359-
)
336+
else if (this._game.GameState == GameStatusType.Paused)
360337
{
338+
this.buttonFoul.Enabled = true;
339+
if (this._calibrationClickCount >= 4)
340+
{
341+
this.buttonCalibration.Enabled = true;
342+
}
343+
this.buttonSettings.Enabled = false;
361344
this.buttonStart.Enabled = false;
345+
this.buttonPause.Enabled = false;
346+
this.buttonContinue.Enabled = true;
347+
this.buttonEnd.Enabled = true;
362348
}
363-
else
349+
else if (this._game.GameState == GameStatusType.Ended)
364350
{
365-
this.buttonStart.Enabled = true;
351+
this.buttonFoul.Enabled = false;
352+
if (this._calibrationClickCount >= 4)
353+
{
354+
this.buttonCalibration.Enabled = true;
355+
}
356+
this.buttonSettings.Enabled = false;
357+
if (
358+
this._game.GameStage == GameStageType.SecondHalf &&
359+
this._game.Camp == CampType.B
360+
)
361+
{
362+
this.buttonStart.Enabled = false;
363+
}
364+
else
365+
{
366+
this.buttonStart.Enabled = true;
367+
}
368+
this.buttonPause.Enabled = false;
369+
this.buttonContinue.Enabled = false;
370+
this.buttonEnd.Enabled = false;
371+
this.labelGameTime.Text = "0.00";
366372
}
367-
this.buttonPause.Enabled = false;
368-
this.buttonContinue.Enabled = false;
369-
this.buttonEnd.Enabled = false;
370-
}
371373

372-
// Force to refresh the window.
373-
this.Refresh();
374-
} catch (Exception e) {
374+
// Force to refresh the window.
375+
this.Refresh();
376+
}
377+
catch (Exception e)
378+
{
375379
_logger.Error($"RefreshAll error: {e.Message}");
376380
}
377381
}
@@ -947,6 +951,9 @@ private void buttonReset_Click(object sender, EventArgs e)
947951
private void buttonFoul_Click(object sender, EventArgs e)
948952
{
949953
_game.SetFoul();
954+
this.labelScoreVehicleA.Text = this._game.Score[CampType.A].ToString("0.000");
955+
this.labelScoreVehicleB.Text = this._game.Score[CampType.B].ToString("0.000");
956+
Refresh();
950957
}
951958

952959
private void buttonSettings_Click(object sender, EventArgs e)

0 commit comments

Comments
 (0)