Try   HackMD

資訊之芽一階大作業 - Tetris

作業繳交表單:https://forms.gle/AKotzxUeXfhmZUWP8

死線

5/2

投影片連結

事前準備

安裝 python3

大家應該早就有了(吧?

安裝 pygame

Win10

以系統管理員身份打開命令提示字元 (cmd),執行以下指令:

如果是使用 Anaconda 安裝 python 的,請打開「開始功能表

Anaconda3
Anaconda Prompt」

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

並輸入以下指令:

pip install pygame

(失敗的話,請試試 python3 -m pip install pygame

MacOS / Linux

打開終端機 / Terminal,輸入指令:

pip3 install pygame

安裝 VSCode (可選)

如果要同時看很多檔案會比較舒服!link

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

下載作業檔(重要)

下載下來後右鍵點選解壓縮。

作業檔案連結

執行

  1. 在作業資料夾打開 cmd 或是 terminal
  2. 使用 cd [位置] 跳到正確的資料夾
  3. python3 main.py

現在你應該要看到下面這個畫面

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

調整尺寸

如果視窗大小對你的電腦來說太大的話,可以修改config.py裡面的 unit

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

現在你可以按按看上下左右
動不了?很正常,因為你的作業是讓他動起來

怎麼做?趕快把 Handler.py 填起來吧!

建議可以看看整份 code 寫了哪些東西

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

說明

shot.status[y][x] == 0 -> 沒東西
shot.status[y][x] == 1 -> 移動中的方塊
shot.status[y][x] == 2 -> 已被佔據

Tasks

以下只是把相關性比較大的工作綁在一起,請按照你覺得合理的順序做 (?

為了可讀性,建議多使用config內的常數

繳交時只須繳交Handler.py,其他檔案除了main.pyDEBUG = True那行以外你們不太需要去動,但鼓勵你們研究看看。詳細的pygame用法會在二階教

建議早點開始做,這樣有問題時才有時間找講師或同學討論喔

為了方便你們寫作業,注意到main.py第8行是DEBUG = True,最後會用DEBUG = False來評分

Task 0 - 方塊左右移動

moveLeft
moveRight

  • (10 pts) 方塊可以左右移動(按左方向鍵、右方向鍵會有反應)(in class)
  • (5 pts) 不會讓方塊超出邊界,若會超過就不給移動 (hint: 要做某些判斷)
  • (5 pts) 方塊左右移動時不會穿過其他方塊,若會穿過就不給移動 (hint: 判斷某個方格是否已被佔據,使用shot.status[y][x] == 2)

Task 1 - 方塊掉落

如果你做完了可以把main.py第8行改成DEBUG = False試試

drop
instantDrop

  • (10 pts) 讓方塊可以往下掉 (in class)
  • (5 pts) 方塊落地不會超出邊界 (in class)
  • (5 pts) 方塊落地時把方塊停下來 (in class) (使用fixPiece函數)
  • (5 pts) 方塊落到其他方塊上方後不會穿過其他方塊
  • (5 pts) 方塊落到其他方塊上方後,把方塊停下來 (使用fixPiece函數)
  • (5 pts) 實做instantDrop,方塊可以直接落地,適合沒耐心的人(?

Task 2 - 方塊旋轉

rotate

  • (10 pts) 讓方塊可以旋轉
  • (5 pts) 讓方塊旋轉時不會超過邊界,若會超過就不能旋轉
  • (5 pts) 讓方塊旋轉時不會穿過其他方塊

Task 3 - 可以死掉

isDefeat

如果新方塊生出來的地方已經被佔據就要return True,否則return False

  • (10 pts) 實做isDefeat,方塊滿出來時會game over

Task 4 - 消去列與計算分數

eliminateFilledRows

分數算法寫在config.py
score_count: 一次消幾行就加幾分

  • (10 pts) 實做eliminateFilledRows,可以正常地把一列消掉
  • (5 pts) 順便將消掉的行數以及加分更新至shot.line_count和shot.score

可能會用到的小技巧

可以把你要處理的資料印出來看看

  • 印出多層list可以使用 pprint 套件

參考影片

俄羅斯方塊也有世界大賽? 冠軍的手速快到你無法想像! | 啾啾鞋

16 Y/O UNDERDOG vs. 7-TIME CHAMP - Classic Tetris World Championship 2018 Final Round

5 Essential Tips To Look Like A Pro In Tetris

FAQ

Q: 方塊的格式是什麼?
A: 詳細可以看piece.py這個檔案,他是一個物件,簡單來說就是存放一些資料的東西。在大作業中需要直接去操作的值基本上只有y, x, rotation