Starting from:
$30

$24

CS 203 - Object-Oriented Programming Assignment 2

Objectives:




To practice types, objects, classes, graphics in JAVA






Remember the Tetris Game




Tetris is a game where players need to match falling tetrominos. A tetromino is a structure consisting of four connected squares. Fig. 1 displays all seven possible tetromino shapes. An active tetrominos can be rotated counterclockwise in 90 degrees steps. Rotating a tetromino four times yields the original shape. You can get more information about Tetris game from here







Homework Instructions




We will implement a Java program that randomly chooses a tetromino shape, a random color, and a random location within the frame, and displays it on the screen.

  










































































Figure 1: The seven tetrominos: they can be also named by the letter they resemble. The figure shows I (light blue), J (dark blue), O (yellow), L (orange), T (purple), S (green), Z (red).







Your Java program should randomly choose a tetromino shape, a random color for this shape, and a random location within the frame, and displays it on the screen. Then, the program can terminate after a while or wait until the user closes the window.

 Create a TetrisViewer class



Create a TetrisComponent (should include a method paintComponent and a method setTetromino(/* shape, color */).
In the TetrisViewer class, randomly choose a tetromino and its color (use java.util.Random). Set this information in the TetrisComponent.
Hint: You will use RGB color system, so you can create three random integers between 0-255 to create a random color.

Display the frame and component (in a random location (random x and y coordinate point)). ** You will be displaying one random tetromino only (do not bother to create more objects in one run)



** We are not developing the whole game, so you should not worry about creating multiple different objects and fitting them on the screen… or other specifications of the Tetris game. Our goal is to create one random object only.




**Hint: You will use the Rectangle component and locate for square together to create different tetrominos.




If any of the problem statements is unclear, use the Canvas discussion board to ask for clarifications.

More products