jyun w
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # 2023 資訊之芽 Python 語法班第一階段大作業 貪吃蛇 ## Deadline: 4/30 ## 新 Deadline : 5/3 23:59 ## Announcement - 4/14: 因為有些人還是不太清楚一些function的實作方法,所以在 [提示](#提示) 裡面簡單介紹 `generate_food, detect_food_collision` 可以嘗試的方向 - 4/15: `Controller.py` 的 `generate_poison` 的註解有誤。 原本註解為 ``` 在隨機位置生成一個 `Poison` 的物件並回傳,不能與現有其他物件或玩家重疊 無回傳值 ``` 應更正成 ``` 在隨機位置生成一個 `Poison` 的物件並回傳,不能與現有其他物件或玩家重疊 ``` - 5/1: 因為繳交數比我們預期中的少,所以我們將這次大作業延長3天到5/3 23:59,但是遲交的分數會打6折。改作業時依舊會照最晚交的那份為主。時間戳記依據google表單。 ## Links [作業程式連結](https://drive.google.com/file/d/1YrwB7ykygJAjRtRGN6UvgBSgt__f2TPa/view?usp=sharing) [作業繳交連結](https://docs.google.com/forms/d/e/1FAIpQLSfmsMORgSIgVNw3sZoovcAquAyNC5TuhEaXzIdRitIq3GYzfw/viewform) ## 事前準備 ### 安裝 python3 - 理論上大家應該都裝好了(?) ### 安裝 `pygame` **注意:指令都只要複製 `$` 後面的字就好,`$` 是表示指令之前的提示符號** #### Windows 按下 Win+R,輸入 `cmd` 開啟命令提示字元 輸入以下指令安裝 `pygame` 的遊戲套件 ``` $ python -m pip install pygame --user ``` 或是 ``` $ python3 -m pip install pygame --user ``` #### MacOS/Linux 打開 terminal,輸入以下指令 ``` $ python3 -m pip install pygame --user ``` ### 下載作業 到 [Links](#Links) 下載作業連結。解壓縮後應該會有這些檔案 - `main.py` - `Models.py` - `Controllers.py` - `Config.py` ### 執行 打開 cmd 或 terminal 輸入以下指令,`python` 還是 `python3` 是根據 [安裝](#安裝-pygame) ``` $ cd 程式資料夾 $ python main.py (或是) $ python3 main.py ``` 如果一切都沒有問題的話應該會跳出一個視窗,然後在 terminal 出現以下文字 ![](https://i.imgur.com/8ofN0u3.png) ## 作業內容 - 透過方向鍵控制貪吃蛇移動,吃到食物長度會變長,吃到毒藥長度會變短,碰到邊界、牆壁、自己就遊戲結束。 - 碰到食物或毒藥後要生出新的對應物件。 - 移動的時間間隔會隨著蛇的長度而變短 一共有 4 個 `.py` 檔案 - 主要的遊戲迴圈在 `main.py` 裡面 - `Config.py` 裡面定義一些會用到的常數及設定 - `Model.py` 裡面定義遊戲物件,如食物、牆壁、蛇等 - `Controller.py` 裡面是一些關於偵測和操控物件的函式 交作業的時候請只把所有必要的檔案,外加`README.txt/README.md`加到壓縮檔 `姓名_X區.zip` 內 解壓縮 `王小明_北區.zip`後,資料夾的內容應該要長這樣 ![](https://i.imgur.com/MDxkq0E.png) ## Tasks 底下依照類別或功能做了分類,沒有說一定要按照這個順序 (但有些還是要,例如要先做生成再做碰撞) 括號中的是跟該功能相關的 function 名稱 另外,每個你要完成的 function 中都有註解告訴你細節,你只需要把中文理解之後轉換成 Python 程式碼即可 ### 移動 - [ ] 玩家移動(`Player.move`) - *10pt* ### 生成物件 - [ ] 生成牆壁(`Controller.py generate_wall`) - *10pt* - [ ] 新牆壁生在現有牆壁周圍 - *10pt (bonus)* - [ ] 生成食物(`Controller.py generate_food`) - *5pt* - [ ] 生成毒藥(`Controller.py generate_poison`) - *5pt* - [ ] 生成蛇(`Player.new_block`) - *5pt* ### 碰撞 - [ ] 邊界碰撞(`Player.check_border`) - *5pt* - [ ] 蛇碰撞(`Player.detect_player_collision`) - *15pt* - [ ] 牆壁碰撞(`Player.detect_wall_collision`) - *5pt* - [ ] 食物碰撞(`Player.detect_food_collision`) - *10pt* - [ ] 毒藥碰撞(`Player.detect_poison_collision`) - *10pt* ### 遊戲機制 - [ ] 根據蛇長度調整移動間格(`Controller.py` 的 `calculate_time_interval`) - *10pt* ### 其他 - [ ] 畫蛇添足(`Player.draw_snake`) - *5pt* - [ ] coding style - *5pt(bonus)* - [ ] 檔案結構 - *5pt* - [ ] README.md or README.txt,裡面記錄你加了什麼功能 - [ ] Controller.py - [ ] Model.py - [ ] Config.py - [ ] main.py - [ ] 其他可能會用到的檔案(圖片、模組等) - [ ] 用 zip 格式壓縮,檔名格式為 `王小明_北區.zip` - [ ] 發揮你的創意(加了甚麼記得寫在README裡面,沒寫此項目不予給分) - *0~10pt(bonus)* --- ## 提示 這邊只是給不知道怎麼寫的人一個大概的方向,如果你的做法跟這邊不一樣也沒關係 ```python def detect_food_collision(self, foods): """ 判斷蛇的頭是否碰到食物 有碰到就回傳 True 沒有碰到回傳 False """ # 定義第一塊的位置 # 把 foods 裡面每一項抓出來比對 # 如果 x 或 y 的座標差比蛇的寬高小就算碰撞 ``` ```python def generate_food(foods, walls, player): """ 在隨機位置生成一個Food的物件並加到foods裡面,不能與現有牆壁或玩家重疊 無回傳值 """ # 隨機選一個座標 # 跟每個物件一一比對有沒有重疊 # 如果重疊就重新選座標 ```

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully