简略版的飞行棋

用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()

  • 4
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值