Code Monkey home page Code Monkey logo

super-template-tetris's Introduction

Super Template Tetris

Implementation of Tetris as a C++ template metaprogram. All game logic is implemented at compile time. The runtime program is only needed to print out the game world and serialize it for next play.

Post discussing implementation.

Playing

Plays one step of the game every time the game is recompiled.

Start a new game:

$ ./reset.sh

Use compiler flags to control input:

$ clang++ main.cpp -std=c++1z -Wno-gnu-string-literal-operator-template -D COMMAND -o tetris ; ./tetris

Valid commands are:

  • LEFT - Move piece left by one.
  • RIGHT - Move piece right by one.
  • LROT - Rotate piece left (counter clockwise).
  • RROT - Rotate piece right (clockwise).
  • HARD - Hard drop the current piece. This drops the piece all the way down and places it.
  • SOFT - Drop the piece all the way down but don't place it.
  • DOWN - Move the piece down by 4.
  • NONE / anything else - Do nothing, advance game by one.

Pieces will continue to fall for all commands. Movement takes place before the piece is moved down. Pieces have a one step delay before being auto placed (that is, when a piece collides with a block, it but will only be placed on the next step if no further movement is performed).

Compiling

  • -std=c++1z since the program uses a few C++17 features.
  • -Wgnu-string-literal-operator-template is used for generating compile time strings.

Example

A few screenshots:

Initial game

Clearing a row

Clearing 3 rows

Game over

super-template-tetris's People

Contributors

mattbierner avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.