tetris-terminal 0.0.1__tar.gz → 0.0.1a1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {tetris_terminal-0.0.1 → tetris_terminal-0.0.1a1}/LICENSE +8 -8
- {tetris_terminal-0.0.1/src/tetris_terminal.egg-info → tetris_terminal-0.0.1a1}/PKG-INFO +70 -65
- {tetris_terminal-0.0.1 → tetris_terminal-0.0.1a1}/README.md +42 -36
- {tetris_terminal-0.0.1 → tetris_terminal-0.0.1a1}/pyproject.toml +50 -50
- {tetris_terminal-0.0.1 → tetris_terminal-0.0.1a1}/setup.cfg +4 -4
- tetris_terminal-0.0.1a1/src/tetris/__init__.py +0 -0
- {tetris_terminal-0.0.1 → tetris_terminal-0.0.1a1}/src/tetris/cli.py +18 -18
- {tetris_terminal-0.0.1 → tetris_terminal-0.0.1a1}/src/tetris/tetris.py +199 -203
- {tetris_terminal-0.0.1 → tetris_terminal-0.0.1a1/src/tetris_terminal.egg-info}/PKG-INFO +70 -65
- {tetris_terminal-0.0.1 → tetris_terminal-0.0.1a1}/src/tetris_terminal.egg-info/SOURCES.txt +0 -1
- tetris_terminal-0.0.1/src/tetris/__init__.py +0 -3
- tetris_terminal-0.0.1/src/tetris_terminal.egg-info/requires.txt +0 -3
- {tetris_terminal-0.0.1 → tetris_terminal-0.0.1a1}/src/tetris_terminal.egg-info/dependency_links.txt +0 -0
- {tetris_terminal-0.0.1 → tetris_terminal-0.0.1a1}/src/tetris_terminal.egg-info/entry_points.txt +0 -0
- {tetris_terminal-0.0.1 → tetris_terminal-0.0.1a1}/src/tetris_terminal.egg-info/top_level.txt +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright 2026 Jay Zhu
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
-
|
|
7
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
-
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright 2026 Jay Zhu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
9
|
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -1,65 +1,70 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: tetris-terminal
|
|
3
|
-
Version: 0.0.
|
|
4
|
-
Summary: A tetris game runs in the terminal
|
|
5
|
-
Author-email: jayzhu <jay.l.zhu@foxmail.com>
|
|
6
|
-
Project-URL: homepage, https://github.com/zlh124/pytetris
|
|
7
|
-
Classifier: Development Status :: 3 - Alpha
|
|
8
|
-
Classifier: Environment :: Console :: Curses
|
|
9
|
-
Classifier: Intended Audience :: End Users/Desktop
|
|
10
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
-
Classifier: Operating System :: POSIX :: Linux
|
|
12
|
-
Classifier: Operating System :: MacOS :: MacOS X
|
|
13
|
-
Classifier: Operating System :: Microsoft :: Windows
|
|
14
|
-
Classifier: Programming Language :: Python :: 3
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
-
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
-
Classifier: Topic :: Games/Entertainment :: Puzzle Games
|
|
22
|
-
Classifier: Topic :: Terminals
|
|
23
|
-
Requires-Python: >=3.8
|
|
24
|
-
Description-Content-Type: text/markdown
|
|
25
|
-
License-File: LICENSE
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
[
|
|
29
|
+
# Pytetris 🎮
|
|
30
|
+
A terminal-based Tetris game written in Python using the `curses` library.
|
|
31
|
+
|
|
32
|
+
[](LICENSE)
|
|
33
|
+
[]()
|
|
34
|
+
|
|
35
|
+
### Features
|
|
36
|
+
- Classic Tetris gameplay with 7 standard tetrominoes
|
|
37
|
+
- Real-time score
|
|
38
|
+
- Next piece preview
|
|
39
|
+
|
|
40
|
+
### Platform Support
|
|
41
|
+
Based on Python's [`curses`](https://docs.python.org/3/library/curses.html) module:
|
|
42
|
+
- ✅ **Linux/macOS**: Works out of the box
|
|
43
|
+
- ⚠️ **Windows**: Not supported yet
|
|
44
|
+
|
|
45
|
+
### Installation & Usage
|
|
46
|
+
- Using [uv](https://github.com/astral-sh/uv) (recommended):
|
|
47
|
+
```bash
|
|
48
|
+
uv pip install -e .
|
|
49
|
+
pytetris
|
|
50
|
+
```
|
|
51
|
+
- Using pip (alternative):
|
|
52
|
+
```bash
|
|
53
|
+
pip install -e .
|
|
54
|
+
pytetris
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Controls
|
|
58
|
+
| Key | Action |
|
|
59
|
+
|-----------|-----------------|
|
|
60
|
+
| `a` | Move left |
|
|
61
|
+
| `d` | Move right |
|
|
62
|
+
| `w` | Rotate piece |
|
|
63
|
+
| `s` | Hard drop |
|
|
64
|
+
| `q` | Quit game |
|
|
65
|
+
|
|
66
|
+
### License
|
|
67
|
+
MIT License - see [LICENSE](LICENSE) for details.
|
|
68
|
+
|
|
69
|
+
### Acknowledgements
|
|
70
|
+
Game logic adapted from [tinytetris](https://github.com/taylorconor/tinytetris) (a C implementation).
|
|
@@ -1,37 +1,43 @@
|
|
|
1
|
-

|
|
2
|
-
#
|
|
3
|
-
A terminal-based Tetris game written in Python using the `curses` library.
|
|
4
|
-
|
|
5
|
-
[](LICENSE)
|
|
6
|
-
[]()
|
|
7
|
-
|
|
8
|
-
### Features
|
|
9
|
-
- Classic Tetris gameplay with 7 standard tetrominoes
|
|
10
|
-
- Real-time score
|
|
11
|
-
- Next piece preview
|
|
12
|
-
|
|
13
|
-
### Platform Support
|
|
14
|
-
Based on Python's [`curses`](https://docs.python.org/3/library/curses.html) module:
|
|
15
|
-
- ✅ **Linux/macOS**: Works out of the box
|
|
16
|
-
-
|
|
17
|
-
|
|
18
|
-
### Installation & Usage
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
1
|
+

|
|
2
|
+
# Pytetris 🎮
|
|
3
|
+
A terminal-based Tetris game written in Python using the `curses` library.
|
|
4
|
+
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
[]()
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
- Classic Tetris gameplay with 7 standard tetrominoes
|
|
10
|
+
- Real-time score
|
|
11
|
+
- Next piece preview
|
|
12
|
+
|
|
13
|
+
### Platform Support
|
|
14
|
+
Based on Python's [`curses`](https://docs.python.org/3/library/curses.html) module:
|
|
15
|
+
- ✅ **Linux/macOS**: Works out of the box
|
|
16
|
+
- ⚠️ **Windows**: Not supported yet
|
|
17
|
+
|
|
18
|
+
### Installation & Usage
|
|
19
|
+
- Using [uv](https://github.com/astral-sh/uv) (recommended):
|
|
20
|
+
```bash
|
|
21
|
+
uv pip install -e .
|
|
22
|
+
pytetris
|
|
23
|
+
```
|
|
24
|
+
- Using pip (alternative):
|
|
25
|
+
```bash
|
|
26
|
+
pip install -e .
|
|
27
|
+
pytetris
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Controls
|
|
31
|
+
| Key | Action |
|
|
32
|
+
|-----------|-----------------|
|
|
33
|
+
| `a` | Move left |
|
|
34
|
+
| `d` | Move right |
|
|
35
|
+
| `w` | Rotate piece |
|
|
36
|
+
| `s` | Hard drop |
|
|
37
|
+
| `q` | Quit game |
|
|
38
|
+
|
|
39
|
+
### License
|
|
40
|
+
MIT License - see [LICENSE](LICENSE) for details.
|
|
41
|
+
|
|
42
|
+
### Acknowledgements
|
|
37
43
|
Game logic adapted from [tinytetris](https://github.com/taylorconor/tinytetris) (a C implementation).
|
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
[build-system]
|
|
2
|
-
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
-
build-backend = "setuptools.build_meta"
|
|
4
|
-
|
|
5
|
-
[project]
|
|
6
|
-
name = "tetris-terminal"
|
|
7
|
-
version = "0.0.1"
|
|
8
|
-
description = "A tetris game runs in the terminal"
|
|
9
|
-
readme = "README.md"
|
|
10
|
-
requires-python = ">=3.8"
|
|
11
|
-
license = { file = "MIT" }
|
|
12
|
-
|
|
13
|
-
authors = [{ name = "jayzhu", email = "jay.l.zhu@foxmail.com" }]
|
|
14
|
-
|
|
15
|
-
dependencies = [
|
|
16
|
-
|
|
17
|
-
classifiers = [
|
|
18
|
-
"Development Status :: 3 - Alpha",
|
|
19
|
-
"Environment :: Console :: Curses",
|
|
20
|
-
"Intended Audience :: End Users/Desktop",
|
|
21
|
-
"License :: OSI Approved :: MIT License",
|
|
22
|
-
"Operating System :: POSIX :: Linux",
|
|
23
|
-
"Operating System :: MacOS :: MacOS X",
|
|
24
|
-
"Operating System :: Microsoft :: Windows", # curses 在 Windows 需额外处理
|
|
25
|
-
"Programming Language :: Python :: 3",
|
|
26
|
-
"Programming Language :: Python :: 3.8",
|
|
27
|
-
"Programming Language :: Python :: 3.9",
|
|
28
|
-
"Programming Language :: Python :: 3.10",
|
|
29
|
-
"Programming Language :: Python :: 3.11",
|
|
30
|
-
"Programming Language :: Python :: 3.12",
|
|
31
|
-
"Programming Language :: Python :: 3.13",
|
|
32
|
-
"Topic :: Games/Entertainment :: Puzzle Games",
|
|
33
|
-
"Topic :: Terminals",
|
|
34
|
-
]
|
|
35
|
-
|
|
36
|
-
[project.urls]
|
|
37
|
-
homepage = "https://github.com/zlh124/pytetris"
|
|
38
|
-
|
|
39
|
-
[project.scripts]
|
|
40
|
-
tetris = "tetris.cli:main"
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
[tool.setuptools]
|
|
44
|
-
package-dir = { "" = "src" }
|
|
45
|
-
|
|
46
|
-
[tool.setuptools.packages.find]
|
|
47
|
-
where = ["src"]
|
|
48
|
-
|
|
49
|
-
[tool.setuptools.exclude-package-data]
|
|
50
|
-
"*" = ["*.md"]
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "tetris-terminal"
|
|
7
|
+
version = "0.0.1-alpha1"
|
|
8
|
+
description = "A tetris game runs in the terminal"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.8"
|
|
11
|
+
license = { file = "MIT" }
|
|
12
|
+
|
|
13
|
+
authors = [{ name = "jayzhu", email = "jay.l.zhu@foxmail.com" }]
|
|
14
|
+
|
|
15
|
+
dependencies = []
|
|
16
|
+
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Development Status :: 3 - Alpha",
|
|
19
|
+
"Environment :: Console :: Curses",
|
|
20
|
+
"Intended Audience :: End Users/Desktop",
|
|
21
|
+
"License :: OSI Approved :: MIT License",
|
|
22
|
+
"Operating System :: POSIX :: Linux",
|
|
23
|
+
"Operating System :: MacOS :: MacOS X",
|
|
24
|
+
"Operating System :: Microsoft :: Windows", # curses 在 Windows 需额外处理
|
|
25
|
+
"Programming Language :: Python :: 3",
|
|
26
|
+
"Programming Language :: Python :: 3.8",
|
|
27
|
+
"Programming Language :: Python :: 3.9",
|
|
28
|
+
"Programming Language :: Python :: 3.10",
|
|
29
|
+
"Programming Language :: Python :: 3.11",
|
|
30
|
+
"Programming Language :: Python :: 3.12",
|
|
31
|
+
"Programming Language :: Python :: 3.13",
|
|
32
|
+
"Topic :: Games/Entertainment :: Puzzle Games",
|
|
33
|
+
"Topic :: Terminals",
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
[project.urls]
|
|
37
|
+
homepage = "https://github.com/zlh124/pytetris"
|
|
38
|
+
|
|
39
|
+
[project.scripts]
|
|
40
|
+
tetris = "tetris.cli:main"
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
[tool.setuptools]
|
|
44
|
+
package-dir = { "" = "src" }
|
|
45
|
+
|
|
46
|
+
[tool.setuptools.packages.find]
|
|
47
|
+
where = ["src"]
|
|
48
|
+
|
|
49
|
+
[tool.setuptools.exclude-package-data]
|
|
50
|
+
"*" = ["*.md"]
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[egg_info]
|
|
2
|
-
tag_build =
|
|
3
|
-
tag_date = 0
|
|
4
|
-
|
|
1
|
+
[egg_info]
|
|
2
|
+
tag_build =
|
|
3
|
+
tag_date = 0
|
|
4
|
+
|
|
File without changes
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import curses
|
|
2
|
-
import sys
|
|
3
|
-
|
|
4
|
-
from tetris import Tetris
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
def wrapper(stdscr: curses.window):
|
|
8
|
-
tetris = Tetris(stdscr)
|
|
9
|
-
tetris.main()
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
def main() -> int:
|
|
13
|
-
curses.wrapper(wrapper)
|
|
14
|
-
return 0
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if __name__ == "__main__":
|
|
18
|
-
sys.exit(main())
|
|
1
|
+
import curses
|
|
2
|
+
import sys
|
|
3
|
+
|
|
4
|
+
from .tetris import Tetris
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def wrapper(stdscr: curses.window):
|
|
8
|
+
tetris = Tetris(stdscr)
|
|
9
|
+
tetris.main()
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def main() -> int:
|
|
13
|
+
curses.wrapper(wrapper)
|
|
14
|
+
return 0
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
if __name__ == "__main__":
|
|
18
|
+
sys.exit(main())
|
|
@@ -1,203 +1,199 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
import
|
|
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
|
-
def
|
|
56
|
-
self.
|
|
57
|
-
|
|
58
|
-
def
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
def
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
def
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
for i in range(
|
|
114
|
-
self.
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
self.
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
self.
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
self.y
|
|
139
|
-
|
|
140
|
-
self.
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
self.x
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
self.
|
|
177
|
-
self.
|
|
178
|
-
self.
|
|
179
|
-
|
|
180
|
-
self.
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
self.
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
self.stdscr.timeout(0)
|
|
202
|
-
self.stdscr.box()
|
|
203
|
-
self.runloop()
|
|
1
|
+
#!/usr/bin/python3
|
|
2
|
+
import curses
|
|
3
|
+
import time
|
|
4
|
+
|
|
5
|
+
from collections import deque
|
|
6
|
+
from copy import copy
|
|
7
|
+
from random import randint, shuffle
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Tetris:
|
|
11
|
+
x = 431424
|
|
12
|
+
y = 598356
|
|
13
|
+
r = 427089
|
|
14
|
+
c = 348480
|
|
15
|
+
p = 615696
|
|
16
|
+
|
|
17
|
+
px = 247872
|
|
18
|
+
py = 799248
|
|
19
|
+
pr = 0
|
|
20
|
+
|
|
21
|
+
tick = 0
|
|
22
|
+
|
|
23
|
+
board = [[0] * 10 for _ in range(20)]
|
|
24
|
+
|
|
25
|
+
piece_chars = ["Z", "S", "O", "J", "T", "I", "L"]
|
|
26
|
+
|
|
27
|
+
block = [
|
|
28
|
+
[x, y, x, y],
|
|
29
|
+
[r, p, r, p],
|
|
30
|
+
[c, c, c, c],
|
|
31
|
+
[599636, 431376, 598336, 432192],
|
|
32
|
+
[411985, 610832, 415808, 595540],
|
|
33
|
+
[px, py, px, py],
|
|
34
|
+
[614928, 399424, 615744, 428369],
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
def __init__(self, stdscr: curses.window):
|
|
38
|
+
self.stdscr = stdscr
|
|
39
|
+
|
|
40
|
+
queue = deque(maxlen=14)
|
|
41
|
+
|
|
42
|
+
score = 0
|
|
43
|
+
lock_until = 0
|
|
44
|
+
|
|
45
|
+
def now_ms(self) -> int:
|
|
46
|
+
return int(time.time() * 1000)
|
|
47
|
+
|
|
48
|
+
def reset_lock_delay(self) -> None:
|
|
49
|
+
self.lock_until = 0
|
|
50
|
+
|
|
51
|
+
def start_lock_delay(self) -> None:
|
|
52
|
+
if not self.lock_until:
|
|
53
|
+
self.lock_until = self.now_ms() + 500
|
|
54
|
+
|
|
55
|
+
def NUM(self, x: int, y: int) -> int:
|
|
56
|
+
return 3 & self.block[self.p][x] >> y
|
|
57
|
+
|
|
58
|
+
def fill_bag(self) -> None:
|
|
59
|
+
bag = list(range(7))
|
|
60
|
+
shuffle(bag)
|
|
61
|
+
while bag:
|
|
62
|
+
self.queue.append(bag.pop())
|
|
63
|
+
|
|
64
|
+
def init_queue(self) -> None:
|
|
65
|
+
self.fill_bag()
|
|
66
|
+
self.fill_bag()
|
|
67
|
+
|
|
68
|
+
def next_from_queue(self) -> int:
|
|
69
|
+
if len(self.queue) == 7:
|
|
70
|
+
self.fill_bag()
|
|
71
|
+
return self.queue.popleft()
|
|
72
|
+
|
|
73
|
+
def new_piece(self) -> None:
|
|
74
|
+
self.y = self.py = 0
|
|
75
|
+
self.p = self.next_from_queue()
|
|
76
|
+
self.r = self.pr = randint(0, 3)
|
|
77
|
+
self.x = self.px = randint(0, 9 - self.NUM(self.r, 16))
|
|
78
|
+
self.reset_lock_delay()
|
|
79
|
+
|
|
80
|
+
def frame(self, stdscr: curses.window) -> None:
|
|
81
|
+
stdscr.move(0, 3)
|
|
82
|
+
stdscr.addstr("Next: ")
|
|
83
|
+
for i in range(5):
|
|
84
|
+
stdscr.addstr(f"{self.piece_chars[self.queue[i]]} ")
|
|
85
|
+
|
|
86
|
+
for i in range(20):
|
|
87
|
+
stdscr.move(i + 1, 1)
|
|
88
|
+
for j in range(10):
|
|
89
|
+
if self.board[i][j]:
|
|
90
|
+
stdscr.attron(262176 | self.board[i][j] << 8)
|
|
91
|
+
stdscr.addstr(" ")
|
|
92
|
+
stdscr.attroff(262176 | self.board[i][j] << 8)
|
|
93
|
+
stdscr.move(21, 1)
|
|
94
|
+
stdscr.addstr(f"Score: {self.score}")
|
|
95
|
+
stdscr.refresh()
|
|
96
|
+
|
|
97
|
+
def set_piece(self, x: int, y: int, r: int, v: int) -> None:
|
|
98
|
+
for i in range(0, 8, 2):
|
|
99
|
+
self.board[self.NUM(r, i * 2) + y][self.NUM(r, (i * 2) + 2) + x] = v
|
|
100
|
+
|
|
101
|
+
def update_piece(self) -> None:
|
|
102
|
+
self.set_piece(self.px, self.py, self.pr, 0)
|
|
103
|
+
self.px, self.py, self.pr = self.x, self.y, self.r
|
|
104
|
+
self.set_piece(self.x, self.y, self.r, self.p + 1)
|
|
105
|
+
|
|
106
|
+
def remove_line(self) -> None:
|
|
107
|
+
for row in range(self.y, self.y + self.NUM(self.r, 18) + 1):
|
|
108
|
+
self.c = 1
|
|
109
|
+
for i in range(10):
|
|
110
|
+
self.c *= self.board[row][i]
|
|
111
|
+
if not self.c:
|
|
112
|
+
continue
|
|
113
|
+
for i in range(row - 1, 0, -1):
|
|
114
|
+
self.board[i + 1] = copy(self.board[i])
|
|
115
|
+
self.board[0] = [0] * 10
|
|
116
|
+
self.score += 1
|
|
117
|
+
|
|
118
|
+
def check_hit(self, x: int, y: int, r: int) -> int:
|
|
119
|
+
if y + self.NUM(r, 18) > 19:
|
|
120
|
+
return 1
|
|
121
|
+
self.set_piece(self.px, self.py, self.pr, 0)
|
|
122
|
+
self.c = 0
|
|
123
|
+
for i in range(0, 8, 2):
|
|
124
|
+
if self.board[y + self.NUM(r, i * 2)][x + self.NUM(r, (i * 2) + 2)]:
|
|
125
|
+
self.c += 1
|
|
126
|
+
self.set_piece(self.px, self.py, self.pr, self.p + 1)
|
|
127
|
+
return self.c
|
|
128
|
+
|
|
129
|
+
def do_tick(self) -> int:
|
|
130
|
+
self.tick += 1
|
|
131
|
+
if self.tick > 30:
|
|
132
|
+
self.tick = 0
|
|
133
|
+
if not self.check_hit(self.x, self.y + 1, self.r):
|
|
134
|
+
self.y += 1
|
|
135
|
+
self.update_piece()
|
|
136
|
+
self.reset_lock_delay()
|
|
137
|
+
else:
|
|
138
|
+
if not self.y:
|
|
139
|
+
return 0
|
|
140
|
+
self.start_lock_delay()
|
|
141
|
+
if self.now_ms() >= self.lock_until:
|
|
142
|
+
self.remove_line()
|
|
143
|
+
self.new_piece()
|
|
144
|
+
if self.lock_until and self.now_ms() >= self.lock_until:
|
|
145
|
+
if self.check_hit(self.x, self.y + 1, self.r):
|
|
146
|
+
self.remove_line()
|
|
147
|
+
self.new_piece()
|
|
148
|
+
else:
|
|
149
|
+
self.reset_lock_delay()
|
|
150
|
+
return 1
|
|
151
|
+
|
|
152
|
+
def runloop(self) -> None:
|
|
153
|
+
while self.do_tick():
|
|
154
|
+
time.sleep(0.01)
|
|
155
|
+
c = self.stdscr.getch()
|
|
156
|
+
if (
|
|
157
|
+
c == ord("a")
|
|
158
|
+
and self.x > 0
|
|
159
|
+
and not self.check_hit(self.x - 1, self.y, self.r)
|
|
160
|
+
):
|
|
161
|
+
self.x -= 1
|
|
162
|
+
if (
|
|
163
|
+
c == ord("d")
|
|
164
|
+
and self.x + self.NUM(self.r, 16) < 9
|
|
165
|
+
and not self.check_hit(self.x + 1, self.y, self.r)
|
|
166
|
+
):
|
|
167
|
+
self.x += 1
|
|
168
|
+
if c == ord("s"):
|
|
169
|
+
while not self.check_hit(self.x, self.y + 1, self.r):
|
|
170
|
+
self.y += 1
|
|
171
|
+
self.update_piece()
|
|
172
|
+
self.reset_lock_delay()
|
|
173
|
+
self.remove_line()
|
|
174
|
+
self.new_piece()
|
|
175
|
+
if c == ord("w"):
|
|
176
|
+
self.r += 1
|
|
177
|
+
self.r %= 4
|
|
178
|
+
while self.x + self.NUM(self.r, 16) > 9:
|
|
179
|
+
self.x -= 1
|
|
180
|
+
if self.check_hit(self.x, self.y, self.r):
|
|
181
|
+
self.x = self.px
|
|
182
|
+
self.r = self.pr
|
|
183
|
+
if c == ord("q"):
|
|
184
|
+
return
|
|
185
|
+
self.update_piece()
|
|
186
|
+
self.frame(self.stdscr)
|
|
187
|
+
|
|
188
|
+
def main(self) -> None:
|
|
189
|
+
curses.start_color()
|
|
190
|
+
self.init_queue()
|
|
191
|
+
for i in range(1, 8):
|
|
192
|
+
curses.init_pair(i, i, 0)
|
|
193
|
+
self.new_piece()
|
|
194
|
+
curses.resizeterm(22, 22)
|
|
195
|
+
curses.noecho()
|
|
196
|
+
curses.curs_set(0)
|
|
197
|
+
self.stdscr.timeout(0)
|
|
198
|
+
self.stdscr.box()
|
|
199
|
+
self.runloop()
|
|
@@ -1,65 +1,70 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: tetris-terminal
|
|
3
|
-
Version: 0.0.
|
|
4
|
-
Summary: A tetris game runs in the terminal
|
|
5
|
-
Author-email: jayzhu <jay.l.zhu@foxmail.com>
|
|
6
|
-
Project-URL: homepage, https://github.com/zlh124/pytetris
|
|
7
|
-
Classifier: Development Status :: 3 - Alpha
|
|
8
|
-
Classifier: Environment :: Console :: Curses
|
|
9
|
-
Classifier: Intended Audience :: End Users/Desktop
|
|
10
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
-
Classifier: Operating System :: POSIX :: Linux
|
|
12
|
-
Classifier: Operating System :: MacOS :: MacOS X
|
|
13
|
-
Classifier: Operating System :: Microsoft :: Windows
|
|
14
|
-
Classifier: Programming Language :: Python :: 3
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
-
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
-
Classifier: Topic :: Games/Entertainment :: Puzzle Games
|
|
22
|
-
Classifier: Topic :: Terminals
|
|
23
|
-
Requires-Python: >=3.8
|
|
24
|
-
Description-Content-Type: text/markdown
|
|
25
|
-
License-File: LICENSE
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
[
|
|
29
|
+
# Pytetris 🎮
|
|
30
|
+
A terminal-based Tetris game written in Python using the `curses` library.
|
|
31
|
+
|
|
32
|
+
[](LICENSE)
|
|
33
|
+
[]()
|
|
34
|
+
|
|
35
|
+
### Features
|
|
36
|
+
- Classic Tetris gameplay with 7 standard tetrominoes
|
|
37
|
+
- Real-time score
|
|
38
|
+
- Next piece preview
|
|
39
|
+
|
|
40
|
+
### Platform Support
|
|
41
|
+
Based on Python's [`curses`](https://docs.python.org/3/library/curses.html) module:
|
|
42
|
+
- ✅ **Linux/macOS**: Works out of the box
|
|
43
|
+
- ⚠️ **Windows**: Not supported yet
|
|
44
|
+
|
|
45
|
+
### Installation & Usage
|
|
46
|
+
- Using [uv](https://github.com/astral-sh/uv) (recommended):
|
|
47
|
+
```bash
|
|
48
|
+
uv pip install -e .
|
|
49
|
+
pytetris
|
|
50
|
+
```
|
|
51
|
+
- Using pip (alternative):
|
|
52
|
+
```bash
|
|
53
|
+
pip install -e .
|
|
54
|
+
pytetris
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Controls
|
|
58
|
+
| Key | Action |
|
|
59
|
+
|-----------|-----------------|
|
|
60
|
+
| `a` | Move left |
|
|
61
|
+
| `d` | Move right |
|
|
62
|
+
| `w` | Rotate piece |
|
|
63
|
+
| `s` | Hard drop |
|
|
64
|
+
| `q` | Quit game |
|
|
65
|
+
|
|
66
|
+
### License
|
|
67
|
+
MIT License - see [LICENSE](LICENSE) for details.
|
|
68
|
+
|
|
69
|
+
### Acknowledgements
|
|
70
|
+
Game logic adapted from [tinytetris](https://github.com/taylorconor/tinytetris) (a C implementation).
|
|
@@ -8,5 +8,4 @@ src/tetris_terminal.egg-info/PKG-INFO
|
|
|
8
8
|
src/tetris_terminal.egg-info/SOURCES.txt
|
|
9
9
|
src/tetris_terminal.egg-info/dependency_links.txt
|
|
10
10
|
src/tetris_terminal.egg-info/entry_points.txt
|
|
11
|
-
src/tetris_terminal.egg-info/requires.txt
|
|
12
11
|
src/tetris_terminal.egg-info/top_level.txt
|
{tetris_terminal-0.0.1 → tetris_terminal-0.0.1a1}/src/tetris_terminal.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
{tetris_terminal-0.0.1 → tetris_terminal-0.0.1a1}/src/tetris_terminal.egg-info/entry_points.txt
RENAMED
|
File without changes
|
{tetris_terminal-0.0.1 → tetris_terminal-0.0.1a1}/src/tetris_terminal.egg-info/top_level.txt
RENAMED
|
File without changes
|