예제 #1
0
        static void Main(string[] args)
        {
            PlayerManager      player              = new PlayerManager();
            EventBus           eventBus            = new EventBus();
            DeckManager        deckManager         = new DeckManager();
            PlayerEventHandler playerEventHandlerA = new PlayerEventHandler();
            PlayerEventHandler playerEventHandlerB = new PlayerEventHandler();
            PlayerEventHandler winner              = new PlayerEventHandler();

            var         playerA     = player.CreatePlayerDeck(1, deckManager.CreateDeck());
            var         playerB     = player.CreatePlayerDeck(2, deckManager.CreateDeck());
            PlayerModel testPlayerA = player.CreatePlayer(1, "playerA", -4);
            PlayerModel testPlayerB = player.CreatePlayer(2, "playerB", 4);

            eventBus.CheckPlayerLuck(playerEventHandlerA, player, testPlayerA);
            eventBus.CheckPlayerDeck(playerEventHandlerA, playerA);
            eventBus.ShowMessage(playerEventHandlerA);

            eventBus.CheckPlayerLuck(playerEventHandlerB, player, testPlayerB);
            eventBus.CheckPlayerDeck(playerEventHandlerB, playerB);
            eventBus.ShowMessage(playerEventHandlerB);

            eventBus.CheckWinner(winner, playerA, playerB);
            eventBus.ShowMessage(winner);

            Console.ReadKey();
        }
예제 #2
0
        public void GetDecks()
        {
            DeckManager dm = createDM();

            var deck1ID = dm.CreateDeck("测试卡组1");
            var deck2ID = dm.CreateDeck("测试卡组2");

            var decks = dm.GetDecks();

            Assert.AreEqual(decks.Count, 2);
            Assert.AreEqual("测试卡组1", decks[deck1ID]);
            Assert.AreEqual("测试卡组2", decks[deck2ID]);
        }
예제 #3
0
        public void DeckCreate()
        {
            DeckManager dm = createDM();

            var id   = dm.CreateDeck("测试卡组");
            var name = dm.GetDeckName(id);

            Assert.AreEqual("测试卡组", name);

            GameObject.Destroy(dm.gameObject);
        }
예제 #4
0
        public void CardsAdd()
        {
            DeckManager dm = createDM();

            var deckID = dm.CreateDeck("测试卡组");

            var instID1 = dm.AddCard(deckID, 1000);
            var instID2 = dm.AddCard(deckID, 1001);

            Assert.AreEqual(1000, dm.GetCardID(instID1));
            Assert.AreEqual(1001, dm.GetCardID(instID2));
        }
예제 #5
0
        public void GetDeckCards()
        {
            DeckManager dm = createDM();

            var deckID = dm.CreateDeck("测试卡组");

            var instID1 = dm.AddCard(deckID, 1000);
            var instID2 = dm.AddCard(deckID, 1001);

            var cards = dm.GetDeckCards(deckID);

            Assert.AreEqual(cards.Count, 2);
            Assert.AreEqual(1000, cards[instID1]);
            Assert.AreEqual(1001, cards[instID2]);
        }
예제 #6
0
        public void CardRemove()
        {
            DeckManager dm = createDM();

            var deckID = dm.CreateDeck("测试卡组");

            var instID1 = dm.AddCard(deckID, 1000);
            var instID2 = dm.AddCard(deckID, 1001);

            dm.RemoveCard(instID2);

            System.Threading.Thread.Sleep(50);

            Assert.AreEqual(1000, dm.GetCardID(instID1));
            Assert.AreEqual(-1, dm.GetCardID(instID2));
        }
예제 #7
0
        public void CardsTransation()
        {
            DeckManager dm = createDM();

            var deckID = dm.CreateDeck("测试卡组");

            var instID1 = dm.AddCard(deckID, 1000);
            var instID2 = dm.AddCard(deckID, 1001);

            // 进入事务
            dm.EnterTransaction();

            var instID3 = dm.AddCard(deckID, 1003);

            dm.RemoveCard(instID1);

            Assert.AreEqual(-1, dm.GetCardID(instID1));
            Assert.AreEqual(1003, dm.GetCardID(instID3));

            // 尝试回滚
            dm.Rollback();
            Assert.AreEqual(1000, dm.GetCardID(instID1));
            Assert.AreEqual(-1, dm.GetCardID(instID3));

            // 进入事务
            dm.EnterTransaction();
            instID3 = dm.AddCard(deckID, 1003);
            dm.RemoveCard(instID2);

            Assert.AreEqual(-1, dm.GetCardID(instID2));
            Assert.AreEqual(1003, dm.GetCardID(instID3));

            // 提交
            dm.Commit();
            Assert.AreEqual(-1, dm.GetCardID(instID2));
            Assert.AreEqual(1003, dm.GetCardID(instID3));
        }