KoogleV4/GameHandler/GameService.cs

72 lines
1.8 KiB
C#

using GameModel;
using GameModel.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GameHandler
{
public class GameService
{
public const int INFINIT_THROWS = 9999;
private bool _isStarted = false;
private ThrowHandler _th;
private ThrowState _lastState;
public string ThrowModeName
{
get
{
if (_lastState != null)
{
return _lastState.BoardState.ThrowMode == ThrowMode.Decrease ? "Abräumen" : "Volle";
}
return string.Empty;
}
}
public ThrowState Start(int GameTypeId=0)
{
if (_isStarted)
{
throw new InvalidGameStateExcpetion("Game already started");
}
if (!_isStarted)
{
_isStarted = true;
}
_th = new ThrowHandler();
var throwMode = GameTypeId == 0 ? ThrowMode.Reposition : ThrowMode.Decrease;
var throwsPerRount = GameTypeId == 0 ? INFINIT_THROWS : 3;
_lastState = ThrowState.Create(throwMode, throwsPerRount);
return _lastState;
}
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;
}
}
}