Python 入門指南 5.0
exercise4408.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | # 從 Brython 引入 document 並以 doc 為別名 from browser import document as doc # 從 Brython 引入 window from browser import window # 引入 Point 定義 from exercise1810 import Point # 引入 Lion 定義 from exercise1812 import Lion # 引入 Elephant 定義 from exercise2901 import Elephant # 引入 Cat 定義 from exercise2902 import Cat # 引入 Mouse 定義 from exercise2903 import Mouse # 引入 move() 定義 from exercise2807 import move # 引入 bound_check() 定義 from exercise2605 import bound_check # 引入 animal_check() 定義 from exercise2809 import animal_check # 引入 get_world_string() 定義 from exercise2906 import get_world_string # 遊戲資料 user = Mouse(Point(3,0), "鼠") animals = {} animals["鼠"] = user animals["象"] = Elephant(Point(0,0), "象") animals["獅"] = Lion(Point(0,3), "獅") animals["貓"] = Cat(Point(3,3), "貓") world = [["口", "口", "口", "口"], ["口", "口", "口", "口"], ["口", "口", "口", "口"], ["口", "口", "口", "口"]] # 印出鬥獸棋棋盤 def print_world(animals_list, world): temp_list = get_world_string(animals_list, world).split("\n") for temp in temp_list: d = doc.createElement("div") d.style.border = "none" d.style.padding = "0" d.style.margin = "0" d.style.fontSize = "3em" d.text = temp doc["display"] <= d # 初始設定 doc["button_up"].disabled = True doc["button_left"].disabled = True doc["button_right"].disabled = True doc["button_down"].disabled = True print_world(list(animals.values()), world) # 檔名: exercise4408.py # 說明:《Python入門指南》的練習 # 網站: http://kaiching.org # 作者: 張凱慶 # 時間: 2023 年 12 月 |