Beispiel #1
0
        public void CannotWithdrawSomeoneElsesProposal()
        {
            BoardState state = DataTest.SampleGame;
            ProposeLoanAction loan = new ProposeLoanAction { PlayerId = 0, LoanAmount = 123m, PayBack = 124m, Period = state.Settings.YearLength };
            state = Tick.Apply(state, new List<GameAction> { loan });

            int withdrawId = state.Proposals.FindIndex(p => p.LoanAmount == 123m);
            WithdrawProposalAction withdraw = new WithdrawProposalAction { PlayerId = 1, ProposalId = withdrawId };
            state = Tick.Apply(state, new List<GameAction> { withdraw });

            Assert.AreEqual(1, state.Proposals.Count(p => p.LoanAmount == 123m));
        }
Beispiel #2
0
        public void SerializeItAll()
        {
            JoinAction join = new JoinAction { PlayerId = 1, PlayerName = "Test Player" };
            HireWorkerAction hire = new HireWorkerAction { PlayerId = 2 };
            FireWorkerAction fire = new FireWorkerAction { PlayerId = 3 };
            ProposeLoanAction propose = new ProposeLoanAction { PlayerId = 4, Period = TimeSpan.FromMinutes(1.0), PayBack = 20m, LoanAmount = 15m };
            WithdrawProposalAction withdraw = new WithdrawProposalAction { PlayerId = 5, ProposalId = 2 };
            GiveGiftAction gift = new GiveGiftAction { PlayerId = 6, ToPlayerId = 2, GiftAmount = 10.2m };
            AssignWorkerAction research = new AssignWorkerAction { PlayerId = 7, Work = Job.Research, WorkerId = 1 };
            AssignWorkerAction factory = new AssignWorkerAction { PlayerId = 8, Work = Job.Factory, WorkerId = 2 };
            TakeLoanAction loan = new TakeLoanAction { PlayerId = 9, LoanProposalId = 1 };

            StringBuilder sb = new StringBuilder();
            sb.Append("{\"gameJson\": ");
            sb.Append(DataTest.SampleGame.ToJson());
            sb.Append("\n, \"NoOp\": ");
            sb.Append(new NoOpAction().ToJson());
            sb.Append("\n \"JoinGame\": ");
            sb.Append(join.ToJson());
            sb.Append("\n \"HireWorker\": ");
            sb.Append(hire.ToJson());
            sb.Append("\n \"FireWorker\": ");
            sb.Append(fire.ToJson());
            sb.Append("\n \"ProposeLoan\": ");
            sb.Append(propose.ToJson());
            sb.Append("\n \"WithdrawProposal\": ");
            sb.Append(withdraw.ToJson());
            sb.Append("\n \"GiveGift\": ");
            sb.Append(gift.ToJson());
            sb.Append("\n \"AssignWorkerResearch\": ");
            sb.Append(research.ToJson());
            sb.Append("\n \"AssignWorkerFactory\": ");
            sb.Append(factory.ToJson());
            sb.Append("\n \"TakeLoan\": ");
            sb.Append(loan.ToJson());

            List<GameAction> actions = new List<GameAction> { hire, fire, loan };
            string json = GameAction.SerializeList(actions);
            List<GameAction> fromJson = GameAction.DeserializeList(json);

            List<GameAction> empty = new List<GameAction>();
            json = GameAction.SerializeList(empty);
            fromJson = GameAction.DeserializeList(json);
        }