Permalink
Browse files

Tapped lands can't be tapped again.

  • Loading branch information...
1 parent 75ef234 commit 5e59b2ffef8177d0927d89cdad67214c90561fa8 @heynemann committed Aug 18, 2009
Showing with 63 additions and 36 deletions.
  1. +2 −0 libmagic/models.py
  2. +61 −1 tests/unit/test_card.py
  3. +0 −35 tests/unit/test_player.py
View
@@ -261,6 +261,8 @@ def on_play(self, game, position):
def generate_mana(self):
if not self.game or not self in self.position.battlefield:
raise InvalidOperationError(r"The player can only generate mana for terrains in his battlefield.")
+ if self.is_tapped:
+ raise InvalidOperationError(r"The player can't generate mana out of a tapped land.")
self.position.mana += 1
self.is_tapped = True
View
@@ -15,10 +15,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+from copy import deepcopy
+
from formencode.api import Invalid
+from libmagic import Game, Player, Deck, Card, Land, FreeForAll, GameMode, InvalidOperationError
from tests.unit.utils import *
-from libmagic import Card, Land
+import tests.unit.data as data
def test_create_card():
card = Card("some card", 0)
@@ -64,7 +67,64 @@ def test_card_on_play_works():
card.on_play(None, None)
assert True, "It shouldn't do anything"
+def test_card_on_upkeep_works():
+ card = Card("some card", 0)
+ card.on_upkeep(None, None)
+ assert True, "It shouldn't do anything"
+
def test_card_validate_play_works():
card = Card("some card", 0)
card.validate_play(None, None)
assert True, "It shouldn't do anything"
+
+def test_tapping_lands_not_in_game_raises():
+ bernardo = Player(name="Bernardo", deck=deepcopy(data.green_land_deck))
+ land_to_play = bernardo.deck.cards[0]
+ assert_raises(InvalidOperationError, land_to_play.generate_mana, exc_pattern=r"The player can only generate mana for terrains in his battlefield.")
+
+def test_tapping_lands_from_hand_raises():
+ new_game = Game()
+ bernardo = Player(name="Bernardo", deck=deepcopy(data.green_land_deck))
+ john = Player(name="John", deck=data.black_land_deck)
+ new_game.add_player(bernardo)
+ new_game.add_player(john)
+
+ new_game.initialize()
+
+ land_to_play = bernardo.position.hand[0]
+
+ assert_raises(InvalidOperationError, land_to_play.generate_mana, exc_pattern=r"The player can only generate mana for terrains in his battlefield.")
+
+def test_player_can_tap_lands_to_get_mana():
+ new_game = Game()
+ bernardo = Player(name="Bernardo", deck=deepcopy(data.green_land_deck))
+ john = Player(name="John", deck=data.black_land_deck)
+ new_game.add_player(bernardo)
+ new_game.add_player(john)
+
+ new_game.initialize()
+
+ land_to_play = bernardo.position.hand[0]
+ bernardo.play(land_to_play)
+
+ land_to_play.generate_mana() #tap to generate mana
+
+ assert bernardo.position.mana == 1
+ assert land_to_play.is_tapped
+
+def test_generating_mana_out_of_a_tapped_land_raises():
+ new_game = Game()
+ bernardo = Player(name="Bernardo", deck=deepcopy(data.green_land_deck))
+ john = Player(name="John", deck=data.black_land_deck)
+ new_game.add_player(bernardo)
+ new_game.add_player(john)
+
+ new_game.initialize()
+
+ land_to_play = bernardo.position.hand[0]
+ bernardo.play(land_to_play)
+
+ land_to_play.generate_mana() #tap to generate mana
+
+ assert_raises(InvalidOperationError, land_to_play.generate_mana, exc_pattern=r"The player can't generate mana out of a tapped land.")
+
View
@@ -175,38 +175,3 @@ def test_player_can_play_two_lands_in_different_turns():
assert len(bernardo.position.battlefield) == 2
assert bernardo.position.battlefield[1] == land_to_play
-def test_tapping_lands_not_in_game_raises():
- bernardo = Player(name="Bernardo", deck=deepcopy(data.green_land_deck))
- land_to_play = bernardo.deck.cards[0]
- assert_raises(InvalidOperationError, land_to_play.generate_mana, exc_pattern=r"The player can only generate mana for terrains in his battlefield.")
-
-def test_tapping_lands_from_hand_raises():
- new_game = Game()
- bernardo = Player(name="Bernardo", deck=deepcopy(data.green_land_deck))
- john = Player(name="John", deck=data.black_land_deck)
- new_game.add_player(bernardo)
- new_game.add_player(john)
-
- new_game.initialize()
-
- land_to_play = bernardo.position.hand[0]
-
- assert_raises(InvalidOperationError, land_to_play.generate_mana, exc_pattern=r"The player can only generate mana for terrains in his battlefield.")
-
-def test_player_can_tap_lands_to_get_mana():
- new_game = Game()
- bernardo = Player(name="Bernardo", deck=deepcopy(data.green_land_deck))
- john = Player(name="John", deck=data.black_land_deck)
- new_game.add_player(bernardo)
- new_game.add_player(john)
-
- new_game.initialize()
-
- land_to_play = bernardo.position.hand[0]
- bernardo.play(land_to_play)
-
- land_to_play.generate_mana() #tap to generate mana
-
- assert bernardo.position.mana == 1
- assert land_to_play.is_tapped
-

0 comments on commit 5e59b2f

Please sign in to comment.