-
Notifications
You must be signed in to change notification settings - Fork 4
Basic economy (issue 113) #114
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
Closed
Closed
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
3a3f666
Added a "wallet"
Davidek523 3708713
Added new class
Davidek523 2d28d2e
Putting logic behind player_gui
Davidek523 83fd970
Drawing gui
Davidek523 20480fe
Removed code
Davidek523 8c79550
Drawin text elsewhere
Davidek523 31790d9
Money changed dynamically
Davidek523 9a63c63
Testing selling and buying
Davidek523 e011e31
Testing
Davidek523 8281fc0
Add helper methods
Davidek523 5aebef9
Buying, selling, price and gui
Davidek523 31b46b0
Making price visible in shop
Davidek523 e3f02d8
Fixed buying
Davidek523 624d282
Testing
Davidek523 f2ad10a
Removind code
Davidek523 ae67883
Removed
Davidek523 4ba56fc
Fixed typehints
Davidek523 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,43 +1,43 @@ | ||
| { | ||
| "Gold Coin": {"type": "currency", "effect": "collect", "quantity": 1}, | ||
| "Silver Coin": {"type": "currency", "effect": "collect", "quantity": 1}, | ||
| "Coin Stack (1)": {"type": "currency", "effect": "collect", "quantity": 3}, | ||
| "Coin Stack (2)": {"type": "currency", "effect": "collect", "quantity": 5}, | ||
| "Circular Gem": {"type": "gem", "effect": "trade", "quantity": 1}, | ||
| "Single Gold Bar": {"type": "treasure", "effect": "trade", "quantity": 1}, | ||
| "Gold Bar Stack": {"type": "treasure", "effect": "trade", "quantity": 3}, | ||
| "Treasure Block": {"type": "treasure", "effect": "open_for_reward", "quantity": 1}, | ||
| "Golden Crown": {"type": "artifact", "effect": "boost_status", "quantity": 1}, | ||
| "Ornate Cup": {"type": "artifact", "effect": "boost_status", "quantity": 1}, | ||
| "Golden Figurine": {"type": "artifact", "effect": "boost_status", "quantity": 1}, | ||
| "Simple Sword": {"type": "weapon", "effect": "melee_attack", "quantity": 1}, | ||
| "Ornate Sword": {"type": "weapon", "effect": "melee_attack", "quantity": 1}, | ||
| "Double-Bladed Axe": {"type": "weapon", "effect": "melee_attack", "quantity": 1}, | ||
| "Spear": {"type": "weapon", "effect": "melee_attack", "quantity": 1}, | ||
| "Circular Shield": {"type": "armor", "effect": "defense_boost", "quantity": 1}, | ||
| "Golden Trophy": {"type": "reward", "effect": "achievement", "quantity": 1}, | ||
| "Candelabra": {"type": "decorative", "effect": "none", "quantity": 1}, | ||
| "Potion (Red)": {"type": "consumable", "effect": "restore_health", "quantity": 1}, | ||
| "Potion (Blue)": {"type": "consumable", "effect": "restore_mana", "quantity": 1}, | ||
| "Potion (Green)": {"type": "consumable", "effect": "poison_resistance", "quantity": 1}, | ||
| "Square Jar": {"type": "consumable", "effect": "unknown", "quantity": 1}, | ||
| "Cake": {"type": "food", "effect": "restore_health", "quantity": 1}, | ||
| "Donut": {"type": "food", "effect": "restore_health", "quantity": 1}, | ||
| "Bread": {"type": "food", "effect": "restore_health", "quantity": 1}, | ||
| "Rug Tile": {"type": "decorative", "effect": "none", "quantity": 1}, | ||
| "Geometric Pattern": {"type": "decorative", "effect": "none", "quantity": 1}, | ||
| "Glowing Orb (Blue)": {"type": "artifact", "effect": "magic_boost", "quantity": 1}, | ||
| "Glowing Orb (Red)": {"type": "artifact", "effect": "fire_boost", "quantity": 1}, | ||
| "Glowing Orb (Green)": {"type": "artifact", "effect": "nature_boost", "quantity": 1}, | ||
| "Golden Ring": {"type": "artifact", "effect": "magic_resistance", "quantity": 1}, | ||
| "Amulet": {"type": "artifact", "effect": "protection", "quantity": 1}, | ||
| "Scroll": {"type": "scroll", "effect": "learn_spell", "quantity": 1}, | ||
| "Key": {"type": "tool", "effect": "unlock", "quantity": 1}, | ||
| "Tool": {"type": "tool", "effect": "repair", "quantity": 1}, | ||
| "Dragon (Red)": {"type": "creature", "effect": "fire_attack", "quantity": 1}, | ||
| "Dragon (Green)": {"type": "creature", "effect": "nature_attack", "quantity": 1}, | ||
| "Dragon (Black)": {"type": "creature", "effect": "dark_attack", "quantity": 1}, | ||
| "Dragon (White)": {"type": "creature", "effect": "light_attack", "quantity": 1}, | ||
| "Gem Cluster": {"type": "treasure", "effect": "trade", "quantity": 1}, | ||
| "Glowing Crystal": {"type": "treasure", "effect": "magic_boost", "quantity": 1} | ||
| "Gold Coin": {"type": "currency", "effect": "collect", "quantity": 1, "price": 23}, | ||
| "Silver Coin": {"type": "currency", "effect": "collect", "quantity": 1, "price": 23}, | ||
| "Coin Stack (1)": {"type": "currency", "effect": "collect", "quantity": 3, "price": 23}, | ||
| "Coin Stack (2)": {"type": "currency", "effect": "collect", "quantity": 5, "price": 23}, | ||
| "Circular Gem": {"type": "gem", "effect": "trade", "quantity": 1, "price": 23}, | ||
| "Single Gold Bar": {"type": "treasure", "effect": "trade", "quantity": 1, "price": 23}, | ||
| "Gold Bar Stack": {"type": "treasure", "effect": "trade", "quantity": 3, "price": 23}, | ||
| "Treasure Block": {"type": "treasure", "effect": "open_for_reward", "quantity": 1, "price": 23}, | ||
| "Golden Crown": {"type": "artifact", "effect": "boost_status", "quantity": 1, "price": 23}, | ||
| "Ornate Cup": {"type": "artifact", "effect": "boost_status", "quantity": 1, "price": 23}, | ||
| "Golden Figurine": {"type": "artifact", "effect": "boost_status", "quantity": 1, "price": 23}, | ||
| "Simple Sword": {"type": "weapon", "effect": "melee_attack", "quantity": 1, "price": 23}, | ||
| "Ornate Sword": {"type": "weapon", "effect": "melee_attack", "quantity": 1, "price": 23}, | ||
| "Double-Bladed Axe": {"type": "weapon", "effect": "melee_attack", "quantity": 1, "price": 23}, | ||
| "Spear": {"type": "weapon", "effect": "melee_attack", "quantity": 1, "price": 23}, | ||
| "Circular Shield": {"type": "armor", "effect": "defense_boost", "quantity": 1, "price": 23}, | ||
| "Golden Trophy": {"type": "reward", "effect": "achievement", "quantity": 1, "price": 23}, | ||
| "Candelabra": {"type": "decorative", "effect": "none", "quantity": 1, "price": 23}, | ||
| "Potion (Red)": {"type": "consumable", "effect": "restore_health", "quantity": 1, "price": 23}, | ||
| "Potion (Blue)": {"type": "consumable", "effect": "restore_mana", "quantity": 1, "price": 23}, | ||
| "Potion (Green)": {"type": "consumable", "effect": "poison_resistance", "quantity": 1, "price": 23}, | ||
| "Square Jar": {"type": "consumable", "effect": "unknown", "quantity": 1, "price": 23}, | ||
| "Cake": {"type": "food", "effect": "restore_health", "quantity": 1, "price": 23}, | ||
| "Donut": {"type": "food", "effect": "restore_health", "quantity": 1, "price": 23}, | ||
| "Bread": {"type": "food", "effect": "restore_health", "quantity": 1, "price": 23}, | ||
| "Rug Tile": {"type": "decorative", "effect": "none", "quantity": 1, "price": 23}, | ||
| "Geometric Pattern": {"type": "decorative", "effect": "none", "quantity": 1, "price": 23}, | ||
| "Glowing Orb (Blue)": {"type": "artifact", "effect": "magic_boost", "quantity": 1, "price": 23}, | ||
| "Glowing Orb (Red)": {"type": "artifact", "effect": "fire_boost", "quantity": 1, "price": 23}, | ||
| "Glowing Orb (Green)": {"type": "artifact", "effect": "nature_boost", "quantity": 1, "price": 23}, | ||
| "Golden Ring": {"type": "artifact", "effect": "magic_resistance", "quantity": 1, "price": 23}, | ||
| "Amulet": {"type": "artifact", "effect": "protection", "quantity": 1, "price": 23}, | ||
| "Scroll": {"type": "scroll", "effect": "learn_spell", "quantity": 1, "price": 23}, | ||
| "Key": {"type": "tool", "effect": "unlock", "quantity": 1, "price": 23}, | ||
| "Tool": {"type": "tool", "effect": "repair", "quantity": 1, "price": 23}, | ||
| "Dragon (Red)": {"type": "creature", "effect": "fire_attack", "quantity": 1, "price": 23}, | ||
| "Dragon (Green)": {"type": "creature", "effect": "nature_attack", "quantity": 1, "price": 23}, | ||
| "Dragon (Black)": {"type": "creature", "effect": "dark_attack", "quantity": 1, "price": 23}, | ||
| "Dragon (White)": {"type": "creature", "effect": "light_attack", "quantity": 1, "price": 23}, | ||
| "Gem Cluster": {"type": "treasure", "effect": "trade", "quantity": 1, "price": 23}, | ||
| "Glowing Crystal": {"type": "treasure", "effect": "magic_boost", "quantity": 1, "price": 23} | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "player_wallet": { | ||
| "quantity": 100000 | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import pygame | ||
|
|
||
| from src.utils.currency import load_wallet | ||
|
|
||
|
|
||
| class Player_gui: | ||
| def __init__(self, screen): | ||
| self.font = pygame.font.Font(None, 36) | ||
| self.screen = screen | ||
| self.margin = 20 | ||
| self.wallet = load_wallet() | ||
| self.player_wallet = self.wallet["player_wallet"]["quantity"] | ||
|
|
||
| def draw_gui(self, screen: pygame.Surface): | ||
| player_money = self.font.render(f"Gold: {self.player_wallet}", True, (255, 255, 255)) | ||
|
|
||
| text_wdith, text_height = player_money.get_size() | ||
| x_pos = screen.get_width() - text_wdith - self.margin | ||
| y_pos = self.margin | ||
| self.screen.blit(player_money, (x_pos, y_pos)) | ||
|
|
||
| screen.blit(self.screen, dest=(0, 0)) | ||
| pygame.display.flip() # Update the display |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import json | ||
|
|
||
|
|
||
| def load_wallet(): | ||
| with open("data/wallet.json", "r") as file: | ||
| return json.load(file) | ||
|
|
||
|
|
||
| def save_wallet(player_wallet): | ||
| wallet_data = {"player_wallet": {"quantity": player_wallet}} | ||
| with open("data/wallet.json", "w") as file: | ||
| return json.dump(wallet_data, file, indent=4) | ||
|
|
||
|
|
||
| def load_inventory(): | ||
| with open("data/inventory.json", "r") as file: | ||
| return json.load(file) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What's the reason to store the currency.py in the utils directory?