Browse Source

feat: 🎨 add final score to playbackServer

tags/0.1.0
gsy1519 2 years ago
parent
commit
6cc2f0a8f9
2 changed files with 21 additions and 0 deletions
  1. +15
    -0
      logic/Server/PlaybackServer.cs
  2. +6
    -0
      logic/Server/Program.cs

+ 15
- 0
logic/Server/PlaybackServer.cs View File

@@ -20,11 +20,20 @@ namespace Server
public int TeamCount => options.TeamCount;
private MessageWriter? mwr = null;
private bool IsGaming { get; set; }
private int[] finalScore;
public int[] FinalScore
{
get
{
return finalScore;
}
}
public PlaybackServer(ArgumentOptions options)
{
this.options = options;
IsGaming = true;
teamScore = new int[0, 0];
finalScore = new int[0];
}

public override async Task AddPlayer(PlayerMsg request, IServerStreamWriter<MessageToClient> responseStream, ServerCallContext context)
@@ -92,6 +101,7 @@ namespace Server
{
Console.WriteLine("Parsing playback file...");
teamScore = new int[mr.teamCount, mr.playerCount];
finalScore = new int[mr.teamCount];
int infoNo = 0;
object cursorLock = new object();
var initialTop = Console.CursorTop;
@@ -137,6 +147,8 @@ namespace Server
if (msg.GameState == GameState.GameEnd)
{
Console.WriteLine("Game over normally!");
finalScore[0] = msg.AllMessage.StudentScore;
finalScore[1] = msg.AllMessage.TrickerScore;
goto endParse;
}
}
@@ -157,6 +169,7 @@ namespace Server
using (MessageReader mr = new MessageReader(options.FileName))
{
teamScore = new int[mr.teamCount, mr.playerCount];
finalScore = new int[mr.teamCount];
int infoNo = 0;
object cursorLock = new object();
var msgCurTop = Console.CursorTop;
@@ -208,6 +221,8 @@ namespace Server
{
Console.WriteLine("Game over normally!");
IsGaming = false;
finalScore[0] = msg.AllMessage.StudentScore;
finalScore[1] = msg.AllMessage.TrickerScore;
ReportGame(msg);
return false;
}


+ 6
- 0
logic/Server/Program.cs View File

@@ -44,6 +44,12 @@ namespace Server
playbackServer.WaitForGame();
Console.WriteLine("Server end!");
server.ShutdownAsync().Wait();

Thread.Sleep(50);
Console.WriteLine("");
Console.WriteLine("=================== Final Score ====================");
Console.WriteLine($"Studnet: {playbackServer.FinalScore[0]}");
Console.WriteLine($"Tricker: {playbackServer.FinalScore[1]}");
}
catch (Exception ex)
{


Loading…
Cancel
Save