Last active
August 24, 2021 12:58
-
-
Save oiojin831/9757e053672cf08c115566f65bc2c813 to your computer and use it in GitHub Desktop.
This file contains 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
class Character(): | |
def __init__(self, id, location, inventories): | |
self.id = id | |
self.location = location | |
self.inventories = inventories | |
def my_location(self): | |
print(f"{self.id}의 위치는 {self.location}") | |
print("") | |
def my_inventories(self): | |
print(f"{self.id}의 위치는 {self.inventories}") | |
def move_x(self,number, direction): | |
if direction == "forward": | |
self.location[0] = self.location[0] + number | |
elif direction == "back": | |
self.location[0] = self.location[0] - number | |
self.my_location() | |
def move_y(self,number, direction): | |
if direction == "right": | |
self.location[1] = self.location[1] + number | |
elif direction == "left": | |
self.location[1] = self.location[1] - number | |
self.my_location() | |
class Tree(): | |
def __init__(self, 자원, location): | |
self.자원 = 자원 | |
self.location = location | |
민성 = Character("민성", [0,1,1], ["칼", "나뭇가지"]) | |
태휘 = Character("태휘", [0,3,1], ["칼", "나뭇가지"]) | |
혜준 = Character("혜준", [0,2,1], ["칼", "나뭇가지"]) | |
나무1 = Tree(10, [4,1,1]) | |
characters = [민성, 태휘, 혜준] | |
index = 0 | |
for x in characters: | |
print(f"{index}: {x.id}") | |
index = index + 1 | |
character_num = int(input("캐릭터번호를 선택해주세요")) | |
my_character = characters[character_num] | |
while True: | |
key_input = input("키입력") | |
if key_input == "w": | |
my_character.move_x(1, "forward") | |
elif key_input == "a": | |
my_character.move_y(1, "left") | |
elif key_input == "s": | |
my_character.move_x(1, "back") | |
elif key_input == "d": | |
my_character.move_y(1, "right") | |
elif key_input == "e": | |
my_character.my_inventories() | |
else: | |
print("잘못된 키 입력입니다.") | |
if (my_character.location[0] == 나무1.location[0]) and (my_character.location[1] == 나무1.location[1]): | |
print("나무랑 부딛쳤습니다.") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment