こんばんは。Yuinaです!
今日は、Pythonですごろくゲームを作りました。
sugoroku1.py
class Rule():
def __init__(self):
self.players = ['私','CPU']
self.goal = 20
self.positions = [0,0]
class Player(Rule):
def __init__(self):
super(). __init__()
self.player_name = self.players[0]
self.position = self.positions[0]
class Player2(Rule):
def __init__(self):
super(). __init__()
self.player_name = self.players[1]
self.position = self.positions[1]
class PointState(Rule):
def __init__(self):
super(). __init__()
self.dice = [0,0]
main.py
import random
from sugoroku1 import Rule, Player, Player2, PointState
game_rules = Rule()
player1 = Player()
player2 = Player2()
game_state = PointState()
while True:
print(f"{player1.player_name}の順番")
input()
dice_roll = random.randint(1, 6)
print(f"サイコロの目: {dice_roll}")
player1.position += dice_roll
game_state.positions[0] = player1.position
print(f"{player1.player_name}の現在位置: {player1.position}")
if player1.position >= game_rules.goal:
print(f"{player1.player_name}の勝ち")
break
print(f"{player2.player_name}の順番")
input()
dice_roll = random.randint(1, 6)
print(f"サイコロの目: {dice_roll}")
player2.position += dice_roll
game_state.positions[1] = player2.position
print(f"{player2.player_name}の現在位置: {player2.position}")
if player2.position >= game_rules.goal:
print(f"{player2.player_name}の勝ち")
break

クラスの継承やオブジェクト指向の復習になってよかったです。
ありがとうございました✨