├── README.md
├── LICENSE
└── tiny-tetris.py
/README.md:
--------------------------------------------------------------------------------
1 | # Tiny Tetris
2 |
3 | ## About
4 |
5 | A Tetris implementation that "fits on a business card"
6 |
7 | Dimensions: 20 lines x 80 characters
8 |
9 |
10 |
11 | ## Rules and Limitations
12 |
13 | - No encoding
14 | - Only standard library and curses allowed
15 |
16 | ## Play It!
17 |
18 | ```bash
19 | git clone https://github.com/nickmpaz/tiny-tetris && cd tiny-tetris && python3 tiny-tetris.py
20 | ```
21 | **Note**: If you are using Windows, you most likely need to install `windows-curses` for compatibility:
22 | ```bash
23 | pip install windows-curses
24 | ```
25 | ## Controls
26 |
27 | - up: rotate
28 | - left: move left
29 | - right: move right
30 | - down: move down
31 | - ctrl+c: quit
32 |
33 | ## Acknowledgements
34 |
35 | Inspired by TinySki https://github.com/KilledByAPixel/TinySki
36 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Nicholas Paz
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/tiny-tetris.py:
--------------------------------------------------------------------------------
1 | from random import*;import time,sys;import curses as h;w=h.initscr();h.noecho() #
2 | P,Q,m,s,e,p,a,q=20,10,5,300,{0:"· ",1:"██"},[[[1,1]]*2,[[0,1,0],[1]*3,[0]*3],[[1#
3 | ,0,0],[1]*3,[0]*3],[[0,0,1],[1]*3,[0]*3],[[1,1,0],[0,1,1],[0]*3],[[0,1,1],[1,1,0#
4 | ],[0]*3],[[0]*4,[1]*4,[0]*4,[0]*4]],range,len;M,b=p[randint(0,6)],[[0]*Q for r #
5 | in a(P)];h.cbreak();y,R,C,cr,l,d,n=lambda z,x,y:e[z[x][y]],0,4,0,1,s,p[randint(0#
6 | ,6)];w.nodelay(1);w.keypad(1);h.curs_set(0);A,B,sw=list,zip,{'U':'if not k(R,C'+#
7 | ',A(B(*M[::-1]))):M=A(B(*M[::-1]))','D':'V();R+=1','L':'if not k(R,C-1,M):C-=1',#
8 | 'R':'if not k(R,C+1,M):C+=1'};exec(('def k(R,C,se):\n for(r,c)in[(r,c)for c in '#
9 | 'a(q(M))for r in a(q(M))]:\n if se[r][c]>0 and(not(0<=R+r
0):return 1\ndef V():\n global R,C,M,n,l,d\n if(k(R+1,C,M)and R<1 an'# 11 | 'd sys.exit())or k(R+1,C,M):\n for(r,c)in[(r,c)for c in a(q(M))for r in a(q(M)'# 12 | ')]:\n if R+r in a(P)and C+c in a(Q)and M[r][c]>0:b[R+r][C+c]=M[r][c]\n M,n,'# 13 | 'R,C,d=n,p[randint(0,6)],-1,4,s+m-l*m\n for i in[j for j in a(P)if sum(b[j])>9'# 14 | ']:b[1:i+1]=b[:i];b[0],l=[0]*Q,l+1\ntry:\n while 1:\n o,z=a(q(n)),a(q(M));u=[('# 15 | 'r,c)for c in z for r in z];time.sleep(.001)\n for(r,c)in[(r,c)for c in a(Q)fo'# 16 | 'r r in a(P)]:`(r,c*q(e),y(b,r,c))\n for(r,c)in[(r,c)for(r,c)in u if M[r][c]>0'# 17 | ']:`(R+r,(C+c)*2,y(M,r,c))\n for(r,c)in[(r,c)for c in o for r in o]:`(r,22+c*2'# 18 | ',y(n,r,c)+"· · ")\n try:cr=(cr+1)%d;ch=w.getkey();exec(sw[ch[4:5]]);raise\n '# 19 | 'except:exec("if cr<1:V();R+=1");`(P,0,"level "+str(l))\nexcept:h.echo();w.keyp'# 20 | 'ad(0);h.nocbreak();h.endwin();print("level "+str(l))').replace('`','w.addstr'))# --------------------------------------------------------------------------------