Skip to content

Commit

Permalink
Merge pull request #140 from AVEgame/mscroggs/new_game
Browse files Browse the repository at this point in the history
Mscroggs/new game
  • Loading branch information
mscroggs authored Jul 10, 2020
2 parents a557fb8 + 723058a commit f0002e8
Show file tree
Hide file tree
Showing 12 changed files with 496 additions and 34 deletions.
1 change: 1 addition & 0 deletions .ave.nanorc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ color blue "\+"
color blue "\$"
color green "__.*__"
color green "<newline>"
color green "<money>"
color white "<\|.*\|>"
color green "<\|"
color green "\|>"
6 changes: 4 additions & 2 deletions ave/ave.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,13 @@ def game_loop(self, the_game):
The game
"""
while True:
text, options = the_game.get_room_info(self.character)
text, options = the_game.get_room_info(
self.character, the_game.currency)
self.screen.clear()
self.screen.put_ave_logo()
self.screen.show_inventory(
self.character.get_inventory(the_game.items))
self.character.get_inventory(the_game.items,
the_game.currency))
self.screen.type_room_text(text)
next_id = self.screen.menu(list(options.values()))
the_game.pick_option(
Expand Down
2 changes: 1 addition & 1 deletion ave/display/curses_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def show_inventory(self, inventory):
curses.color_pair(9))
else:
pad.addstr(i + 1, 0, " " * 19, curses.color_pair(9))
pad.refresh(0, 0, 2, WIDTH - 19, 13, WIDTH)
pad.refresh(0, 0, 2, WIDTH - 19, 14, WIDTH)

def type_room_text(self, text):
"""Type the room text."""
Expand Down
28 changes: 20 additions & 8 deletions ave/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def set(self, item, value):
The value to set it to
"""
self.numbers[item] = value
self.currency = "£"

def remove(self, item, value=1):
"""Remove an item or take from a number.
Expand All @@ -94,7 +95,7 @@ def is_number(self, item):
raise ValueError("item must be a string")
return item in self.numbers

def get_inventory(self, items):
def get_inventory(self, items, currency):
"""Get the names of the character's inventory.
Returns
Expand All @@ -108,14 +109,18 @@ def get_inventory(self, items):
if not item.hidden:
name = item.get_name(self)
if name is not None:
inv.append(finalise(name, self.numbers) + ": " + str(n))
display_name = finalise(name, self.numbers, currency)
if item.id != "money" or currency is None:
display_name += ": "
inv.append(display_name + str(n))
for i in self.inventory:
if i in items:
item = items[i]
if not item.hidden:
name = item.get_name(self)
if name is not None:
inv.append(finalise(item.get_name(self), self.numbers))
inv.append(finalise(item.get_name(self), self.numbers,
currency))
return [i for i in inv if i is not None and i != ""]


Expand Down Expand Up @@ -167,7 +172,9 @@ def __init__(self, file=None, url=None,
self.active = active
self.version = version
self.ave_version = tuple(ave_version)
self.currency = None
self.rooms = None
self.items = None

self.options = []

Expand All @@ -184,6 +191,11 @@ def load(self):
else:
raise ValueError("One of url and file must be set to load a game.")

if "money" in self.items:
c = self.items["money"].names[0].text
if c in ["$", "£"]:
self.currency = c

def __getitem__(self, id):
"""Get a room with given id."""
return self.load_room(id)
Expand Down Expand Up @@ -214,7 +226,7 @@ def pick_option(self, key, character):
o.get_items(character)
character.location = o.get_destination()

def get_room_info(self, character):
def get_room_info(self, character, currency):
"""Get the information about the character's current room.
Parameters
Expand All @@ -230,9 +242,9 @@ def get_room_info(self, character):
The available destination options that the character could take
"""
room = self[character.location]
text = room.get_text(character)
text = room.get_text(character, currency)
options = room.get_options(character)
return text, {i: finalise(o.text, character.numbers)
return text, {i: finalise(o.text, character.numbers, currency)
for i, o in options.items()}

def fail_room(self):
Expand All @@ -257,7 +269,7 @@ def __str__(self):
"""Return a string."""
return "Room with id " + self.id

def get_text(self, character):
def get_text(self, character, currency):
"""Get the text for the room.
Parameters
Expand All @@ -276,7 +288,7 @@ def get_text(self, character):
line.get_items(character)
lines.append(line.text)
return finalise(" ".join([i for i in lines if i != ""]),
character.numbers)
character.numbers, currency)

def get_options(self, character):
"""Get the character's current destination options.
Expand Down
2 changes: 1 addition & 1 deletion ave/gamelist.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"title": "The Wonderful Tea Journey", "author": "Matthew Scroggs & Gin Grasso", "desc": "You're ready to start your epic adventure. But first, how about a lovely cup of tea?", "active": true, "version": 1, "ave_version": [0], "filename": "tea.ave", "number": 0}, {"title": "Moscow", "author": "Alex Bolton", "desc": "", "active": true, "version": 1, "ave_version": [0], "filename": "Moscow.ave", "number": 1}, {"title": "Welcome to Lower Mudville", "author": "Matthew Scroggs", "desc": "Explore this randomly generated village. What will you discover?", "active": true, "version": 1, "ave_version": [1, 9], "filename": "random.ave", "number": 3}, {"title": "How to Write Your Own Game", "author": "Matthew Scroggs", "desc": "This game will guide you through the process of writing your own game.", "active": true, "version": 1, "ave_version": [0], "filename": "make.ave", "number": 10}, {"title": "Test Game", "author": "Matthew Scroggs", "desc": "This game is very boring and so should only be used to test features.", "active": false, "version": 1, "ave_version": [1, 9], "filename": "test.ave", "number": 99}, {"title": "Shopping Simulator", "author": "Billy Buxton", "desc": "In this game, you go shopping.", "active": false, "version": 1, "ave_version": [0], "filename": "shop.ave", "number": null}]
[{"title": "The Wonderful Tea Journey", "author": "Matthew Scroggs & Gin Grasso", "desc": "You're ready to start your epic adventure. But first, how about a lovely cup of tea?", "active": true, "version": 1, "ave_version": [0], "filename": "tea.ave", "number": 0}, {"title": "Welcome to Lower Mudville", "author": "Matthew Scroggs", "desc": "Explore this randomly generated village. What will you discover?", "active": true, "version": 1, "ave_version": [1, 9], "filename": "random.ave", "number": 3}, {"title": "Moscow", "author": "Alex Bolton", "desc": "", "active": true, "version": 1, "ave_version": [0], "filename": "moscow.ave", "number": 4}, {"title": "How to Write Your Own Game", "author": "Matthew Scroggs", "desc": "This game will guide you through the process of writing your own game.", "active": true, "version": 1, "ave_version": [0], "filename": "make.ave", "number": 10}, {"title": "Test Game", "author": "Matthew Scroggs", "desc": "This game is very boring and so should only be used to test features.", "active": false, "version": 1, "ave_version": [1, 9], "filename": "test.ave", "number": 99}, {"title": "Shopping Simulator", "author": "Billy Buxton", "desc": "In this game, you go shopping.", "active": false, "version": 1, "ave_version": [0], "filename": "shop.ave", "number": null}]
4 changes: 2 additions & 2 deletions ave/parsing/file_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def _parse_value(value):
return no.Sum(*[_parse_value(unescape_expression(v))
for v in value.split("+")])
if value.startswith("-"):
return no.Negative(unescape_expression(
_parse_value(value[1:])))
return no.Negative(_parse_value(
unescape_expression(value[1:])))

if "*" in value:
return no.Product(*[_parse_value(unescape_expression(v))
Expand Down
12 changes: 7 additions & 5 deletions ave/parsing/string_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
"[": "SYMBOLOOPPEENNSQ",
"]": "SYMBOLCCLLOOSSEESQ",
"(": "SYMBOLOOPPEENNRO",
")": "SYMBOLCCLLOOSSEERO",
"<": "SYMBOLOOPPEENNPO",
">": "SYMBOLCCLLOOSSEEPO"
")": "SYMBOLCCLLOOSSEERO"
}

more_symbols = {
"$": "SYMBOLDDOOLLAARR"
"$": "SYMBOLDDOOLLAARR",
"<": "SYMBOLOOPPEENNPO",
">": "SYMBOLCCLLOOSSEEPO"
}

expression_symbols = {
Expand Down Expand Up @@ -113,10 +113,12 @@ def more_unescape(text):
return text


def finalise(txt, numbers):
def finalise(txt, numbers, currency=None):
"""Insert variables into text, then unescape final characters."""
for i, n in numbers.items():
txt = txt.replace("$" + i + "$", str(n))
if currency is not None:
txt = txt.replace("<money>", currency)
return more_unescape(txt)


Expand Down
2 changes: 1 addition & 1 deletion ave/test/game_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def check_first_room(game):
c = Character()
c.reset(game.items)
try:
game["start"].get_text(c)
game["start"].get_text(c, game.currency)
except: # noqa: E722
errors.append(AVEFatalError("Could not load text for first room."))
try:
Expand Down
2 changes: 1 addition & 1 deletion games/Moscow.ave → games/moscow.ave
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
== Moscow ==
-- --
** Alex Bolton **
@@ 1 @@
@@ 4 @@
vv 1 vv

# start
Expand Down
Loading

0 comments on commit f0002e8

Please sign in to comment.