Changeset 37594 for lang/csharp

Show
Ignore:
Timestamp:
05/17/10 01:50:49 (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

    r37592 r37594  
    152152            Assert.That(game.supplyPiles.Count - supplies, Is.EqualTo(-1)); 
    153153            Assert.That(game.readOnlySupplyPiles.Count - readOnlySupplies, Is.EqualTo(-1)); 
     154        } 
     155 
     156        #endregion 
     157 
     158        #endregion 
     159 
     160        #region IsEndOfGame 
     161 
     162        #region 2~4人 
     163 
     164        [Test] 
     165        public void IsEndOfGame_EmptySupplies_False([Range(2, 4)]int players, [Range(0, 2)]int emptySupply) 
     166        { 
     167            Game game = new Game(players); 
     168 
     169            for (int i = 0; i < emptySupply; i++) 
     170                game.supplyPiles[i].Clear(); 
     171 
     172            Assert.That(game.IsEndOfGame, Is.False); 
     173        } 
     174 
     175        [Test] 
     176        public void IsEndOfGame_EmptySupplies_True([Range(2, 4)]int players, [Range(3, 5)]int emptySupply) 
     177        { 
     178            Game game = new Game(players); 
     179 
     180            for (int i = 0; i < emptySupply; i++) 
     181                game.supplyPiles[i].Clear(); 
     182 
     183            Assert.That(game.IsEndOfGame, Is.True); 
     184        } 
     185 
     186        [Test] 
     187        public void IsEndOfGame_EmptyProvince_True([Range(2, 4)]int players) 
     188        { 
     189            Game game = new Game(players); 
     190 
     191            game.supplyPiles.Find(cardlist => cardlist.CardInfo is Province).Clear(); 
     192 
     193            Assert.That(game.IsEndOfGame, Is.True); 
     194        } 
     195 
     196        #endregion 
     197 
     198        #region 5~6人 
     199 
     200        [Test] 
     201        public void IsEndOfGame_ManyPlayers_EmptySupplies_False([Range(5, 6)]int players, [Range(0, 3)]int emptySupply) 
     202        { 
     203            Game game = new Game(players); 
     204 
     205            for (int i = 0; i < emptySupply; i++) 
     206                game.supplyPiles[i].Clear(); 
     207 
     208            Assert.That(game.IsEndOfGame, Is.False); 
     209        } 
     210 
     211        [Test] 
     212        public void IsEndOfGame_ManyPlayers_EmptySupplies_True([Range(5, 6)]int players, [Range(4, 5)]int emptySupply) 
     213        { 
     214            Game game = new Game(players); 
     215 
     216            for (int i = 0; i < emptySupply; i++) 
     217                game.supplyPiles[i].Clear(); 
     218 
     219            Assert.That(game.IsEndOfGame, Is.True); 
     220        } 
     221 
     222        [Test] 
     223        public void IsEndOfGame_ManyPlayers_EmptyProvince_True([Range(5, 6)]int players) 
     224        { 
     225            Game game = new Game(players); 
     226 
     227            game.supplyPiles.Find(supply => supply.CardInfo is Province).Clear(); 
     228 
     229            Assert.That(game.IsEndOfGame, Is.True); 
    154230        } 
    155231 
  • lang/csharp/DominionEngine/DominionEngine.Core/Game.cs

    r37592 r37594  
    9696 
    9797        /// <summary> 
     98        /// 終了条件取得用Provinceサプライパイル 
     99        /// </summary> 
     100        internal IUnitaryCardList provinceSupplyPile; 
     101 
     102        /// <summary> 
    98103        /// サプライパイルを初期化する 
    99104        /// </summary> 
     
    110115            SetSupply<Province>(); 
    111116            SetSupply<Curse>(); 
     117 
     118            provinceSupplyPile = supplyPiles.Find(supply => supply.CardInfo is Province); 
    112119 
    113120            SupplyPiles = readOnlySupplyPiles.AsReadOnly(); 
     
    214221 
    215222        } 
     223 
     224        #region ターン 
     225 
     226        public bool IsEndOfGame 
     227        { 
     228            get 
     229            { 
     230                // Provinceが空なら終了 
     231                if (provinceSupplyPile.Count == 0) return true; 
     232 
     233                // 3人までなら3山。4人以上なら4山切れたら終了 
     234                int emptySupplies = supplyPiles.Count(supply => supply.Count == 0); 
     235                return (emptySupplies >= (Players.Count <= 4 ? 3 : 4)); 
     236            } 
     237        } 
     238 
     239        #endregion 
     240 
     241        #region フェイズ 
     242 
     243        #endregion 
    216244    } 
    217245}