Repository navigation
moin-uddin-intro-to-python-II #1
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
Open
Legitcoder
wants to merge
14
commits into
master
Choose a base branch
from
moin-uddin
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
371e502
Create initializer for Room Class
Legitcoder 199a590
Able to move rooms with user input
Legitcoder 0049b2e
Modify print statments for better user experience
Legitcoder 0e9579f
Setup logic without any items initialized
Legitcoder fde6734
Implement on_take and on_drop for item
Legitcoder 7ae06b0
Refactor code, remove place attribute in player
Legitcoder 1946909
Fix errors from refactoring
Legitcoder a07d487
Remove even more unnecessary code
Legitcoder 8b4bc1c
Forgot to remove method call of a method I deleted
Legitcoder 1954fd1
Initialize items and start randomizing them between rooms and player
Legitcoder c0eb377
Refactor and Clean code and dropping items feature implemented
Legitcoder ed5acdd
Implement Dropping and Taking Features as well as Error Handling
Legitcoder 2d8fea3
Complete Minimum Viable Product
Legitcoder a31ee7d
Implement get command
Legitcoder 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,3 +1,4 @@ | ||
| .vscode | ||
| *.pyc | ||
| __pycache__ | ||
| __pycache__ | ||
| .idea |
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,12 @@ | ||
| class Item: | ||
| def __init__(self, name, description=""): | ||
| self.name = name | ||
| self.description = description | ||
|
|
||
|
|
||
| def on_take(self): | ||
| print(f'{self.name} Taken.') | ||
|
|
||
|
|
||
| def on_drop(self): | ||
| print(f'{self.name} Dropped.') |
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,2 +1,33 @@ | ||
| # Write a class to hold player information, e.g. what room they are in | ||
| # currently. | ||
| class Player: | ||
|
|
||
| def __init__(self, current_room, items=[]): | ||
| self.current_room = current_room | ||
| self.items = items | ||
|
|
||
|
|
||
| def print_items(self): | ||
| print(self.items) | ||
|
|
||
|
|
||
| def drop(self, item_name): | ||
| try: | ||
| item = [self.item for self.item in self.items if item_name == self.item.name][0] | ||
| except: | ||
| print(f"Player does not have {item_name}") | ||
| return | ||
| self.items.remove(item) | ||
| item.on_drop() | ||
| self.current_room.add(item) | ||
|
|
||
|
|
||
| def take(self, item_name): | ||
| try: | ||
| item = [self.current_room.item for self.current_room.item in self.current_room.items if item_name == self.current_room.item.name][0] | ||
| except: | ||
| print(f"Item {item_name} does not exist in room") | ||
| return | ||
| self.current_room.remove(item) | ||
| self.items.append(item) | ||
| item.on_take() |
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,2 +1,24 @@ | ||
| # Implement a class to hold room information. This should have name and | ||
| # description attributes. | ||
| # description attributes. | ||
|
|
||
| class Room: | ||
|
|
||
| def __init__(self, name, description): | ||
| self.name = name | ||
| self.description = description | ||
| self.items = [] | ||
|
|
||
| def __str__(self): | ||
| item_names = [item.name for item in self.items] | ||
| items_list_str = ', '.join(item_names) if self.items else "" | ||
| return f"{self.name}, {self.description} \n{items_list_str}" | ||
|
|
||
| def add(self, item): | ||
| self.items.append(item) | ||
|
|
||
|
|
||
| def remove(self, item): | ||
| if item in self.items: | ||
| self.items.remove(item) | ||
| else: | ||
| print(f"Item does not exist in {self.name}") |
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.
MUCH clearer than before!