A Tetris Game for programming education

Overview

Tetris Game

プログラミング学習を目的とした、ブロックを操作してスコアを競うゲームです。
FAQはこちら。
tutorialはこちら。

実行環境準備

Mac環境

Finder→Application→Utility→Terminalから、ターミナルを起動して以下コマンドを実行する。

# install pyqt5 and NumPy
brew install python3
pip3 install pyqt5
pip3 install numpy
# install other packages
brew install git

doc/files/install_mac.mdに上記手順を記載

Ubuntu/JetsonNano環境

doc/files/install_ubuntu.mdに手順を記載

windows環境

WSL(Windows Subsystem for Linux)を使う場合の手順
Docker for Windowsを使う場合の手順

docker環境

docker/README.mdに手順を記載

実行方法

本リポジトリを取得

cd $HOME
git clone https://github.com/seigot/tetris_game

ゲーム開始用スクリプトを実行

cd tetris_game
bash start.sh

Screenshot

ファイル構成

ファイル一覧

  • game_manager/game_manager.py : ゲーム管理用プログラム
  • game_manager/board_manager.py : ボード管理用プログラム
  • block_controller.py : ブロック操作用プログラム(ブロックの操作は、このファイルを更新して下さい。)
  • start.sh : ゲーム開始用スクリプト

詳細

以下のような構成になっています。
ブロック操作用プログラムは、管理プログラムから定期的に呼び出されるので、ボード情報から次の動作を決定して下さい。

Screenshot

詳細

手動操作

実行時、以下のようにオプションを与えることで、手動操作が可能です。 操作方法は、PC操作準拠とゲーム機コントローラ準拠の2種類を選択できるようにしています。

手動操作 PC操作準拠 ゲーム機コントローラ準拠
実行コマンド bash start.sh -m y bash start.sh -m g
up key 回転 落下
left key 左に移動 左に移動
right key 右に移動 右に移動
m key 下に移動 下に移動
space key 落下 回転
P key Pause Pause

スコアアタック用サンプルコード

実行時、以下のようにオプションを与えることで、スコアアタック用サンプルコードの実行が可能です。
サンプルコードについてブロック操作用サンプルプログラムを参照下さい。

bash start.sh -s y

Play rules

制限時間内の獲得スコアを評価します。

Score

加点

項目 得点 備考
1ライン消し + 100点 -
2ライン消し + 300点 -
3ライン消し + 700点 -
4ライン消し + 1300点 -
落下ボーナス + 落下したブロック数を得点に加算 -

減点

項目 得点 備考
gameover - 500点 ブロック出現時にフィールドが埋まっていたらgameover

game level

実行時、オプションを与えることで、難易度(レベル)を指定できます。

level1 level2 level3
実行方法 bash start.sh bash start.sh -l2 bash start.sh -l3
制限時間 180秒 180秒 180秒
ブロックの順番 固定(1-7まで順番に繰り返し) ランダム ランダム
フィールドの初期ブロック なし なし あり
フレーム更新頻度 約1秒 約1秒 約1秒
備考 - - -

各レベルの参考スコア

コード作成のはじめかた

本リポジトリのfork

まず、Githubアカウントを取得して本リポジトリを自リポジトリにforkして下さい。

リポジトリのフォークの例

  1. GitHubアカウントを作成/ログインする。
  2. GitHub で、https://github.com/seigot/tetris_gameリポジトリに移動します
  3. ページの右上にある [Fork] をクリックします。
    参考:リポジトリをフォークする

その後、自リポジトリにforkしたtetris_gameをローカルマシンに取得して下さい。

"さん(yourname=自分のアカウント名に読みかえて下さい)のリポジトリを取得する場合 git clone https://github.com/seigot/tetris_game # このリポジトリを取得する場合 ">
cd ~
git clone https://github.com/
    
     /tetris_game   # "
     
      "さん(yourname=自分のアカウント名に読みかえて下さい)のリポジトリを取得する場合
git clone https://github.com/seigot/tetris_game       # このリポジトリを取得する場合

     
    

既にtetris_gameが存在しており、これを削除したい場合はrm -fを実行して下さい。

sudo rm -rf tetris_game

取得後はソースコード変更、変更リポジトリに反映する等してアップデートを進めて下さい。

実行

実行方法を参考に実行環境の構築をして下さい。
環境構築の完了後、ブロック操作用プログラムblock_controller.pyを更新していってください。

自リポジトリのバイナリを公式リリースする

提出時、自リポジトリのバイナリを公式リリースする場合は、Githubリリースの機能を使うと簡単なのでお勧めです。

自リポジトリのコードを提出(バイナリリリース)する場合の手順参考
リポジトリのリリースを管理する
7.オプションで、コンパイルされたプログラムなどのバイナリファイルをリリースに含めるには、ドラッグアンドドロップするかバイナリボックスで手動で選択します。

本リポジトリの最新バージョン取り込み

今後、本リポジトリもバージョンアップしていく予定です。
本リポジトリのバージョンアップを取り込む場合は、forkしたリポジトリにて以下を実行して下さい。

※追記 2021/5より、Github UI上から操作可能になったようです。
GitHub新機能「Fetch upstream」使ってみた! 1クリックで親リポジトリに追従(同期)

git checkout master                                        # ローカルのmainブランチに移動
git remote add upstream https://github.com/seigot/tetris_game  # fork元のリポジトリをupstream という名前でリモートリポジトリに登録(名前はなんでもいい。登録済みならスキップ)
git fetch upstream                                         # upstream から最新のコードをfetch
git merge upstream/master                                  # upstream/main を ローカルのmaster にmerge
git push                                                   # 変更を反映

参考:github で fork したリポジトリで本家に追従する

Pull Requestを送る(Optional)

本リポジトリへ修正リクエストを送ることが可能です。詳しくは参考をご参照下さい。

※追記 Pull Request練習用リポジトリを作成しました。
test_pull_request

参考:
GitHub-プルリクエストの作成方法
[実践] はじめてのPull Requestをやってみよう
【GitHub】Pull Requestの手順

FAQ

doc/files/FAQ.mdを参照下さい。

参考

https://github.com/LoveDaisy/tetris_game
https://github.com/seigot/tetris_game(2021.12時点まで使用) http://zetcode.com/gui/pyqt5/tetris/
テトリスの歴史を「ブロックが落ちるルール」の進化から学ぶ

今後の課題

次のブロックのランダム性

次のブロックのランダム性は、現在はrandom関数の出力に依存しています。
しかし、こちらの記事によると選択方式が色々ありそうです。
有識者の方からアドバイス頂けると助かります。

nextShapeIndex = np_randomShape.random.randint(1, 8)

対戦モード実装

準備中

AI実装

準備中

自動評価

準備中

LICENSE

MIT LICENSE

Finnaly

~ HAVE FUN ~

CTF (Capture The Flag) started from DEFCON CTF, a competitive game among computer security enthusiasts

CTF Wiki 中文 English Welcome to CTF Wiki! CTF (Capture The Flag) started from DEFCON CTF, a competitive game among computer security enthusiasts, origi

CTF Wiki 6.4k Jan 03, 2023
A simple hangman game for beginners trying to learn python

Hangman Game This is a simple hangman game for beginners trying to learn python. I have tried to keep it as simply as possible. Sample output Here is

1 Oct 13, 2021
Aftermath is an anti token grabber written in Python3.

🎈 Aftermath 🎈 Aftermath is an anti token grabber written in Python3. This tool with a GUI setup is checking the Downloads folder to search for token

Billy 39 Dec 16, 2022
Tool for Path of Exile game to automatically scan Archemesis inventory and display related information

poe-archnemesis-scanner Tool for Path of Exile game to automatically scan Archemesis inventory and display related information Features Controls When

70 Nov 10, 2022
Nerdle - a nerd's approach to solving Wordle

Nerdle - a nerd's approach to solving Wordle

4 Nov 28, 2022
Space shooter being built for PyWeek 32

Axium Humanity's expansion into space had lasted centuries by the time we encountered the vicious Threx. The Threx adopted a single, religious mission

Daniel Pope 6 Oct 28, 2021
Launcherpi - Minecraft Launcher for Raspberry Pi computers

launcherpi Minecraft Launcher for Raspberry Pi computers. ASLO BIG THANKS TO KLO

8 Sep 24, 2022
A visualization of how much Manchester United fans enjoyed each game from the first half of the 21/22 Premier League season.

Man-Utd-Fan-Satisfaction-Levels-First-19-games A visualization of how much Manchester United fans enjoyed each game from the first half of the 21/22 P

1 Jan 19, 2022
OpenGL experiments with Pygame & ModernGL

pygame-opengl OpenGL experiments with Pygame & ModernGL TODO Skybox & Reflections Post-process effects (motion blur, color correction, etc..) Normal m

Kadir Aksoy 4 Oct 28, 2022
Given some input, spit out the possible words for a Wordle puzzle

Wordle Helper, because why not. Given some input, spit out the possible words for a Wordle puzzle First time setup # Download the dictionary to a file

Richard Duarte 1 Jan 25, 2022
The Bowling Club (Facebook Game) get all strikes.

TheBowlingClubBot The Bowling Club (Facebook Game) get all strikes. FAQ Q: What is this? A: TheBowlingClubBot is a automation bot with 99.99% guarante

#~Rith 1 Jan 19, 2022
An open-world game made in Python.

Dragon Realms Notes Windows OS only Contributors This project follows the all-contributors specification (emoji key, command Issue). See what you can

Dragon Realms 2 Jul 28, 2022
Wordle-prophecy - The comprehensive list of all Wordle answers, past and future

About This repo contains the comprehensive list of all Wordle answers, past and

Hayden Moritz 2 Dec 15, 2022
A python program for playing rock-paper-scissors with computer .

Rock_Paper_Scissors_Cut A time passing famous hand game known as rock paper scissors cut game. Starting from children to adults everyone plays this ga

Arghya Banerjee 1 Dec 16, 2021
Creating Tetris with Pygame

Tetris 🤝 Contributing Contributions, issues and feature requests are welcome! Feel free to check issues page. Show your support Give a ⭐️ if this pro

Gavin Capriola 0 Mar 01, 2022
This project is an exciting fun game for beginners to build up

This project is an exciting fun game for beginners to build up. The program generates a random number from 1 to 10, or 1 to 100 any range that is specified and the user must guess the number after a

PyLaboratory 0 Feb 07, 2022
Minecraft.nix - Command line Minecraft launcher managed by nix

minecraft.nix Inspired by this thread, this flake contains derivations of both v

12 Sep 06, 2022
A Pygame application which generates mazes using randomized DFS (Depth-First-Search)

Maze-Generator-with-Randomized-DFS A Pygame application which generates mazes using randomized DFS (Depth-First-Search)-(Iterative implementation). Ra

Aysha sana 2 Feb 08, 2022
NSI project --> 2D platformer in Python with Pygame

Projet de NSI (2021-2022): Jeu sous Python Collaborateurs: Remi K-S et Nathan D Lien de l'environnement IDE de Python en ligne: https://replit.com/@Re

Remi K-S 3 May 24, 2022
A launcher to launch games from Riot Games under Linux

rito-launcher A launcher to launch games from Riot Games under Linux Requirements: Python 3, with the following pip plugins: 'configparser, pathlib, w

6 Mar 07, 2022