102 lines
2.8 KiB
C#
102 lines
2.8 KiB
C#
using GameHandler.Extensions;
|
|
using GameModel;
|
|
using GameModel.Exceptions;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using GameHandler.GameHandler;
|
|
using GameHandler.Parser;
|
|
using GameModel.Contract;
|
|
using GameModel.DeathGame;
|
|
|
|
namespace GameHandler
|
|
{
|
|
public class GameService
|
|
{
|
|
private bool _isStarted = false;
|
|
private IGameHandler _gh;
|
|
private ThrowHandler _th;
|
|
private ThrowState _lastState;
|
|
|
|
public GameService()
|
|
{
|
|
|
|
}
|
|
|
|
public string ThrowModeName
|
|
{
|
|
get
|
|
{
|
|
if (_lastState != null)
|
|
{
|
|
return _lastState.BoardState.ThrowMode == ThrowMode.Decrease ? "Abräumen" : "Volle";
|
|
}
|
|
return string.Empty;
|
|
}
|
|
}
|
|
|
|
static int[] defaultPlayerIds => new[] {1,2,3,4};
|
|
|
|
public ThrowState Start(string gameName = FreeGameHandler.GAMENAME_FREETRAINING) // TODO: add players
|
|
{
|
|
return Start(defaultPlayerIds, new DeathGameSettings(6), gameName);
|
|
}
|
|
|
|
public ThrowState Start(int[] playerIds, IGameSettings gameSettings, string gameName = FreeGameHandler.GAMENAME_FREETRAINING) // TODO: add players
|
|
{
|
|
if (_isStarted)
|
|
{
|
|
throw new InvalidGameStateExcpetion("Game already started");
|
|
}
|
|
_isStarted = true;
|
|
|
|
_gh = this.GetGameHandler(gameName);
|
|
var gm = _gh.InitGameModel(playerIds, gameSettings);
|
|
|
|
_th = new ThrowHandler();
|
|
|
|
//var throwMode = GameTypeId == 0 ? ThrowMode.Reposition : ThrowMode.Decrease;
|
|
//var throwsPerRount = GameTypeId == 0 ? INFINIT_THROWS : 3;
|
|
|
|
_lastState = ThrowState.Create(_gh.ThrowMode(), _gh.ThrowsPerRount());
|
|
return _lastState;
|
|
|
|
}
|
|
|
|
//private IGameHandler GetGameHandler(string gameName)
|
|
//{
|
|
// throw new NotImplementedException();
|
|
//}
|
|
|
|
public ThrowState HandleThrow(PinThrow pinThrow)
|
|
{
|
|
if (!_isStarted)
|
|
{
|
|
throw new InvalidGameStateExcpetion("Game not started");
|
|
}
|
|
|
|
_lastState = _th.Update(_lastState, pinThrow);
|
|
return _lastState;
|
|
}
|
|
|
|
public void Stop()
|
|
{
|
|
if (!_isStarted)
|
|
{
|
|
throw new InvalidGameStateExcpetion("Game not started");
|
|
}
|
|
_isStarted = false;
|
|
}
|
|
|
|
public ThrowCommandData ParseThrowData(string stringData)
|
|
{
|
|
return ThrowCommandParser.Parse(stringData, _gh.FreePlayerSelection(), 0); // TOOD: Player
|
|
}
|
|
|
|
public bool FreePlayerSelection => _gh.FreePlayerSelection();
|
|
}
|
|
}
|