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

Commit 9fb2237

Browse files
futrimeZhangyr2022
andauthored
Update communication protocol, implement exception handler and update UI (#35)
* Update Game.cs * Add order ID * Rename packets * Update something * Update something * Update something * Finish packet transmitting (Get Information) * Fix a very very tiny bug * Fix a fatal bug * Optimize the code and add unhandled exception handler * Update MainWindow.Designer.cs * Update build.yml * Update build.yml * Add icon * Update EdcHost.csproj * Update encoding * Update build.yml Co-authored-by: zhangyr <1302821779@qq.com>
1 parent df92230 commit 9fb2237

22 files changed

+5146
-570
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ jobs:
1414
- name: Checkout the repository
1515
uses: actions/checkout@v3
1616

17+
- name: Replace the version strings
18+
run: (Get-Content -path Source/MainWindow.Designer.cs -Raw) -replace 'EDC_HOST_BUILD_REF','${{ github.ref_name }}' | Set-Content -Path Source/MainWindow.Designer.cs
19+
1720
- name: Setup .NET
1821
uses: actions/setup-dotnet@v2
1922
with:

Assets/Icons/Icon.ico

264 KB
Binary file not shown.

EdcHost.csproj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,21 @@
77
<EnableDefaultItems>false</EnableDefaultItems>
88
<BaseOutputPath>Bin</BaseOutputPath>
99
<BaseIntermediateOutputPath>Obj</BaseIntermediateOutputPath>
10+
<ApplicationIcon>Assets\Icons\Icon.ico</ApplicationIcon>
1011
</PropertyGroup>
1112

1213
<ItemGroup>
1314
<Compile Include="Source/*.cs" />
1415
</ItemGroup>
1516

17+
<ItemGroup>
18+
<Content Include="Assets\Icons\Icon.ico" />
19+
</ItemGroup>
20+
21+
<ItemGroup>
22+
<EmbeddedResource Include="Source\MainWindow.resx" />
23+
</ItemGroup>
24+
1625
<ItemGroup>
1726
<PackageReference Include="OpenCvSharp4" Version="4.6.0.20220608" />
1827
<PackageReference Include="OpenCvSharp4.Extensions" Version="4.6.0.20220608" />

Source/Game.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ public static readonly (long Min, long Max) OrderDeliveryDurationRange = (
252252
/// <summary>
253253
/// The game state.
254254
/// </summary>
255-
public GameStateType GameState => this._gameState;
255+
public GameStatusType GameState => this._gameState;
256256

257257
/// <summary>
258258
/// The game time. Null if the game has not started.
@@ -319,7 +319,7 @@ public long? RemainingTime
319319

320320
private GameStageType _gameStage = GameStageType.PreMatch;
321321

322-
private GameStateType _gameState = GameStateType.Unstarted;
322+
private GameStatusType _gameState = GameStatusType.Unstarted;
323323

324324
// True if the vehicle of the current camp has moved into the
325325
// inner court.
@@ -419,7 +419,7 @@ public void Refresh()
419419
{
420420
// The game should only refresh when running.
421421
if (
422-
this._gameState != GameStateType.Running
422+
this._gameState != GameStatusType.Running
423423
)
424424
{
425425
return;
@@ -471,8 +471,8 @@ public void Refresh()
471471
public void Start(CampType camp, GameStageType gameStage)
472472
{
473473
if (
474-
this._gameState != GameStateType.Unstarted &&
475-
this._gameState != GameStateType.Ended
474+
this._gameState != GameStatusType.Unstarted &&
475+
this._gameState != GameStatusType.Ended
476476
)
477477
{
478478
throw new Exception("The game has started.");
@@ -484,7 +484,7 @@ public void Start(CampType camp, GameStageType gameStage)
484484
throw new Exception("The game stage is invalid.");
485485
}
486486

487-
this._gameState = GameStateType.Running;
487+
this._gameState = GameStatusType.Running;
488488

489489
// Set the metadata.
490490
this._camp = camp;
@@ -536,12 +536,12 @@ public void Start(CampType camp, GameStageType gameStage)
536536
/// </summary>
537537
public void Pause()
538538
{
539-
if (this._gameState != GameStateType.Running)
539+
if (this._gameState != GameStatusType.Running)
540540
{
541541
throw new Exception("The game is not running.");
542542
}
543543

544-
this._gameState = GameStateType.Paused;
544+
this._gameState = GameStatusType.Paused;
545545

546546
// Record the time when start to pause.
547547
this._pauseTime = Utility.SystemTime;
@@ -552,12 +552,12 @@ public void Pause()
552552
/// </summary>
553553
public void Continue()
554554
{
555-
if (this._gameState != GameStateType.Paused)
555+
if (this._gameState != GameStatusType.Paused)
556556
{
557557
throw new Exception("The game is not paused.");
558558
}
559559

560-
this._gameState = GameStateType.Running;
560+
this._gameState = GameStatusType.Running;
561561

562562
// To reduce the paused time in the game time.
563563
this._startTime += Utility.SystemTime - this._pauseTime;
@@ -569,14 +569,14 @@ public void Continue()
569569
public void End()
570570
{
571571
if (
572-
this._gameState != GameStateType.Running &&
573-
this._gameState != GameStateType.Paused
572+
this._gameState != GameStatusType.Running &&
573+
this._gameState != GameStatusType.Paused
574574
)
575575
{
576576
throw new Exception("The game is not running or paused.");
577577
}
578578

579-
this._gameState = GameStateType.Ended;
579+
this._gameState = GameStatusType.Ended;
580580
}
581581

582582
/// <summary>
@@ -779,7 +779,7 @@ void ScoreMoving()
779779
// Score parking penalty.
780780
if (
781781
vehicle.ParkingDuration != null &&
782-
(long)vehicle.ParkingDuration > 5000 + this._lastTickDuration
782+
(long)vehicle.ParkingDuration >= 5000 + this._lastTickDuration
783783
)
784784
{
785785
this._score[(CampType)this._camp] +=
@@ -884,7 +884,7 @@ void TakeAndDeliverOrder()
884884
}
885885

886886
if ((int)Dot.Distance(order.DeparturePosition, vehiclePosition)
887-
< Game.OrderContactScopeRadius)
887+
<= Game.OrderContactScopeRadius)
888888
{
889889
order.Take((long)this.GameTime);
890890

@@ -895,7 +895,7 @@ void TakeAndDeliverOrder()
895895
else if (order.Status == OrderStatusType.InDelivery)
896896
{
897897
if ((int)Dot.Distance(order.DestinationPosition, vehiclePosition)
898-
< Game.OrderContactScopeRadius)
898+
<= Game.OrderContactScopeRadius)
899899
{
900900
order.Deliver((long)this.GameTime);
901901

0 commit comments

Comments
 (0)