当前位置: 首页>>代码示例>>Python>>正文


Python Player.ships_left方法代码示例

本文整理汇总了Python中models.Player.ships_left方法的典型用法代码示例。如果您正苦于以下问题:Python Player.ships_left方法的具体用法?Python Player.ships_left怎么用?Python Player.ships_left使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Player的用法示例。


在下文中一共展示了Player.ships_left方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from models import Player [as 别名]
# 或者: from models.Player import ships_left [as 别名]
def main():
    """Run the console-based python game"""
    # start with a clear screen
    clear_screen()
    show_banner()
    # ask for players names
    name1 = ask_player_name("Player 1")
    name2 = ask_player_name("Player 2")
    # initiate player instances
    player1 = Player(name1)
    player2 = Player(name2)
    input("\nNext you'll each add your ships. {} first. (No peeking {})\n\n"
          "Hit ENTER to continue....".format(name1, name2))

    # placing ships
    clear_screen()
    # defind player1's fleet and add to board
    define_fleet(player1)
    show_banner()
    input("Time to add {}'s ships. Hit ENTER to continue....".format(name2))
    # define player2's fleet and add to board
    define_fleet(player2)

    # commense game play
    show_banner()
    input("Game Time! {} goes first. Hit ENTER to continue....".format(name1))
    game_continue = True
    while game_continue:
        take_turn(player1, player2)
        if not player2.ships_left():
            show_banner()
            input("{} WINS!!! Hit ENTER to see final boards....\n"
                  "".format(player1.name))
            game_continue = False
            continue
        take_turn(player2, player1)
        if not player1.ships_left():
            show_banner()
            input("{} WINS!!! Hit ENTER to see final boards....\n"
                  "".format(player2.name))
            game_continue = False

    # Display final boards
    print_all_boards(player1.name, player2.name,
                     player1.board.get_player_view(),
                     player2.board.get_player_view())
开发者ID:ChrisFreeman,项目名称:battleship,代码行数:48,代码来源:battleship.py


注:本文中的models.Player.ships_left方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。