Changeset 37638 for lang/csharp

Show
Ignore:
Timestamp:
05/19/10 17:05:33 (3 years ago)
Author:
isaisstillalive
Message:
  • 手札をプレイするメソッドを追加
Location:
lang/csharp/DominionEngine
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lang/csharp/DominionEngine/DominionEngine.Core.Test/GameTest.cs

    r37637 r37638  
    808808 
    809809        #endregion 
     810 
     811        #region Play 
     812 
     813        class PlayTestAction : CardInfo.CardInfo, IAction 
     814        { 
     815            public override Worth Cost 
     816            { 
     817                get { throw new NotImplementedException(); } 
     818            } 
     819 
     820            public void Action() 
     821            { 
     822                Player.Coin += 1; 
     823            } 
     824        } 
     825 
     826        [TestCase(Phase.Action, 1)] 
     827        [TestCase(Phase.Buy, 0)] 
     828        [TestCase(Phase.CleanUp, 0)] 
     829        public void Play_WithAction(Phase phase, int expected) 
     830        { 
     831            Game game = new Game(2); 
     832 
     833            game.SpendableWorth = Worth.None; 
     834 
     835            game.phase = phase; 
     836            game.Play(new Card<PlayTestAction>()); 
     837 
     838            Assert.That(game.Players[0].playArea.Count, Is.EqualTo(expected)); 
     839            Assert.That(game.SpendableWorth, Is.EqualTo(Worth.Coin(expected))); 
     840        } 
     841 
     842        [TestCase(Phase.Action, 0)] 
     843        [TestCase(Phase.Buy, 1)] 
     844        [TestCase(Phase.CleanUp, 0)] 
     845        public void Play_WithTreasure(Phase phase, int expected) 
     846        { 
     847            Game game = new Game(2); 
     848 
     849            game.SpendableWorth = Worth.None; 
     850 
     851            game.phase = phase; 
     852            game.Play(new Card<Copper>()); 
     853 
     854            Assert.That(game.Players[0].playArea.Count, Is.EqualTo(expected)); 
     855            Assert.That(game.SpendableWorth, Is.EqualTo(Worth.Coin(expected))); 
     856        } 
     857 
     858        #endregion 
    810859    } 
    811860} 
  • lang/csharp/DominionEngine/DominionEngine.Core/Game.cs

    r37637 r37638  
    344344            InitializeSupplyPiles(); 
    345345 
     346            CardInfo.AnyPlayer.ClearEvent(); 
    346347            CardInfo.AnyPlayer.CardListGetting += AnyPlayer_CardListGetting; 
    347348            CardInfo.AnyPlayer.Drawing += AnyPlayer_Drawing; 
    348349 
     350            CardInfo.TurnPlayer.ClearEvent(); 
    349351            CardInfo.TurnPlayer.ActionChanged += TurnPlayer_ActionChanged; 
    350352            CardInfo.TurnPlayer.BuyChanged += TurnPlayer_BuyChanged; 
    351353            CardInfo.TurnPlayer.CoinChanged += TurnPlayer_CoinChanged; 
     354        } 
     355 
     356        /// <summary> 
     357        /// カードをプレイする 
     358        /// </summary> 
     359        /// <param name="card"></param> 
     360        public void Play(Card card) 
     361        { 
     362            switch (Phase) 
     363            { 
     364                case Phase.Action: 
     365                    if (!(card.CardInfo is IAction)) return; 
     366                    ((IAction)card.CardInfo).Action(); 
     367                    RemainAction -= 1; 
     368                    break; 
     369 
     370                case Phase.Buy: 
     371                    if (!(card.CardInfo is ITreasure)) return; 
     372                    SpendableWorth += ((ITreasure)card.CardInfo).GenerateWorth; 
     373                    break; 
     374 
     375                default: 
     376                    return; 
     377            } 
     378 
     379            TurnPlayer.hand.Remove(card); 
     380            TurnPlayer.playArea.Add(card); 
    352381        } 
    353382