private static async Task MainAsync() { var c1 = new InProcessPlayerCommunicator("player 1"); var c2 = new InProcessPlayerCommunicator("player 2"); var p1 = new Player(c1, new KnuthShuffler()); var p2 = new Player(c2, new KnuthShuffler()); var game = new Game(p1, p2, false); await game.StartGameAsync(); while (!(p1.State.IsDead() || p2.State.IsDead())) { var activeComm = p1.State.IsActive ? c1 : c2; Console.WriteLine("----------"); Console.Write($"Active: {activeComm.PlayerName} ## Enter card index to play or -1 to end turn: "); int idx; if (!int.TryParse(Console.ReadLine(), out idx)) { continue; } if (idx < 0) { activeComm.PerformPlayerAction(new PlayedEventArgs(activeComm.LatestGameState.Tick, PlayerActionType.EndedTurn)); } else if (idx < activeComm.LatestGameState.Hand.Count()) { activeComm.PerformPlayerAction(new PlayedEventArgs(activeComm.LatestGameState.Tick, PlayerActionType.PlayedCard, idx, activeComm.LatestGameState.Hand.ElementAt(idx))); } } }
public async Task InProcessPlayerCommunicator_Performs_Player_Action_Properly() { var ipc = new InProcessPlayerCommunicator("name"); bool received = false; ipc.ActionPerformed += (sender, args) => received = true; ipc.PerformPlayerAction(new PlayedEventArgs(3, PlayerActionType.EndedTurn)); Assert.True(received); }
public async Task Test_InProcessPlayerCommunicator_Shows_Proper_Latest_State() { var ipc = new InProcessPlayerCommunicator("name"); var gs = new GameState(new byte[] { 2, 4 }, 3, 29, 8, 4, true, 14, 13); await ipc.CommunicateWithPlayerAsync(new CommunicationPackage(gs)); Assert.Same(gs, ipc.LatestGameState); gs = new GameState(new byte[] { 2, 4 }, 4, 29, 8, 4, false, 14, 13); await ipc.CommunicateWithPlayerAsync(new CommunicationPackage(gs)); Assert.Same(gs, ipc.LatestGameState); }
public void Test_InProcessPlayerCommunicator_Initialized_Correctly() { var ipc = new InProcessPlayerCommunicator("name"); Assert.Equal("name", ipc.PlayerName); }