From 802ef7e591e9650cdfeb2c9426f3a9a83487637b Mon Sep 17 00:00:00 2001 From: Emil Kovacev Date: Wed, 9 Nov 2022 02:07:26 -0500 Subject: [PATCH 1/2] changed imports for running games --- README.md | 3 +++ crpg/builtin.py | 2 +- crpg/{crpg.py => engine.py} | 4 ++-- games/game-1.py | 7 ++----- games/game-2.py | 7 ++----- games/game-3.py | 7 ++----- 6 files changed, 12 insertions(+), 18 deletions(-) rename crpg/{crpg.py => engine.py} (96%) diff --git a/README.md b/README.md index 5ac3e0e..a492277 100644 --- a/README.md +++ b/README.md @@ -37,5 +37,8 @@ If we want to expand the API for connections, we can always add more symbols for parsing. One I was thinking about is `\->`, which would denote an "ending" connection (to signal destroying the path to reach the current action) +# Running Games +1. Enter the repository: `cd Classic-RPG` +2. Run a game: `python -m games.game-1` diff --git a/crpg/builtin.py b/crpg/builtin.py index 826b9de..8030b56 100644 --- a/crpg/builtin.py +++ b/crpg/builtin.py @@ -1,4 +1,4 @@ -from __future__ import annotations #needed for Node type hints +from __future__ import annotations # needed for Node type hints # Base player classes class Player: diff --git a/crpg/crpg.py b/crpg/engine.py similarity index 96% rename from crpg/crpg.py rename to crpg/engine.py index d4531f0..5f7cdf2 100644 --- a/crpg/crpg.py +++ b/crpg/engine.py @@ -1,5 +1,5 @@ -from setup import start -from builtin import Connection, Node, Location, Player +from .setup import start +from .builtin import Connection, Node, Location, Player # the base crpg game diff --git a/games/game-1.py b/games/game-1.py index efaa784..e5b0ff6 100644 --- a/games/game-1.py +++ b/games/game-1.py @@ -1,8 +1,5 @@ -import sys -sys.path.insert(0, "../crpg") - -from crpg import Game -from builtin import Location, Node +from crpg.engine import Game +from crpg.builtin import Location, Node starting_location = Location("castle") starting_location.add_attr( diff --git a/games/game-2.py b/games/game-2.py index 77e0ff2..372c857 100644 --- a/games/game-2.py +++ b/games/game-2.py @@ -1,7 +1,4 @@ -import sys -sys.path.insert(0, "../crpg") +from crpg.parser import v1 as v1_parser -import parser - -game = parser.v1("game-2-layout.dl") +game = v1_parser("game-2-layout.dl") game.start() diff --git a/games/game-3.py b/games/game-3.py index c0ca265..075b784 100644 --- a/games/game-3.py +++ b/games/game-3.py @@ -1,7 +1,4 @@ -import sys -sys.path.insert(0, "../crpg") +from crpg.parser import v2 as v2_parser -import parser - -game = parser.v2("game-3.dl") +game = v2_parser("game-3.dl") game.start() From e7cb878ae0a50543c0e20edca6f4e7ed740447e1 Mon Sep 17 00:00:00 2001 From: Emil Kovacev Date: Wed, 9 Nov 2022 02:35:47 -0500 Subject: [PATCH 2/2] fixed several parser and test imports --- crpg/parser/parser_v1.py | 5 +++-- crpg/parser/parser_v2.py | 5 +++-- games/game-2.py | 6 +++++- games/game-3.py | 6 +++++- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/crpg/parser/parser_v1.py b/crpg/parser/parser_v1.py index e69bc8c..f2ddb49 100644 --- a/crpg/parser/parser_v1.py +++ b/crpg/parser/parser_v1.py @@ -1,7 +1,8 @@ -from crpg import Game from typing import Callable # for connection function type hints import re -from builtin import Connection, BreakingConnection, Node, Location + +from crpg.engine import Game +from crpg.builtin import Connection, BreakingConnection, Node, Location node_types = { diff --git a/crpg/parser/parser_v2.py b/crpg/parser/parser_v2.py index 97891c7..793d0dd 100644 --- a/crpg/parser/parser_v2.py +++ b/crpg/parser/parser_v2.py @@ -1,7 +1,8 @@ -from crpg import Game from typing import Callable, Any # for connection function type hints import re -from builtin import Connection, BreakingConnection, Node, Location + +from crpg.engine import Game +from crpg.builtin import Connection, BreakingConnection, Node, Location # connection function mapping diff --git a/games/game-2.py b/games/game-2.py index 372c857..a06df60 100644 --- a/games/game-2.py +++ b/games/game-2.py @@ -1,4 +1,8 @@ +import os + from crpg.parser import v1 as v1_parser -game = v1_parser("game-2-layout.dl") + +filepath = os.path.abspath("games/game-2-layout.dl") +game = v1_parser(filepath) game.start() diff --git a/games/game-3.py b/games/game-3.py index 075b784..de9de48 100644 --- a/games/game-3.py +++ b/games/game-3.py @@ -1,4 +1,8 @@ +import os + from crpg.parser import v2 as v2_parser -game = v2_parser("game-3.dl") + +filepath = os.path.abspath("games/game-2-layout.dl") +game = v2_parser(filepath) game.start()