Skip to content

Cross-platform ASCII-compatible terminal-based single-player stop-action game about falling bricks

License

Notifications You must be signed in to change notification settings

kyberdrb/Tetris

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tetris

Quick start

  1. Build the binary

    /usr/bin/cmake --build /home/laptop/git/kyberdrb/Tetris/cmake-build-debug --target Tetris -j 1
  2. Run the game

    • on Linux

      ./Tetris
    • on Windows

      ./Tetris.exe

Design

  1. ConstructionSite (stavenisko - hracia plocha)

  2. BuildingBlock / Polyomino

    • multiple Bricks/Monominos together in various shapes

    • abstract class/interface - Component

    • Brick / Monomino

      • single brick - tehlička - polyomino consisting of a single brick; the Leaf class in Composite design pattern)

    • Domino

      • Polyomino type of order 2

      • Composite specialization - two bricks glued together by their sides

      • Types:

        • Straight only

          #
          #
          ##
    • Tromino

      • Polyomino type of order 3

      • Composite specialization - three bricks glued together by their sides

      • Types:

        • Straight

          #
          #
          #
          ###
        • L

          #
          ##
          ##
          #
          ##
           #
           #
          ##
    • Tetromino

      • Polyomino type of order 4

      • Composite specialization - four bricks glued together by their sides

      • Types:

        • Straight

          #
          #
          #
          #
          ####
        • Square

          ##
          ##
        • L

          #
          #
          ##
          ###
          #
          ##
           #
           #
            #
          ###
        • T

          ###
           #
           #
          ##
           #
           #
          ###
          #
          ##
          #
        • S / skew

           ##
          ##
          #
          ##
           #
  3. Monomino has fallen to the bottom OR Monomino has fallen onto another Monomino (two bricks/monominos are on top of each other) - the (active/moving/falling) brick stops moving (deactivates/freezes) and next brick is created, appears and starts falling

    • Every Polyomino will have the ability to rotate itself (clockwise/counterclockwise), flip horizontally - horizontal symmetry, flip vertically - vertical symmetry

Domino clockwise rotation

Basic rotation

Rotate domino by the pivot - the first monomino
f: first monomino - the pivot
s: second monomino

Rotation/Orientation
0 -> 90 -> 180 -> 270
                   s
fs -> f -> sf  ->  f
      s

##            -> # (2, 4)
(2, 4) (2, 5)    # (3, 4)    second monomino: move down, move left

# (2, 4) -> ## (2, 4) (2, 5) second monomino: move right, move up
# (3, 4)

Full rotation

Recalculation of coordinates and their order for 'freeOrthogonalNeighboursForFirstMonomino'
Domino: lookAroundFirstMonomino()
    Domino full coords:  under, left,  above,   right
| fs | (0, 2), (0, 3): (1, 2), (0, 1), (-1, 2), (0, 3)
|    |                                 ^^^^^^
|    |                                 removed because row index is out of bounds
|    |
``````

Domino: rotateClockwise()
    Domino full coords: 1st clockwise option from current position for second monomino; 2nd rotation position for second monomino; 3rd rotation position; current position of Monomino
| fs | (0, 2), (0, 3): (1, 2), (0, 1), (0, 3)
|    |                 ^^^^^^
|    |                 next clockwise rotation coordinate are applied for second monomino and moved to the end
|    |
``````
Domino: rotateClockwise()
| f  | (0, 2), (1, 2): (0, 1), (0, 3), (1, 2)
| s  |                 ^^^^^^
|    |                 next clockwise rotation coordinate are applied for second monomino and moved to the end
|    |
``````
Domino: rotateClockwise()
|sf  | (0, 2), (0, 1): (0, 3), (1, 2), (0, 1)
|    |                 ^^^^^^
|    |                 next clockwise rotation coordinate are applied for second monomino and moved to the end
|    |
``````
Domino: rotateClockwise()
| fs | (0, 2), (0, 3): (1, 2), (0, 1), (0, 3)
|    |
|    |
|    |
``````
Domino: moveLeft()
    Domino: lookAroundFirstMonomino()
    Domino full coords:  under, left,  above,   right
      (0, 1), (0, 2):  (1, 1), (0, 0), (-1, 1), (0, 2)
                               ^^^^^^   ^^^^^< removed; row index out of bounds
                               removed: playing field boundary / non-blank sign

      freeOrthogonalNeighbours: (1, 1), (0, 2)

|fs  | (0, 1), (0, 2): (1, 1), (0, 2)
|    |                 ^^^^^^
|    |                 next clockwise rotation coordinate are applied for second monomino and moved to the end
|    |
``````

Domino: rotateClockwise()
|f   | (0, 1), (1, 1): (0, 2), (1, 1)
|s   |                 ^^^^^^
|    |                 next clockwise rotation coordinate are applied for second monomino and moved to the end
|    |
``````

Domino: rotateClockwise()
|fs  | (0, 1), (0, 2): (1, 1), (0, 2)
|    |
|    |
|    |
``````

Domino: moveDown()
    Domino: lookAroundFirstMonomino()
    Domino full coords:  under, left,  above,   right
      (1, 1), (1, 2):  (2, 1), (1, 0), (0, 1), (1, 2)
                               ^^^^^^
                               removed: playing field boundary / non-blank sign

      freeOrthogonalNeighbours: (2, 1), (0, 1), (1, 2) - maybe some adjustment is needed

|    |
|fs  | (1, 1), (1, 2): (2, 1), (0, 1), (1, 2)
|    |                 ^^^^^^
|    |                 next clockwise rotation coordinate are applied for second monomino and moved to the end
``````

Domino: rotateClockwise()

|    |
|f   | (1, 1), (2, 1): (0, 1), (1, 2), (2, 1)
|s   |                 ^^^^^^
|    |                 next clockwise rotation coordinate are applied for second monomino and moved to the end
``````

Domino: rotateClockwise()

|s   |
|f   | (1, 1), (0, 1): (1, 2), (2, 1), (0, 1)
|    |                 ^^^^^^
|    |                 next clockwise rotation coordinate are applied for second monomino and moved to the end
``````

Domino: rotateClockwise()

|    |
|fs  | (1, 1), (1, 2): (2, 1), (0, 1), (1, 2)
|    |                 ^^^^^^
|    |                 next clockwise rotation coordinate are applied for second monomino and moved to the end
``````

Domino: moveRight()
    Domino: lookAroundFirstMonomino()
    Domino full coords:  under, left,  above,   right
      (1, 2), (1, 3):  (2, 2), (1, 1), (0, 2), (1, 3)

      freeOrthogonalNeighbours: (2, 2), (1, 1), (0, 2), (1, 3)

|    |
| fs | (1, 2), (1, 3): (2, 2), (1, 1), (0, 2), (1, 3)
|    |                 ^^^^^^
|    |                 next clockwise rotation coordinate are applied for second monomino and moved to the end
``````

Domino: rotateClockwise()

|    |
| f  | (1, 2), (2, 2): (1, 1), (0, 2), (1, 3), (2, 2)
| s  |                 ^^^^^^
|    |                 next clockwise rotation coordinate are applied for second monomino and moved to the end
``````

Domino: moveRight()
    Domino: lookAroundFirstMonomino()
    Domino full coords:  under, left,  above,   right
      (1, 3), (2, 3):  (2, 3), (1, 1), (0, 3), (1, 4)

      freeOrthogonalNeighbours: (2, 3), (1, 1), (0, 3), (1, 4)

    Domino: adjust coordinate order for clockwise rotation by current Domino orientation
      current Domino orientation: 270 degrees
      freeOrthogonalNeighbours: (1, 1), (0, 3), (1, 4), (2, 3) - move front element to the back one time

|    |
|  f | (1, 3), (2, 3): (1, 1), (0, 3), (1, 4), (2, 3)
|  s |
|    |
``````

Commands for moving Tetris directory from one repo to a separate repo

for each commit related to Tetris directory
do

cp README.adoc /home/laptop/git/kyberdrb/Tetris
cp CMakeLists.txt /home/laptop/git/kyberdrb/Tetris
cp --recursive src/ /home/laptop/git/kyberdrb/Tetris/
cp --recursive tests/ /home/laptop/git/kyberdrb/Tetris/
git log | tac

git checkout

---

git status && date

date && git status && echo "" && git diff && date

SPACE
isBrickActive -> isActiveBrickActive

git add --all
git commit -m "some commit message"
git push

TODOs

  • clockwise rotacia Domina

    • urobit clockwise otacanie vo vsetkych dostupnych smeroch; nedostupne smery preskocit/vymazat: - OK

    • zoznam suradnic pre vsetky ortogonalne pozicie dostat do ConstructionSite z Domina cez navratovu hodnotu ako temporary vector - OK

    • rozdelit skenovanie (a este neimplementovany order adjustment) pre adjacentNeighbours v Domine, KTORE bude skenovane po posunuti/vytvoreni Domina, OD clockwise rotacie Domina a rotacie suradnic - OK

    • zoznam dostupnych suradnic pre rotaciu bude ulozeny ako atribut v Domine, a bude sa aktualizovať (zmaze sa a znova sa naplni aktualnymi suradnicami) po každom pohybe a po vytvorení (alebo skor zviditelneni?) z ContstructionSite podla toho, ci nejake frozen monomino nestoji v ceste, resp ci je pozicia na cielovych suradniciach volna (BLANK); suradnicu, ktora je obsadena frozen Dominom, preskocit/ignorovat; zoznam bude vzdy obsahovať aspon sucasnu poziciu Domina (na zaciatku ako posledny prvok); zoznam bude ulozeny ako deque; po kazdej rotacii sa zoznam suradnic zrotuje, t.j. prva suradnica sa presunie na koniec - OK

    • po implememtacii clockwise rotacie upravit v ConstructionSite boundary checky pre pohyb Domina vlavo/vpravo/dole, lebo logika pre pohyb sa spolieha na predpoklad ze pri horizontalnom Domine su monomina v poradi - OK

    • pred commitom: precistit kod, otestovat vsetky rotacie, pphyb a blokacie o ine Domino alebo playing field boundary pri rotovanom domine - OK

  • Tetris: to be implemented

    • counterclockwise rotation

    • horizontal flip

    • vertical flip

Sources

About

Cross-platform ASCII-compatible terminal-based single-player stop-action game about falling bricks

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published