Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

HunterLeorio

Need suggestion on making a tetris game using all oop

This topic is 5274 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

im new to C++ and want to make a tetris game for my project. I am sort of stuck right now and dont kno what to do from here on here are what i hav so far: these are mainly stuff in the .h file and im stuck here on think how to add graphic to the game(gameblock) because i cant use anything besides the CarnegieMellonGraphics Library can anyone help me.......... class Tetrisblock { // The move functions will be implemented in this base class void MoveDown(); void MoveRight(); void MoveLeft(); // The rotate functions will be implemented in the 7 derived classes virtual void RotateCW() = 0; virtual void RotateCCW() = 0; } struct POINT { int x; int y; } class Longblock : public Tetrisblock { void RotateCW(); void RotateCCW(); } class Squareblock : public Tetrisblock { void RotateCW(); void RotateCCW(); } class Zblock : public Tetrisblock { void RotateCW(); void RotateCCW(); } class Sblock : public Tetrisblock { void RotateCW(); void RotateCCW(); } class Lblock : public Tetrisblock { void RotateCW(); void RotateCCW(); } class Jblock : public Tetrisblock { void RotateCW(); void RotateCCW(); } class Tblock : public Tetrisblock { void RotateCW(); void RotateCCW(); } const int GAME_FIELD_HEIGHT = 20; const int GAME_FIELD_WIDTH = 10; class Tetrisstructure { private: BOOL m_GameField[GAME_FIELD_WIDTH][GAME_FIELD_HEIGHT]; void ClearLines(Tetrisblock* blockJustAdded); public: Tetrisstructure(); ~Tetrisstructure(); void AddBlockToStructure(TetrisBlock* blockToAdd); } // implementation Tetrisstructure::Tetrisstructure() { ::ZeroMemory(m_GameField, GAME_FIELD_HEIGHT*GAME_FIELD_WIDTH*sizeof(BOOL)); } class Longblock : public Tetrisblock { Longblock(); void RotateCW(); void RotateCCW(); } the following are for graphic (block) not really sure how to use it but hav a question on how to add my class to the the following #include <iostream> #include <math.h> #include "CarnegieMellonGraphics.h" // this illustrates a simple sprite animation. // The sprite images are cut from // a cutsheet of four frames. using namespace std; const long DT = 60; // measurable time increment const int GAME_FIELD_HEIGHT = 20; const int GAME_FIELD_WIDTH = 10; int main() { int i = 0; int x = 100; int y = 20; string title("Tetris"); Window test(640,480,title,false); Image img("block.jpg",Image::JPEG); // cutsheet Image subimg[] = { //array of sprite frames img.subImage(0,0,32,32)}; test.disableAutoPageFlip(); unsigned long time1, time2; time1 = WindowManager::getTime( ); int iimg=0; // image index while(true) { if(!test.isKeyboardQueueEmpty()) { KeyboardEvent event = test.getKeyboardEvent(); if(KeyboardEvent(NamedKey::ESCAPE) == event) { return 0; } } test.drawImage(subimg[iimg],x,y); time2 = WindowManager::getTime(); if ((time2 - time1) > DT) { iimg = ++iimg %1; time1 = time2; y += 5;; if (y <= 0) y = 10; int dx = 10; //dx += 5; //x -= dx; //if (x < 0) x = 10; //if (x > 420) x = 100; } test.flipPage(); test.drawRectangleFilled(Style::WHITE, 0, 0, test.getWidth(), test.getHeight()); test.drawText( Style(Color::GREEN), Font(Font::TIMES,24), 200, 450, string("Tetris") ); } return 0; } [edited by - HunterLeorio on June 7, 2004 1:30:03 PM]

Share this post


Link to post
Share on other sites
Advertisement
One thing I would like to point out is that if you added data to the teterisblock class you could eleminate the 7 sub classes.

Share this post


Link to post
Share on other sites
for my struct point, can i just put that in the tetrisblock class as protected?

protected:

int x;
int y;

i am doing that because i want the block to use a point in 10*20 grid so i can have 200 elements(little squares)

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!