-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Potion class, and how it is encoded #86
base: v2.0
Are you sure you want to change the base?
Changes from 7 commits
6e5dea6
e4ba2d3
60e3010
5821f1d
e997e95
55a9156
dd8b117
b165b9b
ff1c193
f0c8f3a
c12cc59
3a7d484
e02d36d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,10 +5,11 @@ class Player: | |
def __init__(self): | ||
self.hp = 100 | ||
self.xp = 0 | ||
self.bag = [] | ||
self.money = 0 | ||
|
||
def summary(self): | ||
return f'hp: {self.hp} xp: {self.xp}' | ||
|
||
return f'hp: {self.hp} xp: {self.xp} money: {self.money}' | ||
|
||
# Base connection classes | ||
|
||
|
@@ -58,12 +59,24 @@ def advance(self, index: int) -> Node: | |
def __str__(self): | ||
return self.title | ||
|
||
#To initialize another potion type, create another if statement in init. Define what happens on select in on_select. | ||
class Potion(Node): | ||
def __init__(self, title:str, desc:str, player:Player): | ||
super().__init__(title, desc) | ||
self.desc = desc | ||
self.player = player | ||
if "-health-collect" in title: | ||
self.amount_health = int(title[19:21]) | ||
self.potionType = "Health potion" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we have classes that inherit the potion class for Health, Speed, etc, instead of this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it. Check out the recent push. I made it as generic as possible, but notice that it is impossible to encode "this is a health potion worth 25 hp" without actually calling it out and subsequently using conditionals to decipher it. However, the implementation of Potion is certainly cleaner now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add is_health_potion as an argument? Another approach would be to have an action method with different implementations for each class |
||
def on_select(self): | ||
self.player.bag.append(self) | ||
for i in self.player.bag: | ||
print(i.potionType) | ||
|
||
# Location behaves exactly like a Node | ||
class Location(Node): | ||
pass | ||
|
||
|
||
# Actions include the player for reference (augment player attributes) | ||
class Action(Node): | ||
def __init__(self, title: str, desc: str, player: Player): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
from typing import Callable # for connection function type hints | ||
from setup import start | ||
import re | ||
from builtin import Connection, BreakingConnection, Node, Location, Fight, Run, Player | ||
from builtin import Connection, Potion, BreakingConnection, Node, Location, Fight, Run, Player | ||
|
||
# the base crpg game | ||
|
||
|
@@ -84,7 +84,8 @@ def generate(filename): | |
"node": Node, | ||
"location": Location, | ||
"fight": Fight, | ||
"run": Run | ||
"run": Run, | ||
"potion" : Potion, | ||
} | ||
|
||
c_funcs: dict[str, Callable[[Game, Node, Node], None]] = { | ||
|
@@ -99,7 +100,7 @@ def generate(filename): | |
for node in nodes.split("\n"): | ||
n, n_type, *args = re.split(r"\s*\|\s*", node) | ||
|
||
if n_type == "fight" or n_type == "run": | ||
if n_type == "fight" or n_type == "run" or n_type[:2] == "po": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should be able to specify n_type == "potion" here. n_type stands for node type, and is the second item in the .dl file There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
args.append(game.player) | ||
|
||
obj = n_types[n_type](*args) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,10 @@ | ||
1 | starting | castle | You wake up in the prison cell of an abandoned castle. | ||
2 | node | examine skeleton | You examine the skeleton of a corpse. | ||
3 | node | open cell gate | The cell gate is unlocked. You push it open. | ||
3 | potion | po-health-collect-[25] | Pick up potion | ||
4 | node | left corridor | The corridor leads to an open door to the castle's courtyard. | ||
9 | location | courtyard | You enter the castle's courtyard. | ||
5 | node | right corridor | The corridor leads to a large flight of stairs to the dungeon. | ||
10 | location | dungeon | You enter the castle's dungeon. | ||
6 | node | scale stairs | A dragon swoops down from the sky, blocking your path. | ||
7 | fight | fight dragon | You vanquish the dragon. | ||
8 | run | run from dragon | You run from the dragon. | ||
--- | ||
1 <-> 2 | ||
1 -> 3 | ||
3 -> 4 | ||
3 -> 5 | ||
4 -> 9 | ||
5 -> 10 | ||
9 -> 6 | ||
6 -> 7 | ||
6 -> 8 | ||
7 -> 4 | ||
8 -> 4 | ||
1 <-> 3 | ||
1 -> 2 | ||
2 -> 4 | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still think this documentation is a bit out of place here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deleted.