Why?
Why rewrite something similar to Tetris after it's been written for more platforms than I could ever count? Because my instructor told me to, which sounds like as good a reason as any to over-engineer something.
The assignment
The assignment was to write the game for the Win32 console using the basic functionality of C++. No fancy libs, no bounce, no GUI... Just the good old 80x25 terminal and fundamentals outlined by our textbook.
The process according to me
If we're using the vanilla 80x25 console, and we're not using any special libraries...
Why shouldn't it work on several platforms?
OverEngineering Requirement #1: Multiplatform
Linux consoles are stream devices. As stream devices, it turns out that it's pretty annoying to achieve things like... non-blocking I/O from the keyboard. As a result, my little knock-off game works under Wine, but waits endlessly for input under the Linux console.... Bringing us to OER#2.
OverEngineering Requirement #2: Include essential functions from Curses
Curses is a great library that's been ported to more platforms than Games Like Tetris. In fact, at this point, it would probably be best to nab a copy of pdcurses for Win32 and use that for the Win32 console port. But the code is already written, and it's a pain to copy around libraries. For now, we'll just stick to the vanilla win32 console app.
The extended functions of Curses include some really interesting console effects, like overlapping windows. Additionally, Curses only updates parts of the console that have been changed. Anyone that remembers checking their email with Pine or uses Pico/Nano/Joe/Emacs/etc has used Curses before.
Now the project can display characters and receive controls. So far so good.
Uh oh... Curses only updates specific parts of the screen that have been updated, which means if I write the next location of the piece, the old position stays there...
OverEngineering Requirement #3: Buffer this thing
Ok... This part may be a little silly...
Create one array for the "bucket" (the place where the Tetris-like-pieces go) and any committed pieces (that is, pieces that have "landed" on another piece or the "floor"). Draw the "bucket" and any committed pieces here. Fill "empties" with space so that Curses redraws it.
Create another array for the "bucket", committed pieces and any moving pieces.
During each game update before anything is drawn to the screen, copy the bucket into the screen buffer. Add moving pieces to the screen buffer. Draw the screen buffer to the screen.
Now it displays pretty well and receives controls, but wow... is it hideous...
Linux Version in gnome
Windows Version under WINE in gnome
OverEngineering Requirement #4: GUI
Clearly, textmode Tetris-like-game-thing is not happy times...
So what can we use to make it multiplatform and GUI.... Even better, what can we use to make a consistent, write-once GUI? GTK+!
Here's a preview of the Similar To but Must Not Be Called Tetris in GTK+
Linux GTK+ Version in gnome

{blog entries}