/****************************************************************************** * FILE: tetris_brick.cc * Definition of the class Tetris_brick. * * Author: Dana Vrajitoru, IUSB * Class: C481 B581 Computer Graphics ******************************************************************************/ #include #include "tetris_brick.h" // Constructor with a given shape and orientation. Tetris_brick::Tetris_brick(Brick_type the_shape, int the_orientation) { Set_brick(the_shape, the_orientation); } // Default constructor that generates a random brick. Tetris_brick::Tetris_brick() { Set_brick(); } // Copy constructor Tetris_brick::Tetris_brick(const Tetris_brick &data) { Set_brick(data); } // Destructor: nothing to do. Tetris_brick::~Tetris_brick() {;} // Reinitialize the brick with the shape and orientation. void Tetris_brick::Set_brick(Brick_type the_shape, int the_orientation) { orientation = the_orientation; shape = the_shape; Set_initial_pos(); Reset_bricks(); switch (shape) { case long_shape: // vertical bar for (int i=0; i max) max = bricks[i][which]; return max; } // Checks if the brick fits in the table at the given position. int Tetris_brick::Check_position(Table_type table, int x, int y) { for (int i=0; i= T_WIDTH || y+bricks[i][1] >= T_HEIGHT) return 0; else if (table[x+bricks[i][0]][y+bricks[i][1]] != space_cell) return 0; return 1; } // Checks if the brick fits in the table at the given position. int Tetris_brick::Check_position(Table_type table) { for (int i=0; i= T_WIDTH || pos_y+bricks[i][1] >= T_HEIGHT) return 0; else if (table[pos_x+bricks[i][0]][pos_y+bricks[i][1]] != space_cell) return 0; return 1; } // Moves the brick down by 1 position if possible. Returns 1 or 0 to // say if the movement was possible or not. int Tetris_brick::Move_down(Table_type table) { if (Check_position(table, pos_x, pos_y+1)) { pos_y++; return 1; } else return 0; } // Moves the brick down by 1 position if possible. Returns 1 or 0 to // say if the movement was possible or not. int Tetris_brick::Move_left(Table_type table) { if (Check_position(table, pos_x-1, pos_y)) { pos_x--; return 1; } else return 0; } // Moves the brick down by 1 position if possible. Returns 1 or 0 to // say if the movement was possible or not. int Tetris_brick::Move_right(Table_type table) { if (Check_position(table, pos_x+1, pos_y)) { pos_x++; return 1; } else return 0; } // Write the brick to the table. int Tetris_brick::Write_brick(Table_type table) { for (int i=0; i