This commit is contained in:
Christian Kauer 2023-12-22 22:05:36 +01:00
parent 364223fdf5
commit 113f7bb561
7 changed files with 135 additions and 26 deletions

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GameContract
{
public interface IGameHandler
{
static string GetGameName() => "Default Hello from interface";
}
}

View File

@ -47,7 +47,7 @@ namespace GameHandler.UnitTests
public void HandleThrow_UpdateTheBoardState()
{
GameService service = new GameService();
var ts1 = service.Start();
var ts1 = service.Start(1);
var bs1 = ts1.BoardState;
var pinThrow = PinThrow.Create(1,PinPicture.Create(1,PinState.Down), false, false);

View File

@ -1,4 +1,5 @@
using GameModel;
using GameContract;
using GameModel;
using GameModel.DeathGame;
using System;
using System.Collections.Generic;
@ -11,7 +12,7 @@ namespace GameHandler.DeathGame
public delegate void CoffinCompleted(Coffin coffin);
public delegate void FirstThrowFailed(Coffin coffin);
public class DeathGameHandler
public class DeathGameHandler : IGameHandler
{
const int MIN_PLAYER_COUNT = 3;
const int MAX_PLAYER_COUNT = 12;
@ -176,5 +177,10 @@ namespace GameHandler.DeathGame
return result;
}
public static string GetGameName()
{
return "Totenkiste";
}
}
}

View File

@ -0,0 +1,17 @@
using GameContract;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GameHandler.GameHandler
{
public class FreeGameHandler : IGameHandler
{
public static string GetGameName()
{
return "Freies Spiel";
}
}
}

View File

@ -1,8 +1,10 @@
using GameModel;
using GameContract;
using GameModel;
using GameModel.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
@ -16,11 +18,16 @@ namespace GameHandler
private ThrowHandler _th;
private ThrowState _lastState;
public GameService()
{
LoadGameHandler();
}
public string ThrowModeName
{
get
{
if (_lastState != null)
if (_lastState != null)
{
return _lastState.BoardState.ThrowMode == ThrowMode.Decrease ? "Abräumen" : "Volle";
}
@ -28,12 +35,12 @@ namespace GameHandler
}
}
public ThrowState Start(int GameTypeId=0)
public ThrowState Start(string gameName) // TODO: add players
{
if (_isStarted)
{
throw new InvalidGameStateExcpetion("Game already started");
}
}
if (!_isStarted)
{
_isStarted = true;
@ -48,7 +55,7 @@ namespace GameHandler
return _lastState;
}
public ThrowState HandleThrow(PinThrow pinThrow)
public ThrowState HandleThrow(PinThrow pinThrow)
{
if (!_isStarted)
{
@ -67,5 +74,24 @@ namespace GameHandler
}
_isStarted = false;
}
public static Dictionary<string, Type> LoadGameHandler()
{
var res = new Dictionary<string, Type>();
var type = typeof(IGameHandler);
var types = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(s => s.GetTypes())
.Where(p => type.IsAssignableFrom(p) && (!p.IsInterface));
foreach (var item in types)
{
MethodInfo staticMethodInfo = item.GetMethod("GetGameName");
string returnValue = Convert.ToString(staticMethodInfo.Invoke(null, new object[] { }));
res.Add(returnValue, item);
}
return res;
}
}
}

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GameModel.FreeGame
{
public record FreeGameModel
{
}
}

View File

@ -8,26 +8,29 @@ using Spectre.Console;
using static System.Runtime.InteropServices.JavaScript.JSType;
AnsiConsole.MarkupLine("Welcome to [green]koogle[/]");
do
ShowMainMenu();
void ShowMainMenu()
{
var option = AnsiConsole.Prompt(
new SelectionPrompt<Option>()
.Title("Was willst du tun?")
.PageSize(10)
.MoreChoicesText("[grey](Move up and down)[/]")
.AddChoices(new[] {
do
{
var option = AnsiConsole.Prompt(
new SelectionPrompt<Option>()
.Title("Was willst du tun?")
.PageSize(10)
.MoreChoicesText("[grey](Move up and down)[/]")
.AddChoices(new[] {
new Option("Neues Spiel",NewGameAction),
new Option("Stammdaten", MasterDataAction),
new Option("Beenden", null)
}));
option.Action?.Invoke();
}));
option.Action?.Invoke();
if (option.Name == "Beenden")
{
break;
}
} while (true) ;
if (option.Name == "Beenden")
{
break;
}
} while (true);
}
void MasterDataAction()
{
@ -37,9 +40,40 @@ void MasterDataAction()
GameService _gs;
void NewGameAction()
{
var option = string.Empty;
//do
//{
var games = GameService.LoadGameHandler().Keys.Order().ToList();
games.Add("Abbreche");
option = AnsiConsole.Prompt(
new SelectionPrompt<string>()
.Title("Was willst du tun?")
.PageSize(10)
.MoreChoicesText("[grey](Move up and down)[/]")
.AddChoices(games));
//if (option == "Abbrechen")
//{
// break;
//}
//} while (true);
if (option == "Abbrechen")
{
ShowMainMenu();
}
else
{
StartGameAction(option);
}
}
void StartGameAction(string gameName)
{
_gs = new GameService();
var bs = _gs.Start(1);
var bs = _gs.Start(gameName);
Show(bs);
@ -73,8 +107,9 @@ void NewGameAction()
bs = _gs.HandleThrow(PinThrow.Create(throwData.Pindata, throwData.Bell, throwData.Sink, throwData.PlayerId));
Show(bs);
} while (true) ;
} while (true);
ShowMainMenu();
}
void Show(ThrowState throwState)