diff --git a/ave/game.py b/ave/game.py index 180d26f..59db6fd 100644 --- a/ave/game.py +++ b/ave/game.py @@ -35,7 +35,7 @@ def reset(self, items={}): self.inventory = [] self.numbers = {} for i in items.values(): - if self.is_number(i): + if isinstance(i, NumberItem): self.numbers[i.id] = i.default.get_value(self) self.location = "start" @@ -90,7 +90,9 @@ def remove(self, item, value=1): def is_number(self, item): """Check if item is a NumberItem.""" - return isinstance(item, NumberItem) + if not isinstance(item, str): + raise ValueError("item must be a string") + return item in self.numbers def get_inventory(self, items): """Get the names of the character's inventory. @@ -123,7 +125,7 @@ class Game: def __init__(self, file=None, url=None, filename=None, title="untitled", number=None, description="", author="anonymous", - version=0, ave_version=(0, 0), + version=1, ave_version=(0, 0), active=True): """Make the class. diff --git a/ave/test/game_validation.py b/ave/test/game_validation.py index 34a5b1e..bffa76f 100644 --- a/ave/test/game_validation.py +++ b/ave/test/game_validation.py @@ -2,11 +2,13 @@ from .error_handlers import ( AVEFatalError, AVEError, AVEWarning, AVEInfo, AVENote) from ..game import Character +from ..components.items import NumberItem def check_game(game): """Check a game for errors.""" errors = [] + errors += check_metadata(game) errors += check_first_room(game) errors += get_inaccessible_rooms(game) errors += get_undefined_rooms(game) @@ -16,6 +18,33 @@ def check_game(game): return errors +def check_metadata(game): + """Check that the game has valid metadata.""" + errors = [] + if game.title == "untitled": + errors.append(AVEError("The game's title is 'untitled' (the " + "default value).")) + if game.description == "untitled": + errors.append(AVEError("The game's description is '' (the " + "default value).")) + if game.author == "anonymous": + errors.append(AVEWarning("The game's title is 'anonymous' " + "(the default value).")) + if game.version > 1: + errors.append(AVEInfo("The game's verion is greater than 1. " + "It should be an update of a preexisting " + "game.")) + if not isinstance(game.version, int): + errors.append(AVEError("The game's version is not an integer.")) + if max(game.ave_version) > 0: + errors.append(AVENote( + "The game is set to only work on AVE" + ">=" + ".".join(str(i) for i in game.ave_version) + ".")) + if not game.active: + errors.append(AVEInfo("The game is deactivated.")) + return errors + + def check_first_room(game): """Check that the first room of the game works.""" errors = [] @@ -98,7 +127,7 @@ def explore_items(game): numbers = set() named_items = set() for i in game.items: - if c.is_number(i): + if isinstance(i, NumberItem): numbers.add(i) if i.default.get_value(c) != 0: used_num.add(i) diff --git a/games/make.ave b/games/make.ave index f710ff7..bc4f6da 100644 --- a/games/make.ave +++ b/games/make.ave @@ -7,8 +7,8 @@ vv 1 vv # start You wake up. It is the weekend, so you decide to write an AVE game. After spending some time thinking, you decide to write a shopping simulator. -To test your game, you need to download the latest Python version of AVE, or the VirtualBox image of it. ?! __PYTHON__ -Help me download and run the Python version or image => download ?! __PYTHON__ +To test your game, you need to download the latest Python version of AVE, or the VirtualBox image of it. +Help me download and run the Python version or image => download Get started => go # go diff --git a/games/tea.ave b/games/tea.ave index 157750e..1124e6d 100644 --- a/games/tea.ave +++ b/games/tea.ave @@ -217,7 +217,7 @@ Walk down the stairs => trollbridge_in You are at one end of a bridge guarded by a troll. On the other end of the bridge is a grand golden doorway. The troll says: "You look horrible, clean yourself up, you cannot pass." ?! face_washed -"You look nice. I like your face." ? face_washed ?! real_tea +"You look nice. I like your face." ? face_washed ?! realtea "Why have you given me a note from your mother?" ? troll_note ?! troll_crossed The troll takes pity on you and allows you to cross. ? troll_note ?! troll_crossed Give the troll your note => trollbridge_in ? face_washed ? mystery_note ~ mystery_note + troll_note @@ -230,7 +230,7 @@ You are at one end of a bridge guarded by a troll. On the other end of the bridg The troll says: "You look nice. I like your face." ? face_washed "You have a receipt. I want it. Please give it to me" ? receipt -"You didn't bring me back a present. I don't like you anymore" ? real_tea ?! receipt ?! troll_receipt +"You didn't bring me back a present. I don't like you anymore" ? realtea ?! receipt ?! troll_receipt Give the troll your receipt => trollbridge_mug + mug ? receipt ~ receipt + troll_receipt Cross the bridge => troll_kill ?! troll_receipt Cross the bridge => ornate_doorway ? troll_receipt @@ -276,14 +276,14 @@ Conveniently, there is some milk here as well. You grab it. Continue => tea_aisle # checkout_choice -You need to have an item before you can check out. ?! yorkshire ?! pg_tips ?! real_tea -You have two choices. You can either go to self-checkout or regular checkout. ? yorkshire ?! real_tea -You have two choices. You can either go to self-checkout or regular checkout. ? pg_tips ?! real_tea -You already paid. What are you doing? ? real_tea -Go to the regular checkout => checkout ? pg_tips ?! real_tea -Go to self-checkout => self_check ? pg_tips ?! real_tea -Go to the regular checkout => checkout ? yorkshire ?! real_tea -Go to self-checkout => self_check ? yorkshire ?! real_tea +You need to have an item before you can check out. ?! yorkshire ?! pg_tips ?! realtea +You have two choices. You can either go to self-checkout or regular checkout. ? yorkshire ?! realtea +You have two choices. You can either go to self-checkout or regular checkout. ? pg_tips ?! realtea +You already paid. What are you doing? ? realtea +Go to the regular checkout => checkout ? pg_tips ?! realtea +Go to self-checkout => self_check ? pg_tips ?! realtea +Go to the regular checkout => checkout ? yorkshire ?! realtea +Go to self-checkout => self_check ? yorkshire ?! realtea Go back to the tea aisle => tea_aisle # self_check diff --git a/games/test.ave b/games/test.ave index 9d3ad3b..f6ea1a6 100644 --- a/games/test.ave +++ b/games/test.ave @@ -3,6 +3,7 @@ ** Matthew Scroggs ** vv 1 vv ~~ off ~~ +:: 1.9 :: # start You wake up. What do you want to do? diff --git a/test/test_games.py b/test/test_games.py index 0020bf0..21b63bb 100644 --- a/test/test_games.py +++ b/test/test_games.py @@ -35,20 +35,18 @@ def test_games_for_errors(filename): game = load_game_from_file(filename) game.load() - issues = check_game(game) - errors = [i for i in issues if i.error_value > 3] - info = [i for i in issues if i.error_value <= 3] - errors.sort(key=lambda e: -e.error_value) - info.sort(key=lambda e: -e.error_value) - - if len(errors) > 0: - print("\n " + str(len(errors)) + " errors(s) in " + filename) - for e in errors: - print(e) - if len(info) > 0: - print("\n " + str(len(info)) + " info(s) in " + filename) - for e in info: - print(e) + errors = check_game(game) + + for i in range(5, 0, -1): + ls = [e for e in errors if e.error_value == i] + if len(ls) > 0: + print("") + for e in ls: + print(e) + + # remove Info and Note errors + + errors = [i for i in errors if i.error_value > 2] if filename.endswith("test.ave"): assert len(errors) == 1 @@ -58,12 +56,12 @@ def test_games_for_errors(filename): assert len(errors) == 0 -def test_game_library(): +def xtest_game_library(): ave = AVE() ave.get_download_menu() -def test_load_game_from_library(): +def xtest_load_game_from_library(): ave = AVE() game = load_game_from_library(ave.get_download_menu()[0][2]) game.load()