내일배움캠프 개인과제-
턴제 게임 만들기
내가 생각했던 것.
플레이어의 캐릭터와 몬스터의 상태창 만들고 나서
class를 또 짜서 턴제 게임을 할 수 있게 하면 되겠다!
# """
# 물리공격과 마법공격을 선택할 수 있고, 마법공격 시 mp소모되며 mp부족 시 마법을 쓸 수 없음.
# """
def attack(self, other):
if self.attack_type == 'p':
damage = random.randint(self.ad - 2, self.ad + 2)
elif self.attack_type == 'm':
if self.mp > 25 :
damage = random.randint(self.ap -2, self.ap +2)
self.mp = self.mp - 25
else:
print('마나가 부족해 마법을 쓸 수 없습니다.')
우선 마나가 부족해 마법을 쓸 수 없는 코드는 어떻게 넣는지 몰라서 대기.
이것보다 중요한 것이
class game:
def __init__(self, player1):
self.player1 = player1
self.current_player = player1
# """
# 플레이어 혼자 진행하는 것이기 때문에 항상 턴은 플레이어의 턴이어야 함.
# def turn(self):
# self.current_player = self.player1 라고 코드를 짜봤었음. 근데 아닌듯.
# """
def turn(self):
pass
def play(self):
while self.player1.hp > 0 and self.Monster.hp > 0 :
self.current_player.show_status()
action = input('어떤 공격을 하시겠습니까? (p: 물리 공격, m: 마법 공격)')
if action == 'p':
self.current_player.attack(self.Monster)
elif action == 'm':
self.current_player.attack(self.Monster)
else :
print('잘못된 입력입니다. 다시 입력하세요')
continue
if self.monster.hp == 0 :
print(f'{self.monster.name}이 쓰러졌습니다.')
break
self.monster.attack(self.player)
if self.player.hp == 0 :
print(f'{self.player.name}이 쓰러졌습니다.')
break
이것과 합쳐야 하는데 그걸 못 하겠음.
p와 m으로 물리공격과 마법공격을 구분하는 건 알겠는데,
위에서도 고르고 밑에서도 고르니까 말이 안된다.
그래서 결론은 싹 다 갈아 엎는 중!
class game를 따로 빼지않고 진행 과정에서 자연스럽게 몬스터와 플레이어가 대결할 수 있도록 하겠다.
이 문제는 추후 다시와서 해결할 것!