KoogleV4/GameHandler/GameService.cs

55 lines
1.2 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
{
private bool _isStarted = false;
private ThrowHandler _th;
private BoardState _lastState;
public BoardState Start()
{
if (_isStarted)
{
throw new InvalidGameStateExcpetion("Game already started");
}
if (!_isStarted)
{
_isStarted = true;
}
_th = new ThrowHandler();
_lastState = BoardState.Create(ThrowMode.Decrease);
return _lastState;
}
public BoardState 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;
}
}
}