private void Instantiate() { int[] InitialBoard = BackgammonGame.DefaultGameBoard; // Board.TestBoard3; Board = new Board(InitialBoard); Model = new BackgammonGame(InitialBoard, new RealDice()); ViewInterface = new ViewInterface(Model); Model.ConnectView(this); if (WhitePlayer == PlayerType.Online) { TCPManager.Instance.Instantiate(Model, White); } if (BlackPlayer == PlayerType.Online) { TCPManager.Instance.Instantiate(Model, Black); } if (OptionScreen.ShowPips.SwitchedOn) { WhitePips = new Image() { Text = "White: " + Model.GetGameBoardState().pip(White), Position = new Vector2(Board.midX, 700) }; BlackPips = new Image() { Text = "Black: " + Model.GetGameBoardState().pip(Black), Position = new Vector2(Board.midX, 20) }; WhitePips.LoadContent(); BlackPips.LoadContent(); } }
public void TestChangesRegisteredProperlyAfterNotifyViewFlushesChanges() { List <int[]> moves = new List <int[]>() { ar(1, 3), ar(4, 4) }; fd = new FakeDice(moves); bg = new BackgammonGame(BackgammonGame.DefaultGameBoard, fd); bg.Move(White, 6, 3); var changes = bg.GetChanges(); Assert.AreEqual(3, changes.Count()); var c1 = changes[0]; var c2 = changes[1]; var c3 = changes[2]; Assert.IsTrue(c1.IsDiceState(), "c1 is not dice state"); Assert.IsTrue(c2.IsMove(), "c2 is not move"); Assert.IsTrue(c3.IsDiceState(), "c3 is not dice state"); Assert.IsTrue(arrayEqual(ar(1, 3), c1.AsDiceState().GetDiceValues()), "Expected 1,3 but got " + string.Join(",", c1.AsDiceState().GetDiceValues())); Assert.AreEqual("w 6 3", c2.AsMove().DebugString(), "Expected w 6 3, got " + c2.AsMove().DebugString()); Assert.IsTrue(arrayEqual(new int[] { 1 }, c3.AsDiceState().GetDiceValues())); //At least one view has to be present for backgammon game to flush the recent changes View view = new DummyView(); bg.ConnectView(view); bg.NotifyAllViews(); //Disconnecting the view again so that we may read the changes bg.DisconnectView(view); changes = bg.GetChanges(); Assert.AreEqual(0, changes.Count()); bg.Move(White, 6, 5); changes = bg.GetChanges(); Assert.AreEqual(2, changes.Count()); var c4 = changes[0]; var c5 = changes[1]; Assert.IsTrue(c4.IsMove()); Assert.IsTrue(c5.IsDiceState()); Assert.AreEqual("w 6 5", c4.AsMove().DebugString()); Assert.IsTrue(arrayEqual(new int[] { 4, 4, 4, 4 }, c5.AsDiceState().GetDiceValues())); }