tetris-terminal 0.0.1__tar.gz → 0.0.1a2__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.
@@ -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,63 @@
1
- Metadata-Version: 2.4
2
- Name: tetris-terminal
3
- Version: 0.0.1
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
- Requires-Dist: windows-curses; sys_platform == "win32"
27
- Dynamic: license-file
28
-
29
- ![gameplay](./gameplay.gif)
30
- # Tetris Terminal🎮
31
- A terminal-based Tetris game written in Python using the `curses` library.
32
-
33
- [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
34
- [![Python 3.8+](https://img.shields.io/badge/Python-3.8%2B-blue)]()
35
-
36
- ### Features
37
- - Classic Tetris gameplay with 7 standard tetrominoes
38
- - Real-time score
39
- - Next piece preview
40
-
41
- ### Platform Support
42
- Based on Python's [`curses`](https://docs.python.org/3/library/curses.html) module:
43
- - **Linux/macOS**: Works out of the box
44
- - ✅️ **Windows**: With [`windows-curses`](https://github.com/zephyrproject-rtos/windows-curses)
45
-
46
- ### Installation & Usage
47
- ```bash
48
- pip install tetris-terminal
49
- tetris
50
- ```
51
-
52
- ### Controls
53
- | Key | Action |
54
- |-----------|-----------------|
55
- | `a` | Move left |
56
- | `d` | Move right |
57
- | `w` | Rotate piece |
58
- | `s` | Hard drop |
59
- | `q` | Quit game |
60
-
61
- ### License
62
- MIT License - see [LICENSE](LICENSE) for details.
63
-
64
- ### Acknowledgements
65
- Game logic adapted from [tinytetris](https://github.com/taylorconor/tinytetris) (a C implementation).
1
+ Metadata-Version: 2.4
2
+ Name: tetris-terminal
3
+ Version: 0.0.1a2
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
+ Dynamic: license-file
27
+
28
+ ![gameplay](./gameplay.gif)
29
+ # Tetris Terminal🎮
30
+ A terminal-based Tetris game written in Python using the `curses` library.
31
+
32
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
33
+ [![Python 3.8+](https://img.shields.io/badge/Python-3.8%2B-blue)]()
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
+ ```bash
47
+ pip install tetris-terminal
48
+ ```
49
+
50
+ ### Controls
51
+ | Key | Action |
52
+ |-----------|-----------------|
53
+ | `a` | Move left |
54
+ | `d` | Move right |
55
+ | `w` | Rotate piece |
56
+ | `s` | Hard drop |
57
+ | `q` | Quit game |
58
+
59
+ ### License
60
+ MIT License - see [LICENSE](LICENSE) for details.
61
+
62
+ ### Acknowledgements
63
+ Game logic adapted from [tinytetris](https://github.com/taylorconor/tinytetris) (a C implementation).
@@ -1,37 +1,36 @@
1
- ![gameplay](./gameplay.gif)
2
- # Tetris Terminal🎮
3
- A terminal-based Tetris game written in Python using the `curses` library.
4
-
5
- [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
6
- [![Python 3.8+](https://img.shields.io/badge/Python-3.8%2B-blue)]()
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**: With [`windows-curses`](https://github.com/zephyrproject-rtos/windows-curses)
17
-
18
- ### Installation & Usage
19
- ```bash
20
- pip install tetris-terminal
21
- tetris
22
- ```
23
-
24
- ### Controls
25
- | Key | Action |
26
- |-----------|-----------------|
27
- | `a` | Move left |
28
- | `d` | Move right |
29
- | `w` | Rotate piece |
30
- | `s` | Hard drop |
31
- | `q` | Quit game |
32
-
33
- ### License
34
- MIT License - see [LICENSE](LICENSE) for details.
35
-
36
- ### Acknowledgements
1
+ ![gameplay](./gameplay.gif)
2
+ # Tetris Terminal🎮
3
+ A terminal-based Tetris game written in Python using the `curses` library.
4
+
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
6
+ [![Python 3.8+](https://img.shields.io/badge/Python-3.8%2B-blue)]()
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
+ ```bash
20
+ pip install tetris-terminal
21
+ ```
22
+
23
+ ### Controls
24
+ | Key | Action |
25
+ |-----------|-----------------|
26
+ | `a` | Move left |
27
+ | `d` | Move right |
28
+ | `w` | Rotate piece |
29
+ | `s` | Hard drop |
30
+ | `q` | Quit game |
31
+
32
+ ### License
33
+ MIT License - see [LICENSE](LICENSE) for details.
34
+
35
+ ### Acknowledgements
37
36
  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 = ["windows-curses; sys_platform == 'win32'"]
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-alpha2"
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
- tetris class definition and main game logic
3
- """
4
-
5
- import curses
6
- import time
7
-
8
- from collections import deque
9
- from copy import copy
10
- from random import randint, shuffle
11
-
12
-
13
- class Tetris:
14
- """
15
- main game class
16
- """
17
-
18
- x = 431424
19
- y = 598356
20
- r = 427089
21
- c = 348480
22
- p = 615696
23
-
24
- px = 247872
25
- py = 799248
26
- pr = 0
27
-
28
- tick = 0
29
-
30
- board = [[0] * 10 for _ in range(20)]
31
-
32
- piece_chars = ["Z", "S", "O", "J", "T", "I", "L"]
33
-
34
- block = [
35
- [x, y, x, y],
36
- [r, p, r, p],
37
- [c, c, c, c],
38
- [599636, 431376, 598336, 432192],
39
- [411985, 610832, 415808, 595540],
40
- [px, py, px, py],
41
- [614928, 399424, 615744, 428369],
42
- ]
43
-
44
- def __init__(self, stdscr: curses.window):
45
- self.stdscr = stdscr
46
-
47
- queue = deque(maxlen=14)
48
-
49
- score = 0
50
- lock_until = 0
51
-
52
- def now_ms(self) -> int:
53
- return int(time.time() * 1000)
54
-
55
- def reset_lock_delay(self) -> None:
56
- self.lock_until = 0
57
-
58
- def start_lock_delay(self) -> None:
59
- if not self.lock_until:
60
- self.lock_until = self.now_ms() + 500
61
-
62
- def NUM(self, x: int, y: int) -> int:
63
- return 3 & self.block[self.p][x] >> y
64
-
65
- def fill_bag(self) -> None:
66
- bag = list(range(7))
67
- shuffle(bag)
68
- while bag:
69
- self.queue.append(bag.pop())
70
-
71
- def init_queue(self) -> None:
72
- self.fill_bag()
73
- self.fill_bag()
74
-
75
- def next_from_queue(self) -> int:
76
- if len(self.queue) == 7:
77
- self.fill_bag()
78
- return self.queue.popleft()
79
-
80
- def new_piece(self) -> None:
81
- self.y = self.py = 0
82
- self.p = self.next_from_queue()
83
- self.r = self.pr = randint(0, 3)
84
- self.x = self.px = randint(0, 9 - self.NUM(self.r, 16))
85
- self.reset_lock_delay()
86
-
87
- def frame(self, stdscr: curses.window) -> None:
88
- stdscr.move(0, 3)
89
- stdscr.addstr("Next: ")
90
- for i in range(5):
91
- stdscr.addstr(f"{self.piece_chars[self.queue[i]]} ")
92
-
93
- for i in range(20):
94
- stdscr.move(i + 1, 1)
95
- for j in range(10):
96
- stdscr.addstr(" ", curses.color_pair(self.board[i][j]))
97
- stdscr.move(21, 1)
98
- stdscr.addstr(f"Score: {self.score}")
99
- stdscr.refresh()
100
-
101
- def set_piece(self, x: int, y: int, r: int, v: int) -> None:
102
- for i in range(0, 8, 2):
103
- self.board[self.NUM(r, i * 2) + y][self.NUM(r, (i * 2) + 2) + x] = v
104
-
105
- def update_piece(self) -> None:
106
- self.set_piece(self.px, self.py, self.pr, 0)
107
- self.px, self.py, self.pr = self.x, self.y, self.r
108
- self.set_piece(self.x, self.y, self.r, self.p + 1)
109
-
110
- def remove_line(self) -> None:
111
- for row in range(self.y, self.y + self.NUM(self.r, 18) + 1):
112
- self.c = 1
113
- for i in range(10):
114
- self.c *= self.board[row][i]
115
- if not self.c:
116
- continue
117
- for i in range(row - 1, 0, -1):
118
- self.board[i + 1] = copy(self.board[i])
119
- self.board[0] = [0] * 10
120
- self.score += 1
121
-
122
- def check_hit(self, x: int, y: int, r: int) -> int:
123
- if y + self.NUM(r, 18) > 19:
124
- return 1
125
- self.set_piece(self.px, self.py, self.pr, 0)
126
- self.c = 0
127
- for i in range(0, 8, 2):
128
- if self.board[y + self.NUM(r, i * 2)][x + self.NUM(r, (i * 2) + 2)]:
129
- self.c += 1
130
- self.set_piece(self.px, self.py, self.pr, self.p + 1)
131
- return self.c
132
-
133
- def do_tick(self) -> int:
134
- self.tick += 1
135
- if self.tick > 30:
136
- self.tick = 0
137
- if not self.check_hit(self.x, self.y + 1, self.r):
138
- self.y += 1
139
- self.update_piece()
140
- self.reset_lock_delay()
141
- else:
142
- if not self.y:
143
- return 0
144
- self.start_lock_delay()
145
- if self.now_ms() >= self.lock_until:
146
- self.remove_line()
147
- self.new_piece()
148
- if self.lock_until and self.now_ms() >= self.lock_until:
149
- if self.check_hit(self.x, self.y + 1, self.r):
150
- self.remove_line()
151
- self.new_piece()
152
- else:
153
- self.reset_lock_delay()
154
- return 1
155
-
156
- def runloop(self) -> None:
157
- while self.do_tick():
158
- time.sleep(0.01)
159
- c = self.stdscr.getch()
160
- if (
161
- c == ord("a")
162
- and self.x > 0
163
- and not self.check_hit(self.x - 1, self.y, self.r)
164
- ):
165
- self.x -= 1
166
- if (
167
- c == ord("d")
168
- and self.x + self.NUM(self.r, 16) < 9
169
- and not self.check_hit(self.x + 1, self.y, self.r)
170
- ):
171
- self.x += 1
172
- if c == ord("s"):
173
- while not self.check_hit(self.x, self.y + 1, self.r):
174
- self.y += 1
175
- self.update_piece()
176
- self.reset_lock_delay()
177
- self.remove_line()
178
- self.new_piece()
179
- if c == ord("w"):
180
- self.r += 1
181
- self.r %= 4
182
- while self.x + self.NUM(self.r, 16) > 9:
183
- self.x -= 1
184
- if self.check_hit(self.x, self.y, self.r):
185
- self.x = self.px
186
- self.r = self.pr
187
- if c == ord("q"):
188
- return
189
- self.update_piece()
190
- self.frame(self.stdscr)
191
-
192
- def main(self) -> None:
193
- self.init_queue()
194
- for i in range(1, 8):
195
- curses.init_pair(i, i, i)
196
- self.new_piece()
197
-
198
- curses.resize_term(22, 22)
199
- curses.curs_set(0)
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,63 @@
1
- Metadata-Version: 2.4
2
- Name: tetris-terminal
3
- Version: 0.0.1
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
- Requires-Dist: windows-curses; sys_platform == "win32"
27
- Dynamic: license-file
28
-
29
- ![gameplay](./gameplay.gif)
30
- # Tetris Terminal🎮
31
- A terminal-based Tetris game written in Python using the `curses` library.
32
-
33
- [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
34
- [![Python 3.8+](https://img.shields.io/badge/Python-3.8%2B-blue)]()
35
-
36
- ### Features
37
- - Classic Tetris gameplay with 7 standard tetrominoes
38
- - Real-time score
39
- - Next piece preview
40
-
41
- ### Platform Support
42
- Based on Python's [`curses`](https://docs.python.org/3/library/curses.html) module:
43
- - **Linux/macOS**: Works out of the box
44
- - ✅️ **Windows**: With [`windows-curses`](https://github.com/zephyrproject-rtos/windows-curses)
45
-
46
- ### Installation & Usage
47
- ```bash
48
- pip install tetris-terminal
49
- tetris
50
- ```
51
-
52
- ### Controls
53
- | Key | Action |
54
- |-----------|-----------------|
55
- | `a` | Move left |
56
- | `d` | Move right |
57
- | `w` | Rotate piece |
58
- | `s` | Hard drop |
59
- | `q` | Quit game |
60
-
61
- ### License
62
- MIT License - see [LICENSE](LICENSE) for details.
63
-
64
- ### Acknowledgements
65
- Game logic adapted from [tinytetris](https://github.com/taylorconor/tinytetris) (a C implementation).
1
+ Metadata-Version: 2.4
2
+ Name: tetris-terminal
3
+ Version: 0.0.1a2
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
+ Dynamic: license-file
27
+
28
+ ![gameplay](./gameplay.gif)
29
+ # Tetris Terminal🎮
30
+ A terminal-based Tetris game written in Python using the `curses` library.
31
+
32
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
33
+ [![Python 3.8+](https://img.shields.io/badge/Python-3.8%2B-blue)]()
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
+ ```bash
47
+ pip install tetris-terminal
48
+ ```
49
+
50
+ ### Controls
51
+ | Key | Action |
52
+ |-----------|-----------------|
53
+ | `a` | Move left |
54
+ | `d` | Move right |
55
+ | `w` | Rotate piece |
56
+ | `s` | Hard drop |
57
+ | `q` | Quit game |
58
+
59
+ ### License
60
+ MIT License - see [LICENSE](LICENSE) for details.
61
+
62
+ ### Acknowledgements
63
+ 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
@@ -1,3 +0,0 @@
1
- from .tetris import Tetris
2
-
3
- __all__ = ["Tetris"]
@@ -1,3 +0,0 @@
1
-
2
- [:sys_platform == "win32"]
3
- windows-curses