Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- import curses
- import random
- # キャラクター定数
- PLAYER = "@" # 弁護士(君だ)
- SCAMMER = "S" # 詐欺師(実刑という判断を下すべき対象)
- LAW_BOOK = "L" # 判例集(メンタルを回復する知恵の結晶)
- WALL = "#" # ネットの障壁
- EMPTY = "."
- class JusticeGame:
- def __init__(self, stdscr):
- self.stdscr = stdscr
- self.px, self.py = 10, 10
- self.hp = 100
- self.evidence = 0
- self.world = {} # 無限マップ
- self.setup_curses()
- self.run()
- def setup_curses(self):
- curses.curs_set(0)
- self.stdscr.nodelay(False)
- self.stdscr.keypad(True)
- def get_tile(self, x, y):
- # 座標が未生成なら動的に生成
- if (x, y) not in self.world:
- prob = random.random()
- # 判定順序を修正。希少なものから判定することで生成を確実にする
- if prob < 0.06: # 6%の確率で詐欺師
- self.world[(x, y)] = SCAMMER
- elif prob < 0.09: # 3%の確率で判例集
- self.world[(x, y)] = LAW_BOOK
- elif prob < 0.22: # 13%の確率で壁
- self.world[(x, y)] = WALL
- else:
- self.world[(x, y)] = EMPTY
- return self.world[(x, y)]
- def draw(self):
- self.stdscr.clear()
- height, width = self.stdscr.getmaxyx()
- # ステータス表示(解像度を高めろ)
- status = f"メンタル(HP): {self.hp} | 確保した証拠: {self.evidence} | 座標: ({self.px}, {self.py})"
- self.stdscr.addstr(0, 0, status, curses.A_BOLD)
- self.stdscr.addstr(1, 0, "走り続けろ、夜明けまで。 [WASDで直感的に移動 / Qで辞職]")
- # プレイヤーを中心とした視界の描画
- view_h, view_w = height - 4, width - 2
- for y in range(view_h):
- for x in range(view_w):
- world_x = self.px - view_w // 2 + x
- world_y = self.py - view_h // 2 + y
- char = self.get_tile(world_x, world_y)
- if world_x == self.px and world_y == self.py:
- self.stdscr.addch(y + 2, x + 1, PLAYER, curses.A_REVERSE)
- else:
- self.stdscr.addch(y + 2, x + 1, char)
- def run(self):
- while self.hp > 0:
- self.draw()
- # getch()はキー入力を待機する。WASDですぐに動く。
- key = self.stdscr.getch()
- dx, dy = 0, 0
- if key in [ord('w'), ord('W')]: dy = -1
- elif key in [ord('s'), ord('S')]: dy = 1
- elif key in [ord('a'), ord('A')]: dx = -1
- elif key in [ord('d'), ord('D')]: dx = 1
- elif key in [ord('q'), ord('Q')]: break
- nx, ny = self.px + dx, self.py + dy
- tile = self.get_tile(nx, ny)
- if tile == WALL:
- continue # コンプライアンスの壁。無理な突破は慎め。
- elif tile == SCAMMER:
- # 詐欺師との法的闘争。メンタルを削りながらも証拠を掴む。
- self.hp -= 25
- self.evidence += 20
- self.world[(nx, ny)] = EMPTY # 司直の手が及んだ
- elif tile == LAW_BOOK:
- # 勉強をして解像度を上げ、メンタルを回復。
- self.hp = min(100, self.hp + 35)
- self.world[(nx, ny)] = EMPTY
- self.px, self.py = nx, ny
- self.end_game()
- def end_game(self):
- self.stdscr.clear()
- self.stdscr.addstr(10, 10, "闘争の終わり。")
- self.stdscr.addstr(11, 10, f"最終的な証拠確保数: {self.evidence}")
- if self.hp <= 0:
- self.stdscr.addstr(13, 10, "メンタルが崩壊した。もう一度本を読み直せ。")
- else:
- self.stdscr.addstr(13, 10, "夜明けが来た。君の歩みは止められない。")
- self.stdscr.refresh()
- self.stdscr.getch()
- if __name__ == "__main__":
- curses.wrapper(JusticeGame)
Advertisement
Add Comment
Please, Sign In to add comment