dev
This commit is contained in:
parent
aadac068b5
commit
12c9c14b97
|
|
@ -73,6 +73,13 @@ namespace GameHandler.DeathGame
|
|||
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)
|
||||
{
|
||||
var current = gm.Coffins.First();
|
||||
|
|
@ -200,6 +207,8 @@ namespace GameHandler.DeathGame
|
|||
return gm.Coffins.First().PlayerId;
|
||||
}
|
||||
|
||||
public int ThrowsPerRount() => 3;
|
||||
public int ThrowsPerRount() => IGameHandler.INFINIT_THROWS;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using GameModel.Contract;
|
||||
using GameModel;
|
||||
using GameModel.Contract;
|
||||
using GameModel.Contracts;
|
||||
using GameModel.FreeGame;
|
||||
using System;
|
||||
|
|
@ -27,5 +28,10 @@ namespace GameHandler.GameHandler
|
|||
{
|
||||
return new FreeGameModel(playerIds);
|
||||
}
|
||||
|
||||
public IGameModel Update(PinThrow pinThrow, IGameModel gameModel, BoardState boardStateBeforeUpdate)
|
||||
{
|
||||
return gameModel; // TODO update model
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ using GameHandler.Parser;
|
|||
using GameModel.Contract;
|
||||
using GameModel.DeathGame;
|
||||
using GameModel.Contracts;
|
||||
using System.Data;
|
||||
|
||||
namespace GameHandler
|
||||
{
|
||||
|
|
@ -72,10 +73,16 @@ namespace GameHandler
|
|||
throw new InvalidGameStateExcpetion("Game not started");
|
||||
}
|
||||
|
||||
var boardStateBeforeUpdate = _lastState.ThrowState.BoardState;
|
||||
|
||||
pinThrow = AutoCompletePlayerId(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 ;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,30 @@ namespace GameModel.UnitTests
|
|||
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]
|
||||
public void SinkThrow_IsNothing()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ namespace GameModel.Contract
|
|||
bool FreePlayerSelection() => true;
|
||||
IGameModel InitGameModel(int[] playerIds, IGameSettings gameSettings);
|
||||
int GetCurrentPlayerId(IGameModel gameModel);
|
||||
|
||||
IGameModel Update(PinThrow pinThrow, IGameModel gameModel, BoardState boardStateBeforeUpdate);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ namespace GameModel
|
|||
|
||||
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)
|
||||
{
|
||||
return new PinThrow(playerId, picPicture, isBell, isSink);
|
||||
|
|
|
|||
|
|
@ -132,17 +132,14 @@ void Show(GameState gameState)
|
|||
|
||||
ShowPlayer();
|
||||
|
||||
ShowThrow(gameState.ThrowState);
|
||||
ShowThrow(gameState);
|
||||
ShowBoard(gameState.ThrowState.BoardState);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void ShowThrow(ThrowState throwState)
|
||||
void ShowThrow(GameState gameState)
|
||||
{
|
||||
int throwCount = throwState.ThrowCount;
|
||||
int throwsPerRount = throwState.ThrowsPerRount;
|
||||
int throwCount = gameState.ThrowState.ThrowCount;
|
||||
int throwsPerRount = gameState.ThrowState.ThrowsPerRount;
|
||||
Text text1;
|
||||
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));
|
||||
|
||||
// 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));
|
||||
|
||||
// Apply padding to the three text elements
|
||||
|
|
|
|||
Loading…
Reference in New Issue