Settings

Theme

Show HN: A Terminal Tetris Game

github.com

52 points by adder46 5 years ago · 21 comments

Reader

herodotus 5 years ago

I successfully used Tetris to teach a first course in programming. What I did was provide a module I called "Gridworld". This provided a simple way for the students to create an N * N grid of cells where the cell size was fixed. The only other thing that could be done with Gridworld was to fill or clear the cells. After presenting Gridworld, I then asked the students how we might make an animation of a single square moving down the screen. This was in the very first class!

So instead of talking about semi-colons, syntax, types and so on, we thought about timing, animation, and how to make the animation uniform regardless of the speed of the computer.

After that, the students were given a series of staged assignments, finally ending up with the complete game by the end of the term.

adder46OP 5 years ago

I wanted to share my attempt at implementing the classic tetris game. It works in the terminal and uses the ncurses-rs bindings for the UI part. For me, the coolest part about it is that the tetrominos and their rotations are encoded as 16-bit unsigned integers. For example, to represent a square, we want 51! Why 51? Because 51 decimal is `0b0000000000110011`. We can make 4x4 Vec from that, and we get:

``` [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 1, 1], [0, 0, 1, 1]] ```

Notice how the 1s form a square?

As I'm still learning Rust, any suggestions regarding the architecture, overall design of the game, more idiomatic code, etc., are very welcome.

If you want to play or just see how it turned out, check out:

https://github.com/adder46/tetris.rs

  • PetitPrince 5 years ago

    Look up for tetrisconcept.net and theabsolute.plus discord ( https://discord.gg/6Gf2awJ ). Several people have made attempts to recreate sophisticated clones of Tetris, and the absolute plus leader board is written in rust.

  • whateveracct 5 years ago

    Does representing tetrominos that way make hit detection or anything like that easier? My gut says the only thing they add is slightly smaller memory usage, but maybe i'm missing some sort of elegant bit trick.

caterama 5 years ago

In no way detracting from your awesome toy project, intrigued people might also want to check out vitetris. Very similar tetris in the terminal with ncruses, but also supports network play! https://github.com/vicgeralds/vitetris

taviso 5 years ago

What is the greatest terminal game ever written?

I guess rogue, adom, nethack would be popular answers; probably the entire infocom catalog?

They're not really my cup of tea, the game I've enjoyed the most is probably asciiportal.

  • tyingq 5 years ago

    ascii-patrol is impressive. https://github.com/msokalski/ascii-patrol

  • anthk 5 years ago

    Hello Tavis. On global IF:

    Most Infocom games, plus Adventure.

    From IF archive (amateur games, but these are anything but amateur).

    Curses.

    Jigsaw.

    Anchorhead.

    Spider and Web.

    On roguelikes:

    Nethack/Slashem.

    Dungeon Crawl SS.

    Cataclysm DDA.

    Game pack: BSD games.

    4x strategy/tactics:

    VMS-Empire.

    Note that VMS-Empire has a Unix port since forever.

    Weird strategy/sim:

    Liberal Crime Squad.

  • Y_Y 5 years ago

    gcc

lucy_gatenby 5 years ago

I got this:

  thread 'main' panicked at 'index out of bounds: the len is 10 but the index is 18446744073709551615', src/core.rs:182:24
elkos 5 years ago

I have to admit that I have a soft-spot for the ncurses based bastet: a tetris clone that will give you the least useful tetrimo block.

gabrielsroka 5 years ago

Does it run on an Elektronika?

https://youtu.be/O0gAgQQHFcQ

  • eps 5 years ago

    Nice. Never seen the original before.

    The drop-and-slide of a square around 1:26 leaves behind some filled cells! I wonder if that's a bug or was it a part of the original gameplay.

nevezen 5 years ago

I miss playing.netris with other users SDF.org..

mulcahey 5 years ago

But doesn't emacs come with this built in? It's practically pre-installed on most of the unix machines I've used. I've even played it at the Apple Store.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection