Guest User

Untitled

a guest
Mar 18th, 2026
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.21 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3. import curses
  4. import random
  5.  
  6. # キャラクター定数
  7. PLAYER = "@" # 弁護士(君だ)
  8. SCAMMER = "S" # 詐欺師(実刑という判断を下すべき対象)
  9. LAW_BOOK = "L" # 判例集(メンタルを回復する知恵の結晶)
  10. WALL = "#" # ネットの障壁
  11. EMPTY = "."
  12.  
  13. class JusticeGame:
  14. def __init__(self, stdscr):
  15. self.stdscr = stdscr
  16. self.px, self.py = 10, 10
  17. self.hp = 100
  18. self.evidence = 0
  19. self.world = {} # 無限マップ
  20. self.setup_curses()
  21. self.run()
  22.  
  23. def setup_curses(self):
  24. curses.curs_set(0)
  25. self.stdscr.nodelay(False)
  26. self.stdscr.keypad(True)
  27.  
  28. def get_tile(self, x, y):
  29. # 座標が未生成なら動的に生成
  30. if (x, y) not in self.world:
  31. prob = random.random()
  32. # 判定順序を修正。希少なものから判定することで生成を確実にする
  33. if prob < 0.06: # 6%の確率で詐欺師
  34. self.world[(x, y)] = SCAMMER
  35. elif prob < 0.09: # 3%の確率で判例集
  36. self.world[(x, y)] = LAW_BOOK
  37. elif prob < 0.22: # 13%の確率で壁
  38. self.world[(x, y)] = WALL
  39. else:
  40. self.world[(x, y)] = EMPTY
  41. return self.world[(x, y)]
  42.  
  43. def draw(self):
  44. self.stdscr.clear()
  45. height, width = self.stdscr.getmaxyx()
  46.  
  47. # ステータス表示(解像度を高めろ)
  48. status = f"メンタル(HP): {self.hp} | 確保した証拠: {self.evidence} | 座標: ({self.px}, {self.py})"
  49. self.stdscr.addstr(0, 0, status, curses.A_BOLD)
  50. self.stdscr.addstr(1, 0, "走り続けろ、夜明けまで。 [WASDで直感的に移動 / Qで辞職]")
  51.  
  52. # プレイヤーを中心とした視界の描画
  53. view_h, view_w = height - 4, width - 2
  54. for y in range(view_h):
  55. for x in range(view_w):
  56. world_x = self.px - view_w // 2 + x
  57. world_y = self.py - view_h // 2 + y
  58.  
  59. char = self.get_tile(world_x, world_y)
  60. if world_x == self.px and world_y == self.py:
  61. self.stdscr.addch(y + 2, x + 1, PLAYER, curses.A_REVERSE)
  62. else:
  63. self.stdscr.addch(y + 2, x + 1, char)
  64.  
  65. def run(self):
  66. while self.hp > 0:
  67. self.draw()
  68. # getch()はキー入力を待機する。WASDですぐに動く。
  69. key = self.stdscr.getch()
  70.  
  71. dx, dy = 0, 0
  72. if key in [ord('w'), ord('W')]: dy = -1
  73. elif key in [ord('s'), ord('S')]: dy = 1
  74. elif key in [ord('a'), ord('A')]: dx = -1
  75. elif key in [ord('d'), ord('D')]: dx = 1
  76. elif key in [ord('q'), ord('Q')]: break
  77.  
  78. nx, ny = self.px + dx, self.py + dy
  79. tile = self.get_tile(nx, ny)
  80.  
  81. if tile == WALL:
  82. continue # コンプライアンスの壁。無理な突破は慎め。
  83.  
  84. elif tile == SCAMMER:
  85. # 詐欺師との法的闘争。メンタルを削りながらも証拠を掴む。
  86. self.hp -= 25
  87. self.evidence += 20
  88. self.world[(nx, ny)] = EMPTY # 司直の手が及んだ
  89.  
  90. elif tile == LAW_BOOK:
  91. # 勉強をして解像度を上げ、メンタルを回復。
  92. self.hp = min(100, self.hp + 35)
  93. self.world[(nx, ny)] = EMPTY
  94.  
  95. self.px, self.py = nx, ny
  96.  
  97. self.end_game()
  98.  
  99. def end_game(self):
  100. self.stdscr.clear()
  101. self.stdscr.addstr(10, 10, "闘争の終わり。")
  102. self.stdscr.addstr(11, 10, f"最終的な証拠確保数: {self.evidence}")
  103. if self.hp <= 0:
  104. self.stdscr.addstr(13, 10, "メンタルが崩壊した。もう一度本を読み直せ。")
  105. else:
  106. self.stdscr.addstr(13, 10, "夜明けが来た。君の歩みは止められない。")
  107. self.stdscr.refresh()
  108. self.stdscr.getch()
  109.  
  110. if __name__ == "__main__":
  111. curses.wrapper(JusticeGame)
  112.  
Advertisement
Add Comment
Please, Sign In to add comment