dev
This commit is contained in:
parent
12c9c14b97
commit
fb5ac3c4b3
|
|
@ -1,5 +1,6 @@
|
||||||
using GameHandler.Exceptions;
|
using GameHandler.Exceptions;
|
||||||
using GameModel.Contract;
|
using GameModel.Contract;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
@ -41,5 +42,11 @@ namespace GameHandler.Extensions
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string GetJson(this GameService gameService)
|
||||||
|
{
|
||||||
|
string json = JsonConvert.SerializeObject(gameService.GameModel, Formatting.Indented);
|
||||||
|
return json;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,10 @@
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\GameModel\GameModel.csproj" />
|
<ProjectReference Include="..\GameModel\GameModel.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,9 @@ namespace GameHandler
|
||||||
private bool _isStarted = false;
|
private bool _isStarted = false;
|
||||||
private IGameHandler _gh;
|
private IGameHandler _gh;
|
||||||
private ThrowHandler _th;
|
private ThrowHandler _th;
|
||||||
|
private ExpenseHandler _eh;
|
||||||
private GameState _lastState;
|
private GameState _lastState;
|
||||||
|
public GameState GameModel { get { return _lastState; } }
|
||||||
|
|
||||||
public GameService()
|
public GameService()
|
||||||
{
|
{
|
||||||
|
|
@ -59,6 +61,7 @@ namespace GameHandler
|
||||||
var gm = _gh.InitGameModel(playerIds, gameSettings);
|
var gm = _gh.InitGameModel(playerIds, gameSettings);
|
||||||
|
|
||||||
_th = new ThrowHandler();
|
_th = new ThrowHandler();
|
||||||
|
_eh = new ExpenseHandler();
|
||||||
|
|
||||||
var throwState = ThrowState.Create(_gh.ThrowMode(), _gh.ThrowsPerRount());
|
var throwState = ThrowState.Create(_gh.ThrowMode(), _gh.ThrowsPerRount());
|
||||||
_lastState = GameState.Create(throwState, _gh.GetCurrentPlayerId(gm), gm);
|
_lastState = GameState.Create(throwState, _gh.GetCurrentPlayerId(gm), gm);
|
||||||
|
|
@ -82,7 +85,7 @@ namespace GameHandler
|
||||||
// todo: update expense model
|
// todo: update expense model
|
||||||
|
|
||||||
|
|
||||||
_lastState = _lastState with { ThrowState = throwState, GameModel = gameModel };
|
_lastState = _lastState with { ThrowState = throwState, GameModel = gameModel, NextPlayerId = _gh.GetCurrentPlayerId(gameModel) };
|
||||||
return _lastState ;
|
return _lastState ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="CommandLineParser" Version="2.9.1" />
|
<PackageReference Include="CommandLineParser" Version="2.9.1" />
|
||||||
<PackageReference Include="Spectre.Console" Version="0.48.0" />
|
<PackageReference Include="Spectre.Console" Version="0.48.0" />
|
||||||
|
<PackageReference Include="Spectre.Console.Json" Version="0.48.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ using GameModel.Contract;
|
||||||
using GameModel.DeathGame;
|
using GameModel.DeathGame;
|
||||||
using KoogleCli.Model;
|
using KoogleCli.Model;
|
||||||
using Spectre.Console;
|
using Spectre.Console;
|
||||||
|
using Spectre.Console.Json;
|
||||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||||
|
|
||||||
AnsiConsole.MarkupLine("Welcome to [green]koogle[/]");
|
AnsiConsole.MarkupLine("Welcome to [green]koogle[/]");
|
||||||
|
|
@ -134,33 +135,35 @@ void Show(GameState gameState)
|
||||||
|
|
||||||
ShowThrow(gameState);
|
ShowThrow(gameState);
|
||||||
ShowBoard(gameState.ThrowState.BoardState);
|
ShowBoard(gameState.ThrowState.BoardState);
|
||||||
|
|
||||||
|
|
||||||
|
var json = new JsonText(_gs.GetJson());
|
||||||
|
AnsiConsole.Write(
|
||||||
|
new Panel(json)
|
||||||
|
.Header("Datamodel:")
|
||||||
|
.Collapse()
|
||||||
|
.RoundedBorder()
|
||||||
|
.BorderColor(Color.Yellow));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShowThrow(GameState gameState)
|
void ShowThrow(GameState gameState)
|
||||||
{
|
{
|
||||||
int throwCount = gameState.ThrowState.ThrowCount;
|
int throwCount = gameState.ThrowState.ThrowCount;
|
||||||
int throwsPerRount = gameState.ThrowState.ThrowsPerRount;
|
int throwsPerRount = gameState.ThrowState.ThrowsPerRount;
|
||||||
Text text1;
|
Text textThrows;
|
||||||
if (throwsPerRount == IGameHandler.INFINIT_THROWS)
|
if (throwsPerRount == IGameHandler.INFINIT_THROWS)
|
||||||
{
|
{
|
||||||
text1 = new Text($"Würfe: {throwCount}", new Style(Color.Red, Color.Black));
|
textThrows = new Text($"Würfe: {throwCount}", new Style(Color.Red, Color.Black));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
text1 = new Text($"Würfe: {throwCount}/{throwsPerRount}", new Style(Color.Red, Color.Black));
|
textThrows = new Text($"Würfe: {throwCount}/{throwsPerRount}", new Style(Color.Red, Color.Black));
|
||||||
}
|
}
|
||||||
var text1_2 = new Text($"Modus: {_gs.ThrowModeName}", new Style(Color.Red, Color.Black));
|
var textMode = new Text($"Modus: {_gs.ThrowModeName}", new Style(Color.Red, Color.Black));
|
||||||
|
|
||||||
// Create three text elements
|
// Create three text elements
|
||||||
var paddedText_II = new Text($"Spieler: {gameState.NextPlayerId}", new Style(Color.Green, Color.Black));
|
var textPlayer = new Text($"Spieler: {gameState.NextPlayerId}", new Style(Color.Green, Color.Black));
|
||||||
var paddedText_III = new Text("Spielzeit: ", new Style(Color.Blue, Color.Black));
|
var textGametime = new Text("Spielzeit: ", new Style(Color.Blue, Color.Black));
|
||||||
|
|
||||||
// Apply padding to the three text elements
|
|
||||||
var pad1_1 = new Padder(text1).PadRight(16).PadBottom(0).PadTop(2);
|
|
||||||
var pad1_2 = new Padder(text1_2).PadRight(0).PadBottom(0).PadTop(2);
|
|
||||||
|
|
||||||
var pad_II = new Padder(paddedText_II).PadBottom(0).PadTop(2);
|
|
||||||
var pad_III = new Padder(paddedText_III).PadLeft(16).PadBottom(0).PadTop(0);
|
|
||||||
|
|
||||||
// Insert padded elements within single-row grid
|
// Insert padded elements within single-row grid
|
||||||
var grid = new Grid();
|
var grid = new Grid();
|
||||||
|
|
@ -169,8 +172,8 @@ void ShowThrow(GameState gameState)
|
||||||
grid.AddColumn();
|
grid.AddColumn();
|
||||||
grid.AddColumn();
|
grid.AddColumn();
|
||||||
|
|
||||||
grid.AddRow(pad1_2);
|
grid.AddRow(textMode);
|
||||||
grid.AddRow(pad1_1, pad_II, pad_III);
|
grid.AddRow(textThrows, textPlayer, textGametime);
|
||||||
|
|
||||||
// Write grid and it's padded contents to the Console
|
// Write grid and it's padded contents to the Console
|
||||||
AnsiConsole.Write(grid);
|
AnsiConsole.Write(grid);
|
||||||
|
|
@ -186,22 +189,22 @@ void ShowBoard(BoardState board)
|
||||||
grid.AddColumn();
|
grid.AddColumn();
|
||||||
grid.AddColumn();
|
grid.AddColumn();
|
||||||
|
|
||||||
Padder pad_1, pad_2, pad_3, pad_4, pad_5;
|
Text text1, text2, text3, text4, text5;
|
||||||
|
|
||||||
GetRow(1, out pad_1, out pad_2, out pad_3, out pad_4, out pad_5, board);
|
GetRow(1, out text1, out text2, out text3, out text4, out text5, board);
|
||||||
grid.AddRow(pad_1, pad_2, pad_3, pad_4, pad_5);
|
grid.AddRow(text1, text2, text3, text4, text5);
|
||||||
|
|
||||||
GetRow(2, out pad_1, out pad_2, out pad_3, out pad_4, out pad_5, board);
|
GetRow(2, out text1, out text2, out text3, out text4, out text5, board);
|
||||||
grid.AddRow(pad_1, pad_2, pad_3, pad_4, pad_5);
|
grid.AddRow(text1, text2, text3, text4, text5);
|
||||||
|
|
||||||
GetRow(3, out pad_1, out pad_2, out pad_3, out pad_4, out pad_5, board);
|
GetRow(3, out text1, out text2, out text3, out text4, out text5, board);
|
||||||
grid.AddRow(pad_1, pad_2, pad_3, pad_4, pad_5);
|
grid.AddRow(text1, text2, text3, text4, text5);
|
||||||
|
|
||||||
GetRow(4, out pad_1, out pad_2, out pad_3, out pad_4, out pad_5, board);
|
GetRow(4, out text1, out text2, out text3, out text4, out text5, board);
|
||||||
grid.AddRow(pad_1, pad_2, pad_3, pad_4, pad_5);
|
grid.AddRow(text1, text2, text3, text4, text5);
|
||||||
|
|
||||||
GetRow(5, out pad_1, out pad_2, out pad_3, out pad_4, out pad_5, board);
|
GetRow(5, out text1, out text2, out text3, out text4, out text5, board);
|
||||||
grid.AddRow(pad_1, pad_2, pad_3, pad_4, pad_5);
|
grid.AddRow(text1, text2, text3, text4, text5);
|
||||||
|
|
||||||
// Write grid and it's padded contents to the Console
|
// Write grid and it's padded contents to the Console
|
||||||
AnsiConsole.Write(grid);
|
AnsiConsole.Write(grid);
|
||||||
|
|
@ -212,7 +215,7 @@ void ShowPlayer()
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static void GetRow(int row, out Padder pad_1, out Padder pad_2, out Padder pad_3, out Padder pad_4, out Padder pad_5, BoardState board)
|
static void GetRow(int row, out Text text1, out Text text2, out Text text3, out Text text4, out Text text5, BoardState board)
|
||||||
{
|
{
|
||||||
string txt1 = "0";
|
string txt1 = "0";
|
||||||
string txt2 = "0";
|
string txt2 = "0";
|
||||||
|
|
@ -261,16 +264,16 @@ static void GetRow(int row, out Padder pad_1, out Padder pad_2, out Padder pad_3
|
||||||
txt5 = " ";
|
txt5 = " ";
|
||||||
}
|
}
|
||||||
// Create three text elements
|
// Create three text elements
|
||||||
var paddedText_1 = new Text(txt1, new Style(txt1 == "0" ? Color.DarkSlateGray3 : Color.Blue, Color.Black));
|
text1 = new Text(txt1, new Style(txt1 == "0" ? Color.DarkSlateGray3 : Color.Blue, Color.Black));
|
||||||
var paddedText_2 = new Text(txt2, new Style(txt2 == "0" ? Color.DarkSlateGray3 : Color.Blue, Color.Black));
|
text2 = new Text(txt2, new Style(txt2 == "0" ? Color.DarkSlateGray3 : Color.Blue, Color.Black));
|
||||||
var paddedText_3 = new Text(txt3, new Style(txt3 == "0" ? Color.DarkSlateGray3 : Color.Blue, Color.Black));
|
text3 = new Text(txt3, new Style(txt3 == "0" ? Color.DarkSlateGray3 : Color.Blue, Color.Black));
|
||||||
var paddedText_4 = new Text(txt4, new Style(txt4 == "0" ? Color.DarkSlateGray3 : Color.Blue, Color.Black));
|
text4 = new Text(txt4, new Style(txt4 == "0" ? Color.DarkSlateGray3 : Color.Blue, Color.Black));
|
||||||
var paddedText_5 = new Text(txt5, new Style(txt5 == "0" ? Color.DarkSlateGray3 : Color.Blue, Color.Black));
|
text5 = new Text(txt5, new Style(txt5 == "0" ? Color.DarkSlateGray3 : Color.Blue, Color.Black));
|
||||||
|
|
||||||
// Apply padding to the three text elements
|
// Apply padding to the three text elements
|
||||||
pad_1 = new Padder(paddedText_1); //.PadRight(16).PadBottom(0).PadTop(4);
|
//padCol1 = new Padder(text1).PadRight(0).PadBottom(0).PadTop(4);
|
||||||
pad_2 = new Padder(paddedText_2); //.PadBottom(0).PadTop(2);
|
//padCol2 = new Padder(text2); //.PadBottom(0).PadTop(2);
|
||||||
pad_3 = new Padder(paddedText_3); //.PadLeft(16).PadBottom(0).PadTop(0);
|
//pacCol3 = new Padder(text3); //.PadLeft(16).PadBottom(0).PadTop(0);
|
||||||
pad_4 = new Padder(paddedText_4); //.PadLeft(16).PadBottom(0).PadTop(0);
|
//padCol4 = new Padder(text4); //.PadLeft(16).PadBottom(0).PadTop(0);
|
||||||
pad_5 = new Padder(paddedText_5); //.PadLeft(16).PadBottom(0).PadTop(0);
|
//padCol5 = new Padder(text5); //.PadLeft(16).PadBottom(0).PadTop(0);
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue