기본적으로 텍스트로만 모든게 진행되는데 기본적으로 방치형이고 플레이어 닉네임 앞에는 항상 레벨이 붙어있어. 레벨 몇부터 몇은 앞에 이모티콘을 붙히는 식(칭호느낌으로) 그리고 방치 텍스트출력은 끄거나 켤 수 있고 기본적으로 접속한 사람들하고 채팅이 되는거지 친목질도 하고 길에 소속되면 그 길드만의 글자색이라던가 뱃지라던가 하는 혜택. 어떨 거 같음?
대충 이런 느낌임
import time
import threading
import sys
import json
import os
class Character:
def __init__(self, name, attack, health=100, level=1, experience=0, experience_to_next_level=5):
self.name = name
self.attack = attack
self.health = health
self.alive = True
self.level = level
self.experience = experience
self.experience_to_next_level = experience_to_next_level
def is_alive(self):
return self.health > 0
def attack_monster(self, monster):
if self.alive and monster.is_alive():
monster.health -= self.attack
return monster.health
return None
def gain_experience(self, amount, pause_event):
self.experience += amount
if pause_event.is_set():
print_output(f"\033[33mLv.{self.level} {self.name}(이)가 경험치를 얻었습니다! 현재 경험치: {self.experience}/{self.experience_to_next_level}\033[0m")
self.check_level_up()
def check_level_up(self):
while self.experience >= self.experience_to_next_level:
self.level += 1
self.attack *= 2
print(f"\033[96mLevel Up! 공격력: {self.attack}\033[0m")
self.experience -= self.experience_to_next_level
self.update_experience_needed()
def update_experience_needed(self):
if self.level == 1:
self.experience_to_next_level = 5
else:
self.experience_to_next_level = int(self.experience_to_next_level * 5)
class Monster:
def __init__(self, name, health, attack):
self.name = name
self.health = health
self.max_health = health
self.attack = attack
def is_alive(self):
return self.health > 0
output_lines = [] # 출력된 텍스트를 저장할 리스트
output_lock = threading.Lock() # 출력용 Lock 추가
def print_output(message):
global output_lines
with output_lock: # 메시지 출력 시 Lock을 사용
output_lines.append(message)
print(message)
def clear_output():
global output_lines
with output_lock:
output_lines.clear() # 리스트 비우기
print("\033[H\033[J", end='') # 콘솔 화면 지우기
def save_game(character):
data = {
'name': character.name,
'attack': character.attack,
'health': character.health,
'level': character.level,
'experience': character.experience,
'experience_to_next_level': character.experience_to_next_level
}
with open('save_data.json', 'w') as f:
json.dump(data, f)
def load_game():
if os.path.exists('save_data.json'):
with open('save_data.json', 'r') as f:
data = json.load(f)
return Character(**data)
return None
def battle(hero, pause_event):
while True:
monster = Monster("\033[92m슬라임\033[0m", 80, 15)
if pause_event.is_set():
print_output(f"새로운 몬스터가 나타났습니다: {monster.name} (체력: {monster.max_health})")
while hero.is_alive() and monster.is_alive():
if pause_event.is_set():
hero.attack_monster(monster)
print_output(f"Lv.{hero.level} {hero.name}(이)가 {monster.name}을(를) 공격! {monster.name}의 체력: ({monster.health} / {monster.max_health})")
time.sleep(3) # 원래 간격으로 유지
else:
hero.attack_monster(monster)
time.sleep(3) # 원래 간격으로 유지
if monster.health <= 0:
monster.health = 0
hero.gain_experience(1, pause_event)
break
if not hero.is_alive():
print_output(f"Lv.{hero.level} {hero.name}(이)가 패배했습니다! 새로운 영웅을 소환합니다...")
hero = Character(hero.name, 20)
print_output(f"새로운 영웅이 소환되었습니다: {hero.name}(이)가 (현재 레벨: {hero.level}, 공격력: {hero.attack})")
def toggle_pause(pause_event, hero):
paused = False
last_message = "" # 마지막 메시지를 저장
while True:
command = input()
if command.strip().lower() == '/종료':
save_game(hero)
print("프로그램을 종료합니다...")
sys.exit()
elif command.strip() == '.p':
paused = not paused
if paused:
pause_event.clear()
print_output("전투 텍스트 출력을 멈췄습니다. 전투는 계속 진행됩니다.")
else:
pause_event.set()
print_output("전투 텍스트 출력을 계속합니다.")
print_output(f"현재 {hero.name}(이)가의 체력: {hero.health}, 현재 경험치: {hero.experience}/{hero.experience_to_next_level}")
elif command.strip() == '.정리':
clear_output() # 출력 정리 기능 호출
else:
# 채팅 메시지 형식 출력 (조사 제외)
print_output(f"Lv.{hero.level}. {hero.name}(이)가 : {command}") # 자동 생성 메시지 포함
def main():
hero = load_game()
if hero is None:
hero_name = input("닉네임을 입력해주세요: ")
hero = Character(hero_name, 20)
pause_event = threading.Event()
pause_event.set()
battle_thread = threading.Thread(target=battle, args=(hero, pause_event))
battle_thread.start()
try:
toggle_pause(pause_event, hero)
except KeyboardInterrupt:
save_game(hero)
print("\n프로그램이 종료되었습니다.")
if __name__ == "__main__":
main()
- dc official App
게임 자체 재미는 드릅게 없겠지만 친목이 재밌지 않을까? 채팅할때도 레벨과 뱃지, 글자 색 등등이 나름의 자존감도 채워주고 - dc App
ai 있으니까 게임이 막 쉬워보여???
쉬워보이진 않는데 어떨까 생각해보는거지 - dc App
머드 게임이나 텍스트 어드벤쳐라고 장르 자체는 이미 있긴 해 온라인 머드 게임이란 것도 있고... 이런 장르 팬층은 늘 있었음 이걸 좀 더 현대적인 방식으로 풀어낸 게임중에는 '라이프라인'이 인상적이었는데 한번 참고 ㄱㄱ
걍 바로 웹에서 되어도 할까말까인데 그걸 왜 파이썬으로?...
해봐
디스코드 봇에 그런거 있으면 괜찮을지도