dev
This commit is contained in:
parent
e8ecac57c1
commit
dd24bd4871
|
|
@ -1,9 +1,13 @@
|
||||||
using GameData.Repository;
|
using GameData.Repository;
|
||||||
using GameModel;
|
using GameModel;
|
||||||
|
using GameModel.DeathGame;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
|
|
||||||
namespace GameData.UnitTests
|
namespace GameData.UnitTests
|
||||||
{
|
{
|
||||||
|
record TestRecord(PinState PinState);
|
||||||
|
|
||||||
public class Tests
|
public class Tests
|
||||||
{
|
{
|
||||||
[SetUp]
|
[SetUp]
|
||||||
|
|
@ -11,9 +15,38 @@ namespace GameData.UnitTests
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Serialize_PinPicture()
|
||||||
|
{
|
||||||
|
var r = new TestRecord(PinState.Down);
|
||||||
|
var p = PinPicture.Create();
|
||||||
|
|
||||||
|
string s = JsonConvert.SerializeObject(p);
|
||||||
|
string s2 = JsonConvert.SerializeObject(r);
|
||||||
|
|
||||||
|
var p2 = JsonConvert.DeserializeObject<PinPicture>(s);
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void Test1()
|
public void Test1()
|
||||||
{
|
{
|
||||||
|
var setting = new DeathGameSettings(77);
|
||||||
|
var gm = new DeathGameModel(1, new[] { new Coffin(1, 0, 0) }, setting, new[] { 1, 2, 3 });
|
||||||
|
var gameState = GameState.Create(Guid.NewGuid(), "test", ThrowState.Create(ThrowMode.Reposition,99), 1, gm);
|
||||||
|
|
||||||
|
string test = JsonConvert.SerializeObject(
|
||||||
|
gameState,
|
||||||
|
new JsonSerializerSettings()
|
||||||
|
{
|
||||||
|
TypeNameHandling = TypeNameHandling.Auto
|
||||||
|
});
|
||||||
|
|
||||||
|
var obj = JsonConvert.DeserializeObject<GameState>(test, new JsonSerializerSettings()
|
||||||
|
{
|
||||||
|
TypeNameHandling = TypeNameHandling.Auto
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
//var client = new ExpenseRepository(null, null, null);
|
//var client = new ExpenseRepository(null, null, null);
|
||||||
//var test = client.GetAll();
|
//var test = client.GetAll();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,10 +12,10 @@ namespace GameData.Dummy
|
||||||
{
|
{
|
||||||
List<GameState> gameStates = new List<GameState>();
|
List<GameState> gameStates = new List<GameState>();
|
||||||
|
|
||||||
public Task Save(GameState gameState)
|
public Task<GameState> Save(GameState gameState)
|
||||||
{
|
{
|
||||||
gameStates.Add(gameState);
|
gameStates.Add(gameState);
|
||||||
return Task.CompletedTask;
|
return Task.FromResult(gameState);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GameState Load(Guid gameId)
|
public GameState Load(Guid gameId)
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace GameData.Model
|
namespace GameData.Model
|
||||||
{
|
{
|
||||||
public record GameStateDo(Guid Id, Guid GameId, string GameName, GameState GameState)
|
public record GameStateDo(Guid Id, Guid GameId, string GameName, string GameState)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,13 @@
|
||||||
using GameModel;
|
using GameModel;
|
||||||
using GameModel.Contracts;
|
using GameModel.Contracts;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using static System.Net.Mime.MediaTypeNames;
|
||||||
|
|
||||||
namespace GameData.Repository
|
namespace GameData.Repository
|
||||||
{
|
{
|
||||||
|
|
@ -29,10 +31,22 @@ namespace GameData.Repository
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Save(GameState gameState)
|
public async Task<GameState> Save(GameState gameState)
|
||||||
{
|
{
|
||||||
var gameStateDo = new GameStateDo(gameState.Id, gameState.GameId, gameState.GameName, gameState);
|
var str = JsonConvert.SerializeObject(gameState, new JsonSerializerSettings()
|
||||||
|
{
|
||||||
|
TypeNameHandling = TypeNameHandling.Auto
|
||||||
|
});
|
||||||
|
var gameStateDo = new GameStateDo(gameState.Id, gameState.GameId, gameState.GameName, str);
|
||||||
var res = await _client.Post<GameStateDo>(gameStateDo,UrlGameState);
|
var res = await _client.Post<GameStateDo>(gameStateDo,UrlGameState);
|
||||||
|
|
||||||
|
|
||||||
|
var obj = JsonConvert.DeserializeObject<GameState>(res.GameState, new JsonSerializerSettings()
|
||||||
|
{
|
||||||
|
TypeNameHandling = TypeNameHandling.Auto
|
||||||
|
});
|
||||||
|
|
||||||
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Update(Game game)
|
public async Task Update(Game game)
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,9 @@ namespace GameHandler.UnitTests.Mocks
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task Save(GameState gameState)
|
public Task<GameState> Save(GameState gameState)
|
||||||
{
|
{
|
||||||
return Task.CompletedTask;
|
return Task.FromResult(gameState);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task Update(Game game)
|
public Task Update(Game game)
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ namespace GameModel.Contracts
|
||||||
{
|
{
|
||||||
Task<Game> Create(Game game);
|
Task<Game> Create(Game game);
|
||||||
GameState Load(Guid gameId);
|
GameState Load(Guid gameId);
|
||||||
Task Save(GameState gameState);
|
Task<GameState> Save(GameState gameState);
|
||||||
Task Update(Game game);
|
Task Update(Game game);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,4 +6,8 @@
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using GameModel.Exceptions;
|
using GameModel.Exceptions;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
@ -6,34 +7,156 @@ using System.Linq;
|
||||||
using System.Net.NetworkInformation;
|
using System.Net.NetworkInformation;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Reflection.Metadata.Ecma335;
|
using System.Reflection.Metadata.Ecma335;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace GameModel
|
namespace GameModel
|
||||||
{
|
{
|
||||||
public record PinPicture(PinState PinState1, PinState PinState2, PinState PinState3, PinState PinState4, PinState PinState5, PinState PinState6, PinState PinState7, PinState PinState8, PinState PinState9)
|
public record PinPicture(PinState PinState1, PinState PinState2, PinState PinState3, PinState PinState4, PinState PinState5, PinState PinState6, PinState PinState7, PinState PinState8, PinState PinState9)
|
||||||
: IEnumerable<PinState>, IEnumerable
|
|
||||||
{
|
{
|
||||||
|
public static PinPicture Create()
|
||||||
|
{
|
||||||
|
return PinPicture.Create(PinState.Up, PinState.Up, PinState.Up, PinState.Up, PinState.Up, PinState.Up, PinState.Up, PinState.Up, PinState.Up);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public static PinPicture Create(PinState pinState1, PinState pinState2, PinState pinState3, PinState pinState4, PinState pinState5, PinState pinState6, PinState pinState7, PinState pinState8, PinState pinState9)
|
public static PinPicture Create(PinState pinState1, PinState pinState2, PinState pinState3, PinState pinState4, PinState pinState5, PinState pinState6, PinState pinState7, PinState pinState8, PinState pinState9)
|
||||||
{
|
{
|
||||||
return new PinPicture(pinState1, pinState2, pinState3, pinState4, pinState5, pinState6, pinState7, pinState8, pinState9);
|
return new PinPicture(pinState1, pinState2, pinState3, pinState4, pinState5, pinState6, pinState7, pinState8, pinState9);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PinPicture Create()
|
public static PinPicture Create(int pinNumber, PinState pinState)
|
||||||
{
|
{
|
||||||
return PinPicture.Create(PinState.Up, PinState.Up, PinState.Up, PinState.Up, PinState.Up, PinState.Up, PinState.Up, PinState.Up, PinState.Up);
|
if (pinNumber < 1 || pinNumber > 9)
|
||||||
//pins.Add(PinState1);
|
{
|
||||||
//pins.Add(pinState2);
|
throw new InvalidPinPictureException();
|
||||||
//pins.Add(pinState3);
|
}
|
||||||
//pins.Add(pinState4);
|
|
||||||
//pins.Add(pinState5);
|
var states = new List<PinState>(new[] { PinState.Up, PinState.Up, PinState.Up, PinState.Up, PinState.Up, PinState.Up, PinState.Up, PinState.Up, PinState.Up }).ToArray();
|
||||||
//pins.Add(pinState6);
|
states[pinNumber - 1] = pinState;
|
||||||
//pins.Add(pinState7);
|
return PinPicture.Create(states);
|
||||||
//pins.Add(pinState8);
|
|
||||||
//pins.Add(pinState9);
|
|
||||||
//ValidatePinPicture(pins);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static PinPicture Create(PinState[] states)
|
||||||
|
{
|
||||||
|
return PinPicture.Create(states[0], states[1], states[2], states[3], states[4], states[5], states[6], states[7], states[8]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PinPicture CreateAllPins()
|
||||||
|
{
|
||||||
|
var states = new List<PinState>(new[] { PinState.Down, PinState.Down, PinState.Down, PinState.Down, PinState.Down, PinState.Down, PinState.Down, PinState.Down, PinState.Down }).ToArray();
|
||||||
|
return PinPicture.Create(states);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PinPicture CreateCircle()
|
||||||
|
{
|
||||||
|
var states = new List<PinState>(new[] { PinState.Down, PinState.Down, PinState.Down, PinState.Down, PinState.Up, PinState.Down, PinState.Down, PinState.Down, PinState.Down }).ToArray();
|
||||||
|
return PinPicture.Create(states);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static PinPicture Create(string pindata)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(pindata))
|
||||||
|
{
|
||||||
|
if (!int.TryParse(pindata, out int dummy))
|
||||||
|
{
|
||||||
|
throw new InvalidDataException($"{pindata} cannot be parsed as throw");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var states = new[] {
|
||||||
|
pindata.Contains("1") ? PinState.Down : PinState.Up,
|
||||||
|
pindata.Contains("2") ? PinState.Down : PinState.Up,
|
||||||
|
pindata.Contains("3") ? PinState.Down : PinState.Up,
|
||||||
|
pindata.Contains("4") ? PinState.Down : PinState.Up,
|
||||||
|
pindata.Contains("5") ? PinState.Down : PinState.Up,
|
||||||
|
pindata.Contains("6") ? PinState.Down : PinState.Up,
|
||||||
|
pindata.Contains("7") ? PinState.Down : PinState.Up,
|
||||||
|
pindata.Contains("8") ? PinState.Down : PinState.Up,
|
||||||
|
pindata.Contains("9") ? PinState.Down : PinState.Up,
|
||||||
|
};
|
||||||
|
|
||||||
|
return PinPicture.Create(states);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PinPicture operator +(PinPicture pic, PinThrow pinThrow)
|
||||||
|
{
|
||||||
|
if (pinThrow.IsSink)
|
||||||
|
return pic with { };
|
||||||
|
|
||||||
|
//if (pic.PinState1 == PinState.Down && pinThrow.PicPicture.PinState1 == PinState.Down)
|
||||||
|
//{
|
||||||
|
// throw new InvalidPinCalcExcetion();
|
||||||
|
//}
|
||||||
|
|
||||||
|
return pic with
|
||||||
|
{
|
||||||
|
PinState1 = pinThrow.PicPicture.PinState1 == PinState.Down ? PinState.Down : pic.PinState1,
|
||||||
|
PinState2 = pinThrow.PicPicture.PinState2 == PinState.Down ? PinState.Down : pic.PinState2,
|
||||||
|
PinState3 = pinThrow.PicPicture.PinState3 == PinState.Down ? PinState.Down : pic.PinState3,
|
||||||
|
PinState4 = pinThrow.PicPicture.PinState4 == PinState.Down ? PinState.Down : pic.PinState4,
|
||||||
|
PinState5 = pinThrow.PicPicture.PinState5 == PinState.Down ? PinState.Down : pic.PinState5,
|
||||||
|
PinState6 = pinThrow.PicPicture.PinState6 == PinState.Down ? PinState.Down : pic.PinState6,
|
||||||
|
PinState7 = pinThrow.PicPicture.PinState7 == PinState.Down ? PinState.Down : pic.PinState7,
|
||||||
|
PinState8 = pinThrow.PicPicture.PinState8 == PinState.Down ? PinState.Down : pic.PinState8,
|
||||||
|
PinState9 = pinThrow.PicPicture.PinState9 == PinState.Down ? PinState.Down : pic.PinState9
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public int UpCount
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
var res = 0;
|
||||||
|
res += Convert.ToInt32((PinState1 == PinState.Up));
|
||||||
|
res += Convert.ToInt32((PinState2 == PinState.Up));
|
||||||
|
res += Convert.ToInt32((PinState3 == PinState.Up));
|
||||||
|
res += Convert.ToInt32((PinState4 == PinState.Up));
|
||||||
|
res += Convert.ToInt32((PinState5 == PinState.Up));
|
||||||
|
res += Convert.ToInt32((PinState6 == PinState.Up));
|
||||||
|
res += Convert.ToInt32((PinState7 == PinState.Up));
|
||||||
|
res += Convert.ToInt32((PinState8 == PinState.Up));
|
||||||
|
res += Convert.ToInt32((PinState9 == PinState.Up));
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int DownCount
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
var res = 0;
|
||||||
|
res += Convert.ToInt32((PinState1 == PinState.Down));
|
||||||
|
res += Convert.ToInt32((PinState2 == PinState.Down));
|
||||||
|
res += Convert.ToInt32((PinState3 == PinState.Down));
|
||||||
|
res += Convert.ToInt32((PinState4 == PinState.Down));
|
||||||
|
res += Convert.ToInt32((PinState5 == PinState.Down));
|
||||||
|
res += Convert.ToInt32((PinState6 == PinState.Down));
|
||||||
|
res += Convert.ToInt32((PinState7 == PinState.Down));
|
||||||
|
res += Convert.ToInt32((PinState8 == PinState.Down));
|
||||||
|
res += Convert.ToInt32((PinState9 == PinState.Down));
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool AllUp
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return DownCount == 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public record PinPictureEnum : PinPicture, IEnumerable<PinState>, IEnumerable
|
||||||
|
{
|
||||||
|
public PinPictureEnum(PinState PinState1, PinState PinState2, PinState PinState3, PinState PinState4, PinState PinState5, PinState PinState6, PinState PinState7, PinState PinState8, PinState PinState9) : base(PinState1, PinState2, PinState3, PinState4, PinState5, PinState6, PinState7, PinState8, PinState9)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//private PinPicture(IEnumerable<PinState> pins)
|
//private PinPicture(IEnumerable<PinState> pins)
|
||||||
//{
|
//{
|
||||||
// this.pins = pins.Select(_ => _).ToList();
|
// this.pins = pins.Select(_ => _).ToList();
|
||||||
|
|
@ -62,7 +185,8 @@ namespace GameModel
|
||||||
// throw new InvalidPinPictureException();
|
// throw new InvalidPinPictureException();
|
||||||
//}
|
//}
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
private List<PinState> pins
|
private List<PinState> pins
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
|
@ -71,6 +195,7 @@ namespace GameModel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
public PinState this[int index]
|
public PinState this[int index]
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
|
@ -112,47 +237,9 @@ namespace GameModel
|
||||||
//public PinState PinState8 { get { return this[8]; } set { this[8] = value; } }
|
//public PinState PinState8 { get { return this[8]; } set { this[8] = value; } }
|
||||||
//public PinState PinState9 { get { return this[9]; } set { this[9] = value; } }
|
//public PinState PinState9 { get { return this[9]; } set { this[9] = value; } }
|
||||||
|
|
||||||
public int UpCount
|
|
||||||
{
|
|
||||||
get { return pins.Count(_ => _ == PinState.Up); }
|
|
||||||
}
|
|
||||||
|
|
||||||
public int DownCount
|
|
||||||
{
|
|
||||||
get { return pins.Count(_ => _ == PinState.Down); }
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool AllUp
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return DownCount == 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static PinPicture operator +(PinPicture pic, PinThrow pinThrow)
|
|
||||||
{
|
|
||||||
if (pinThrow.IsSink)
|
|
||||||
return pic with { };
|
|
||||||
|
|
||||||
//if (pic.PinState1 == PinState.Down && pinThrow.PicPicture.PinState1 == PinState.Down)
|
|
||||||
//{
|
|
||||||
// throw new InvalidPinCalcExcetion();
|
|
||||||
//}
|
|
||||||
|
|
||||||
return pic with
|
|
||||||
{
|
|
||||||
PinState1 = pinThrow.PicPicture.PinState1 == PinState.Down ? PinState.Down : pic.PinState1,
|
|
||||||
PinState2 = pinThrow.PicPicture.PinState2 == PinState.Down ? PinState.Down : pic.PinState2,
|
|
||||||
PinState3 = pinThrow.PicPicture.PinState3 == PinState.Down ? PinState.Down : pic.PinState3,
|
|
||||||
PinState4 = pinThrow.PicPicture.PinState4 == PinState.Down ? PinState.Down : pic.PinState4,
|
|
||||||
PinState5 = pinThrow.PicPicture.PinState5 == PinState.Down ? PinState.Down : pic.PinState5,
|
|
||||||
PinState6 = pinThrow.PicPicture.PinState6 == PinState.Down ? PinState.Down : pic.PinState6,
|
|
||||||
PinState7 = pinThrow.PicPicture.PinState7 == PinState.Down ? PinState.Down : pic.PinState7,
|
|
||||||
PinState8 = pinThrow.PicPicture.PinState8 == PinState.Down ? PinState.Down : pic.PinState8,
|
|
||||||
PinState9 = pinThrow.PicPicture.PinState9 == PinState.Down ? PinState.Down : pic.PinState9
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public IEnumerator<PinState> GetEnumerator()
|
public IEnumerator<PinState> GetEnumerator()
|
||||||
{
|
{
|
||||||
|
|
@ -167,58 +254,6 @@ namespace GameModel
|
||||||
return this.GetEnumerator();
|
return this.GetEnumerator();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PinPicture Create(int pinNumber, PinState pinState)
|
|
||||||
{
|
|
||||||
if (pinNumber < 1 || pinNumber > 9)
|
|
||||||
{
|
|
||||||
throw new InvalidPinPictureException();
|
|
||||||
}
|
|
||||||
|
|
||||||
var states = new List<PinState>(new[] { PinState.Up, PinState.Up, PinState.Up, PinState.Up, PinState.Up, PinState.Up, PinState.Up, PinState.Up, PinState.Up }).ToArray();
|
|
||||||
states[pinNumber - 1] = pinState;
|
|
||||||
return PinPicture.Create(states);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static PinPicture Create(PinState[] states)
|
|
||||||
{
|
|
||||||
return PinPicture.Create(states[0], states[1], states[2], states[3], states[4], states[5], states[6], states[7], states[8]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static PinPicture CreateAllPins()
|
|
||||||
{
|
|
||||||
var states = new List<PinState>(new[] { PinState.Down, PinState.Down, PinState.Down, PinState.Down, PinState.Down, PinState.Down, PinState.Down, PinState.Down, PinState.Down }).ToArray();
|
|
||||||
return PinPicture.Create(states);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static PinPicture CreateCircle()
|
|
||||||
{
|
|
||||||
var states = new List<PinState>(new[] { PinState.Down, PinState.Down, PinState.Down, PinState.Down, PinState.Up, PinState.Down, PinState.Down, PinState.Down, PinState.Down }).ToArray();
|
|
||||||
return PinPicture.Create(states);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static PinPicture Create(string pindata)
|
|
||||||
{
|
|
||||||
if (!string.IsNullOrEmpty(pindata))
|
|
||||||
{
|
|
||||||
if (!int.TryParse(pindata, out int dummy))
|
|
||||||
{
|
|
||||||
throw new InvalidDataException($"{pindata} cannot be parsed as throw");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var states = new[] {
|
|
||||||
pindata.Contains("1") ? PinState.Down : PinState.Up,
|
|
||||||
pindata.Contains("2") ? PinState.Down : PinState.Up,
|
|
||||||
pindata.Contains("3") ? PinState.Down : PinState.Up,
|
|
||||||
pindata.Contains("4") ? PinState.Down : PinState.Up,
|
|
||||||
pindata.Contains("5") ? PinState.Down : PinState.Up,
|
|
||||||
pindata.Contains("6") ? PinState.Down : PinState.Up,
|
|
||||||
pindata.Contains("7") ? PinState.Down : PinState.Up,
|
|
||||||
pindata.Contains("8") ? PinState.Down : PinState.Up,
|
|
||||||
pindata.Contains("9") ? PinState.Down : PinState.Up,
|
|
||||||
};
|
|
||||||
|
|
||||||
return PinPicture.Create(states);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ namespace GameModel
|
||||||
{
|
{
|
||||||
public record PinThrow(int PlayerId, PinPicture PicPicture, bool IsBell, bool IsSink)
|
public record PinThrow(int PlayerId, PinPicture PicPicture, bool IsBell, bool IsSink)
|
||||||
{
|
{
|
||||||
public bool IsCircle => !IsSink && PicPicture.DownCount == 8 && (PicPicture[5] == PinState.Up);
|
public bool IsCircle => !IsSink && PicPicture.DownCount == 8 && (PicPicture.PinState5 == PinState.Up);
|
||||||
|
|
||||||
public bool IsNinePins => !IsSink && PinCount == 9;
|
public bool IsNinePins => !IsSink && PinCount == 9;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue