Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,22 @@ 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)

# Game objects

1) Know the attributes of your object (duh)

2) Go to **builtin.py** -> **Obj** and find **Obj** class. This is where you initialize the object. **NOTE:** You don't assume the player is going to use an object. This is merely initialization. Tip: Initialize the logic of your object here.

3) The hard part is done - go nuts and build your own class definition.

4) Do not forget to go to **crpg.py** -> **generate()** iff you are:
- creating a new object type.
- go to the first for loop and look for the first if statement.
- remember to include your new object type in n_types
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should steer away from instructions on modifying the code itself. Instead, we can comment above and within the functions we write so that devs can understand exactly what each function does!


Objects we currenlty have:
-Money. Encoded in a .dl file as
> id | currency | amount_as_an_integer | Description
> potion | pohealth | Description
New potions should be encoded like this: <"po"type>
- for example, pohealth, pohp, pomagic
Comment thread
zacharyLYH marked this conversation as resolved.
Outdated
33 changes: 31 additions & 2 deletions builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -58,6 +59,34 @@ def advance(self, index: int) -> Node:
def __str__(self):
return self.title

class Obj(Node):
Comment thread
zacharyLYH marked this conversation as resolved.
Outdated
def __init__(self, title:str, desc:str, player:Player):
super().__init__(title, desc)
self.desc = desc
self.player = player
if title.isnumeric(): #initializing money
self.amount_Money = int(title)
elif title[:2] == "po": #if first 2 characters are po then its a potion
Comment thread
zacharyLYH marked this conversation as resolved.
Outdated
if title[2:] == "health":
self.amount_Hp = 25
self.potionType = "Health potion"

class Potion(Obj):
def on_select(self):
if self in self.player.bag:
if self.amount_Hp:
self.player.hp += self.amount_Hp
self.player.bag.remove(self)
Comment thread
zacharyLYH marked this conversation as resolved.
Outdated
else:
self.player.bag.append(self)
for i in self.player.bag:
print(i.potionType)

class Currency(Obj):
def on_select(self):
self.player.money += self.amount_Money
print(self.player.summary())
Comment thread
zacharyLYH marked this conversation as resolved.
Outdated
Comment thread
zacharyLYH marked this conversation as resolved.
Outdated


# Location behaves exactly like a Node
class Location(Node):
Expand Down
8 changes: 5 additions & 3 deletions crpg.py
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, Currency,Potion, BreakingConnection, Node, Location, Fight, Run, Player

# the base crpg game

Expand Down Expand Up @@ -84,7 +84,9 @@ def generate(filename):
"node": Node,
"location": Location,
"fight": Fight,
"run": Run
"run": Run,
"potion" : Potion,
"currency" : Currency
}

c_funcs: dict[str, Callable[[Game, Node, Node], None]] = {
Expand All @@ -99,7 +101,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" or n_type == "currency":
Comment thread
zacharyLYH marked this conversation as resolved.
Outdated
args.append(game.player)

obj = n_types[n_type](*args)
Expand Down
25 changes: 7 additions & 18 deletions game-2-layout.dl
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
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 | pohealth | 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.
5 | currency | 1000 | Collect money
---
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
2 <-> 5