用python写了一个简略版的飞行棋,还挺有意思的,大家有时间可以试着玩玩
import random
class Player:
def __init__(self, name, color):
self.name = name
self.color = color
self.pieces = [0] * 4 # 棋子的起始位置
def move_piece(self, index, steps):
if self.pieces[index] + steps <= 63: # 假设棋盘大小为64格,0为起点,63为终点
self.pieces[index] += steps
else:
self.pieces[index] = 63 # 到达终点
class Game:
def __init__(self):
self.players = [Player("Player 1", "Red"), Player("Player 2", "Blue"),
Player("Player 3", "Green"), Player("Player 4", "Yellow")]
self.current_player_index = 0
def roll_dice(self):
return random.randint(1, 6) # 投掷1-6的骰子
def play_turn(self):
current_player = self.players[self.current_player_index]
dice_roll = self.roll_dice()
print(f"{current_player.name} rolls a {dice_roll}.")
# 选择要移动的棋子
while True:
piece_index = int(input(f"{current_player.name}, choose a piece to move (0-3): "))
if 0 <= piece_index < 4:
break
else:
print("Invalid piece index. Please choose again.")
current_player.move_piece(piece_index, dice_roll)
# 检查是否有棋子到达终点
if current_player.pieces[piece_index] == 63:
print(f"{current_player.name}'s piece {piece_index + 1} has reached the finish line!")
# 轮到下一个玩家
self.current_player_index = (self.current_player_index + 1) % 4
def start_game(self):
while True:
self.play_turn()
# 可以在这里添加游戏结束的条件,比如所有玩家的棋子都到达终点
if __name__ == "__main__":
game = Game()
game.start_game()