This commit is contained in:
Christian Kauer 2023-12-24 10:33:50 +01:00
parent aadac068b5
commit 12c9c14b97
7 changed files with 58 additions and 11 deletions

View File

@ -73,6 +73,13 @@ namespace GameHandler.DeathGame
return new DeathGameModel(1, coffins.OrderBy(_ => random.Next()).ToList().ToArray(), deathGameSettings); return new DeathGameModel(1, coffins.OrderBy(_ => random.Next()).ToList().ToArray(), deathGameSettings);
} }
public IGameModel Update(PinThrow pinThrow, IGameModel gameModel, BoardState boardStateBeforeUpdate)
{
var isTrowIntoAllPins = boardStateBeforeUpdate.PinPicture.UpCount == 9;
var boardCleared = pinThrow.IsCleared;
return CalcNextModel(gameModel as DeathGameModel, pinThrow.PinCount, isTrowIntoAllPins, boardCleared);
}
public DeathGameModel CalcNextModel(DeathGameModel gm, int pinCount, bool isTrowIntoAllPins, bool boardCleared) public DeathGameModel CalcNextModel(DeathGameModel gm, int pinCount, bool isTrowIntoAllPins, bool boardCleared)
{ {
var current = gm.Coffins.First(); var current = gm.Coffins.First();
@ -200,6 +207,8 @@ namespace GameHandler.DeathGame
return gm.Coffins.First().PlayerId; return gm.Coffins.First().PlayerId;
} }
public int ThrowsPerRount() => 3; public int ThrowsPerRount() => IGameHandler.INFINIT_THROWS;
} }
} }

View File

@ -1,4 +1,5 @@
using GameModel.Contract; using GameModel;
using GameModel.Contract;
using GameModel.Contracts; using GameModel.Contracts;
using GameModel.FreeGame; using GameModel.FreeGame;
using System; using System;
@ -27,5 +28,10 @@ namespace GameHandler.GameHandler
{ {
return new FreeGameModel(playerIds); return new FreeGameModel(playerIds);
} }
public IGameModel Update(PinThrow pinThrow, IGameModel gameModel, BoardState boardStateBeforeUpdate)
{
return gameModel; // TODO update model
}
} }
} }

View File

@ -12,6 +12,7 @@ using GameHandler.Parser;
using GameModel.Contract; using GameModel.Contract;
using GameModel.DeathGame; using GameModel.DeathGame;
using GameModel.Contracts; using GameModel.Contracts;
using System.Data;
namespace GameHandler namespace GameHandler
{ {
@ -72,10 +73,16 @@ namespace GameHandler
throw new InvalidGameStateExcpetion("Game not started"); throw new InvalidGameStateExcpetion("Game not started");
} }
var boardStateBeforeUpdate = _lastState.ThrowState.BoardState;
pinThrow = AutoCompletePlayerId(pinThrow); pinThrow = AutoCompletePlayerId(pinThrow);
var throwState = _th.Update(_lastState.ThrowState, pinThrow); var throwState = _th.Update(_lastState.ThrowState, pinThrow);
_lastState = _lastState with { ThrowState = throwState }; var gameModel = _gh.Update(pinThrow, _lastState.GameModel, boardStateBeforeUpdate);
// todo: update expense model
_lastState = _lastState with { ThrowState = throwState, GameModel = gameModel };
return _lastState ; return _lastState ;
} }

View File

@ -23,6 +23,30 @@ namespace GameModel.UnitTests
Assert.That(t.PinCount, Is.EqualTo(9)); Assert.That(t.PinCount, Is.EqualTo(9));
} }
[Test]
public void IsCleared_IsFalseWhenAtLeastOnePinIsUp()
{
var pic = new PinPicture(PinState.Down, PinState.Down, PinState.Up, PinState.Down, PinState.Down, PinState.Down, PinState.Down, PinState.Down, PinState.Down);
var t = PinThrow.Create(1, pic, false, true);
Assert.That(t.IsCleared, Is.False);
}
[Test]
public void IsCleared_IsTrueWhenAllPinsAreDown()
{
var pic = new PinPicture(PinState.Down, PinState.Down, PinState.Down, PinState.Down, PinState.Down, PinState.Down, PinState.Down, PinState.Down, PinState.Down);
var t = PinThrow.Create(1, pic, false, false);
Assert.That(t.IsCleared, Is.True);
}
[Test]
public void IsCleared_IsFalseWhenAllPinsAreDownButSinkIsTrue()
{
var pic = new PinPicture(PinState.Down, PinState.Down, PinState.Down, PinState.Down, PinState.Down, PinState.Down, PinState.Down, PinState.Down, PinState.Down);
var t = PinThrow.Create(1, pic, false, true);
Assert.That(t.IsCleared, Is.False);
}
[Test] [Test]
public void SinkThrow_IsNothing() public void SinkThrow_IsNothing()
{ {

View File

@ -21,6 +21,8 @@ namespace GameModel.Contract
bool FreePlayerSelection() => true; bool FreePlayerSelection() => true;
IGameModel InitGameModel(int[] playerIds, IGameSettings gameSettings); IGameModel InitGameModel(int[] playerIds, IGameSettings gameSettings);
int GetCurrentPlayerId(IGameModel gameModel); int GetCurrentPlayerId(IGameModel gameModel);
IGameModel Update(PinThrow pinThrow, IGameModel gameModel, BoardState boardStateBeforeUpdate);
} }
} }

View File

@ -19,6 +19,8 @@ namespace GameModel
public bool IsNoWood => PicPicture.DownCount == 0 && !IsSink; public bool IsNoWood => PicPicture.DownCount == 0 && !IsSink;
public bool IsCleared => PicPicture.UpCount == 0 && !IsSink;
public static PinThrow Create(int playerId, PinPicture picPicture, bool isBell, bool isSink) public static PinThrow Create(int playerId, PinPicture picPicture, bool isBell, bool isSink)
{ {
return new PinThrow(playerId, picPicture, isBell, isSink); return new PinThrow(playerId, picPicture, isBell, isSink);

View File

@ -132,17 +132,14 @@ void Show(GameState gameState)
ShowPlayer(); ShowPlayer();
ShowThrow(gameState.ThrowState); ShowThrow(gameState);
ShowBoard(gameState.ThrowState.BoardState); ShowBoard(gameState.ThrowState.BoardState);
} }
void ShowThrow(ThrowState throwState) void ShowThrow(GameState gameState)
{ {
int throwCount = throwState.ThrowCount; int throwCount = gameState.ThrowState.ThrowCount;
int throwsPerRount = throwState.ThrowsPerRount; int throwsPerRount = gameState.ThrowState.ThrowsPerRount;
Text text1; Text text1;
if (throwsPerRount == IGameHandler.INFINIT_THROWS) if (throwsPerRount == IGameHandler.INFINIT_THROWS)
{ {
@ -155,7 +152,7 @@ void ShowThrow(ThrowState throwState)
var text1_2 = new Text($"Modus: {_gs.ThrowModeName}", new Style(Color.Red, Color.Black)); var text1_2 = 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: ", new Style(Color.Green, Color.Black)); var paddedText_II = new Text($"Spieler: {gameState.NextPlayerId}", new Style(Color.Green, Color.Black));
var paddedText_III = new Text("Spielzeit: ", new Style(Color.Blue, Color.Black)); var paddedText_III = new Text("Spielzeit: ", new Style(Color.Blue, Color.Black));
// Apply padding to the three text elements // Apply padding to the three text elements