溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

python怎樣實(shí)現(xiàn)簡(jiǎn)單飛行棋

發(fā)布時(shí)間:2021-03-24 10:01:41 來(lái)源:億速云 閱讀:209 作者:小新 欄目:開(kāi)發(fā)技術(shù)

這篇文章主要介紹python怎樣實(shí)現(xiàn)簡(jiǎn)單飛行棋,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!

chess_main.py

import chess_tools

# 輸入玩家信息
chess_tools.input_player()

while chess_tools.end_flag:
  for player in chess_tools.player_list:
    chess_tools.ironman(player)
    input(player["name"]+",請(qǐng)按enter擲骰子")
    chess_tools.throw(player)
    if chess_tools.judge(player) == 1:
      break
    chess_tools.hit(player)
    chess_tools.speedup(player)
    print("")

chess_tools.py

from random import randint


player_list = []
end_flag = 1


def input_player():
  num = input("數(shù)據(jù)玩家數(shù)量:")
  i = 0
  while i < int(num):
    player_name = input("輸入第" + str(i + 1) + "位玩家名字:")
    play_info = {"name": player_name,
           "score": 0}
    player_list.append(play_info)
    i = i + 1


def throw(player):
  """
  玩家扔骰子,隨機(jī)1-6點(diǎn)
  :param player: 當(dāng)前玩家
  :return:
  """
  points = randint(1,6)

  # 首先判定是否起飛
  if player["score"] == 0 and points == 6:
    player["score"] = 1
    print("%d 點(diǎn),恭喜起飛!當(dāng)前在第%d格" % (points, player["score"]))

  elif player["score"] == 0 and points < 6:
    print("%d 點(diǎn),起飛失?。?quot; % points)
    return
  # 分?jǐn)?shù)大于100,要后退,多幾分退幾步
  elif player["score"] + points > 100:
    player["score"] = player["score"] - (player["score"]+ points) % 100 + 1
    print("%d 點(diǎn),飛過(guò)頭了!回到%d格" % (points,player["score"]))
  else:
    player["score"] += points
    print("%d 點(diǎn)!當(dāng)前在第%d格" % (points, player["score"]))


def judge(player):
  global end_flag
  if player["score"] == 100:
    end_flag = 0
    print(player["name"]+"贏了")
    return 1


def hit(player):
  """
  判斷當(dāng)前玩家是否會(huì)將領(lǐng)先的玩家撞回起飛位置
  :param player: 當(dāng)前玩家名字
  """
  for other_player in player_list:
    if player["score"] == other_player["score"] \
        and other_player["name"] != player["name"]:
      other_player["score"] = 0


def speedup(player):
  if player["score"] == 15 or \
      player["score"] == 35 or \
      player["score"] == 85:
    player["score"] += 5
    print("加速5格,當(dāng)前在%d格" % player["score"])


def ironman(player):
  """
  主角光環(huán),名字中含有指定字符的人可以獲得50分加成
  :param player:當(dāng)前玩家的名字
  """
  master = player["name"].count("t")
  if master > 0 and player["score"] == 0:
    player["score"] = 50
    print("- I am Iron Man!賈維斯,先給我加50分。")
    print("- 好的,%s 。當(dāng)前已走到第50格。" % player["name"])
    print("")

以上是“python怎樣實(shí)現(xiàn)簡(jiǎn)單飛行棋”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI