7

Python3编程实战Tetris游戏(序)

 3 years ago
source link: https://segmentfault.com/a/1190000040121026
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Python3编程实战Tetris游戏(序)

本系列文章,使用Python3一步步记录Tetris游戏的编写全过程,游戏功能包括手动游戏、游戏回放(数据库操作)、自动游戏(AI机器人)。已经完成C++版本,Qt5之QGraphicsItem编写Tetris俄罗斯方块游戏

  • 项目结构
  • block类,最小方块定义
  • tetris类,俄罗斯方块定义
  • tetris方块的移动与旋转
  • game类,游戏流程控制
  • 完成游戏基本功能,支持游戏暂停
  • 为数据查询封装json
  • 设计通用数据库操作封装,首先使用sqlite3
  • 设计ORM实现自动查询
  • 存储历史数据,实现游戏回放
  • 机器学习,改进AI

该游戏尽量不使用第三方库,主要注重算法,因此界面库选择python内置的tkinter。设计思想也采用传统的方式,用一个二维数组来控制游戏空间,类似迷宫的方式。选择这种方式有一个好处是,游戏的数据直观存在,容易获取。

https://gitee.com/zhoutk/ptetris
或
https://github.com/zhoutk/ptetris
1. install python3, git
2. git clone https://gitee.com/zhoutk/ptetris (or download and unzip source code)
3. cd ptetris
4. python3 tetris

This project surpport windows, linux, macOs

on linux, you must install tkinter first, use this command:  
sudo apt install python3-tk

已经实现了C++版,项目地址:

https://gitee.com/zhoutk/qtetris

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK