/Tetris

Primary LanguageJava

TETRIS

A simple game where we apply what we learnt in class to practice the concept of OOP.

In this project, we use the Apache Net Bean IDE thanks to its beginner friendly GUI design.

To do list

  • Create the board game
  • Draw block on the board
  • Add block color
  • Make the block fall down
  • Spawn new block
  • Moving, rotating block on key press
  • Clear complete rows and add score

Requirements

  • Java
  • Java Swing

Board game

First, we create the game board by using JPanel, then we divided it into smaller cells base on the formula below.

image

Drawing Block

After creating the board, now we need to draw the shape(tetrominoes) inside it. There are 7 tetrominoes in total, each of them will have different shape and color to distinguish.

image

Each tetrominoes will be stored in a 2d array with values 0, 1 where 1 is colored cell and otherwise.

image

The output is something similar like this

image

Make block fall down

With the block spawning at the middle top of game board, now we need to make them fall down by printing its postion after a fixed timestep and delete the previous one.

So the process is: print-wait-delete-print

image

Line removal

  • First we need to find the completed line
  • Remove it
  • Shift down the lines above