Thread: Proplem with TETRIS game in C++

  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    26

    Proplem with TETRIS game in C++

    My intro to c++ class is making a tetris game for a project.

    My code can be found here: [C++] TETRIS C++ -ERRORS- - Pastebin.com

    or here:
    Code:
    //Dark GDK - The Game Creators - www.thegamecreators.com
    
    //the wizard has created a very simple project that uses Dark GDK
    //it contains the basic code for a GDK application
    
    //whenever using Dark GDK you must ensure you include the header file
    #include "DarkGDK.h"
    
    
    //Global
    int Block_Size=20;
    const DWORD Red = dbRGB(255,0,0);
    const DWORD Green = dbRGB(0,255,0);
    const DWORD Blue = dbRGB(0,0,255);
    const DWORD Magenta = dbRGB(255,0,255);
    const DWORD Black = dbRGB(0,0,0);
    const DWORD White = dbRGB(255,255,255);
    const DWORD Yellow = dbRGB(255,255,0);
    const DWORD Cyan = dbRGB(0,255,255);
    const DWORD Orange = dbRGB(255,165,0);
    //end global
    
    //Classes
    
    class Block {
    private:
        int x,y;
        DWORD color;
    public:
        Block();
        Block(int, int, DWORD);
        void draw();
        void move(int, int);
      void clear();
    
    };
    Block::Block(){
    x = 0;
    y =0;
    color = White;
    }
    //Methods (Block)
    
    Block::Block(int X, int Y, DWORD COLOR)
    {
        x=X;
        y=Y;
        color=COLOR;
    }
    
    void Block::draw()
    {
        int x1, y1, x2, y2;
        x1=x*Block_Size;
        y1=y*Block_Size;
        x2=x1+Block_Size;
        y2=y1+Block_Size;
    
    //    dbInk(color, Black);
        dbBox(x1,y1,x2,y2);
    }
    
    void Block::clear()
    {
    
        dbInk(Black, Black);
        //dbBox(x1,y1,x2,y2);
        draw();
    }
    
    void Block::move(int dx, int dy)
    {
        x=x+dx;
        y=y+dy;
        dbInk(color, Black);
        draw();
    }
    //End Method (Block)
    
    class Shape {
    
    private:
        Block blocks[4];
        int pos[8];
    public:
        Shape();
        make_shape();
        void move_shape(int,int);
        void draw_shape();
    };
    //Methods (Shape)
    Shape::Shape() {
    blocks[0] = Block(0,0, Red);
    blocks[1] = Block(0,0, Red);
    blocks[2] = Block(0,0, Red);
    blocks[3] = Block(0,0, Red);
    }
    Shape::make_shape()
    {
        blocks[0] = Block(pos[0],pos[1],color);
        blocks[1] = Block(pos[2],pos[3],color);
        blocks[2] = Block(pos[4],pos[5],color);
        blocks[3] = Block(pos[6],pos[7],color);
    }
    
    void Shape::draw_shape()
    {
        for (int i=0; i<4; i++)
        {
            blocks[i].draw();
        }
    }
    
    void Shape::move_shape(int dx, int dy)
    {
        for (int i=0; i<4; i++)
        {
            blocks[i].clear();
        }
        for (int i=0; i<4; i++)
        {
            blocks[i].move(dx,dy);
        }
    }
    
    
    class I_Shape: public Shape{
    public:
        I_Shape(int,int);
        
    private:
        DWORD color;
        //int pos[8];
    };
    
    //Methods (I_Shape)
    
    
    I_Shape::I_Shape(int x, int y):Shape()
    {
        color=Blue;
        pos[0]=x-1;
        pos[1]=y;
        pos[2]=x;
        pos[3]=y;
        pos[4]=x+1;
        pos[5]=y;
        pos[6]=x+2;
        pos[7]=y;
        make_shape(pos,color);
    }
    
    // the main entry point for the application is this function
    void DarkGDK ( void )
    {
        //Block NewBlock(0,0,Red);
        I_Shape First(5,3);
        // turn on sync rate and set maximum rate to 1 fps
        dbSyncOn   ( );
        dbSyncRate ( 1 );
        First.draw_shape();
        First.move_shape(5,5);
    
        //NewBlock.draw();
        //    NewBlock.move(2,2);
        // our main loop
        while ( LoopGDK ( ) )
        {
            First.move_shape(0,1);
    
            
            // update the screen
            dbSync ( );
        }
    
        // return back to windows
        return;
    }

    I am getting these errors:
    Code:
    1>------ Build started: Project: Dark GDK - tetris, Configuration: Debug Win32 ------
    1>Compiling...
    1>Main.cpp
    1>h:\ school\ spring 2012\comsc-048\tetris code\tetris code\tetris code\tetris\dark gdk - tetris\dark gdk - tetris\main.cpp(87) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    1>h:\ school\ spring 2012\comsc-048\tetris code\tetris code\tetris code\tetris\dark gdk - tetris\dark gdk - tetris\main.cpp(87) : warning C4183: 'make_shape': missing return type; assumed to be a member function returning 'int'
    1>h:\ school\ spring 2012\comsc-048\tetris code\tetris code\tetris code\tetris\dark gdk - tetris\dark gdk - tetris\main.cpp(99) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    1>h:\ school\ spring 2012\comsc-048\tetris code\tetris code\tetris code\tetris\dark gdk - tetris\dark gdk - tetris\main.cpp(100) : error C2065: 'color' : undeclared identifier
    1>h:\ school\ spring 2012\comsc-048\tetris code\tetris code\tetris code\tetris\dark gdk - tetris\dark gdk - tetris\main.cpp(101) : error C2065: 'color' : undeclared identifier
    1>h:\ school\ spring 2012\comsc-048\tetris code\tetris code\tetris code\tetris\dark gdk - tetris\dark gdk - tetris\main.cpp(102) : error C2065: 'color' : undeclared identifier
    1>h:\ school\ spring 2012\comsc-048\tetris code\tetris code\tetris code\tetris\dark gdk - tetris\dark gdk - tetris\main.cpp(103) : error C2065: 'color' : undeclared identifier
    1>h:\ school\ spring 2012\comsc-048\tetris code\tetris code\tetris code\tetris\dark gdk - tetris\dark gdk - tetris\main.cpp(142) : error C2248: 'Shape::pos' : cannot access private member declared in class 'Shape'
    1>        h:\ school\ spring 2012\comsc-048\tetris code\tetris code\tetris code\tetris\dark gdk - tetris\dark gdk - tetris\main.cpp(84) : see declaration of 'Shape::pos'
    1>        h:\ school\ spring 2012\comsc-048\tetris code\tetris code\tetris code\tetris\dark gdk - tetris\dark gdk - tetris\main.cpp(80) : see declaration of 'Shape'
    1>h:\ school\ spring 2012\comsc-048\tetris code\tetris code\tetris code\tetris\dark gdk - tetris\dark gdk - tetris\main.cpp(143) : error C2248: 'Shape::pos' : cannot access private member declared in class 'Shape'
    1>        h:\ school\ spring 2012\comsc-048\tetris code\tetris code\tetris code\tetris\dark gdk - tetris\dark gdk - tetris\main.cpp(84) : see declaration of 'Shape::pos'
    1>        h:\ school\ spring 2012\comsc-048\tetris code\tetris code\tetris code\tetris\dark gdk - tetris\dark gdk - tetris\main.cpp(80) : see declaration of 'Shape'
    1>h:\ school\ spring 2012\comsc-048\tetris code\tetris code\tetris code\tetris\dark gdk - tetris\dark gdk - tetris\main.cpp(144) : error C2248: 'Shape::pos' : cannot access private member declared in class 'Shape'
    1>        h:\ school\ spring 2012\comsc-048\tetris code\tetris code\tetris code\tetris\dark gdk - tetris\dark gdk - tetris\main.cpp(84) : see declaration of 'Shape::pos'
    1>        h:\ school\ spring 2012\comsc-048\tetris code\tetris code\tetris code\tetris\dark gdk - tetris\dark gdk - tetris\main.cpp(80) : see declaration of 'Shape'
    1>h:\ school\ spring 2012\comsc-048\tetris code\tetris code\tetris code\tetris\dark gdk - tetris\dark gdk - tetris\main.cpp(145) : error C2248: 'Shape::pos' : cannot access private member declared in class 'Shape'
    1>        h:\ school\ spring 2012\comsc-048\tetris code\tetris code\tetris code\tetris\dark gdk - tetris\dark gdk - tetris\main.cpp(84) : see declaration of 'Shape::pos'
    1>        h:\ school\ spring 2012\comsc-048\tetris code\tetris code\tetris code\tetris\dark gdk - tetris\dark gdk - tetris\main.cpp(80) : see declaration of 'Shape'
    1>h:\ school\ spring 2012\comsc-048\tetris code\tetris code\tetris code\tetris\dark gdk - tetris\dark gdk - tetris\main.cpp(146) : error C2248: 'Shape::pos' : cannot access private member declared in class 'Shape'
    1>        h:\ school\ spring 2012\comsc-048\tetris code\tetris code\tetris code\tetris\dark gdk - tetris\dark gdk - tetris\main.cpp(84) : see declaration of 'Shape::pos'
    1>        h:\ school\ spring 2012\comsc-048\tetris code\tetris code\tetris code\tetris\dark gdk - tetris\dark gdk - tetris\main.cpp(80) : see declaration of 'Shape'
    1>h:\ school\ spring 2012\comsc-048\tetris code\tetris code\tetris code\tetris\dark gdk - tetris\dark gdk - tetris\main.cpp(147) : error C2248: 'Shape::pos' : cannot access private member declared in class 'Shape'
    1>        h:\ school\ spring 2012\comsc-048\tetris code\tetris code\tetris code\tetris\dark gdk - tetris\dark gdk - tetris\main.cpp(84) : see declaration of 'Shape::pos'
    1>        h:\ school\ spring 2012\comsc-048\tetris code\tetris code\tetris code\tetris\dark gdk - tetris\dark gdk - tetris\main.cpp(80) : see declaration of 'Shape'
    1>h:\ school\ spring 2012\comsc-048\tetris code\tetris code\tetris code\tetris\dark gdk - tetris\dark gdk - tetris\main.cpp(148) : error C2248: 'Shape::pos' : cannot access private member declared in class 'Shape'
    1>        h:\ school\ spring 2012\comsc-048\tetris code\tetris code\tetris code\tetris\dark gdk - tetris\dark gdk - tetris\main.cpp(84) : see declaration of 'Shape::pos'
    1>        h:\ school\ spring 2012\comsc-048\tetris code\tetris code\tetris code\tetris\dark gdk - tetris\dark gdk - tetris\main.cpp(80) : see declaration of 'Shape'
    1>h:\ school\ spring 2012\comsc-048\tetris code\tetris code\tetris code\tetris\dark gdk - tetris\dark gdk - tetris\main.cpp(149) : error C2248: 'Shape::pos' : cannot access private member declared in class 'Shape'
    1>        h:\ school\ spring 2012\comsc-048\tetris code\tetris code\tetris code\tetris\dark gdk - tetris\dark gdk - tetris\main.cpp(84) : see declaration of 'Shape::pos'
    1>        h:\ school\ spring 2012\comsc-048\tetris code\tetris code\tetris code\tetris\dark gdk - tetris\dark gdk - tetris\main.cpp(80) : see declaration of 'Shape'
    1>h:\ school\ spring 2012\comsc-048\tetris code\tetris code\tetris code\tetris\dark gdk - tetris\dark gdk - tetris\main.cpp(150) : error C2248: 'Shape::pos' : cannot access private member declared in class 'Shape'
    1>        h:\ school\ spring 2012\comsc-048\tetris code\tetris code\tetris code\tetris\dark gdk - tetris\dark gdk - tetris\main.cpp(84) : see declaration of 'Shape::pos'
    1>        h:\ school\ spring 2012\comsc-048\tetris code\tetris code\tetris code\tetris\dark gdk - tetris\dark gdk - tetris\main.cpp(80) : see declaration of 'Shape'
    1>h:\ school\ spring 2012\comsc-048\tetris code\tetris code\tetris code\tetris\dark gdk - tetris\dark gdk - tetris\main.cpp(150) : error C2660: 'Shape::make_shape' : function does not take 2 arguments
    1>Build log was saved at "file://h:\ SCHOOL\ Spring 2012\COMSC-048\tetris code\tetris code\tetris code\tetris\Dark GDK - tetris\Dark GDK - tetris\Debug\BuildLog.htm"
    1>Dark GDK - tetris - 16 error(s), 1 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    For this project we are using DarkGDK and MS visual c++ express 2008.

    I am currently having trouble making the I_Shape (i.e combining the '4' blocks into the 'I_Shape')

    These classes are what teacher told us to use.

    Also my teacher said to put the
    Code:
    int pos[8];
    into the shape class, not the I_Shape class.

    What can I do?




    Thanks,
    Dylan

  2. #2
    Registered User
    Join Date
    May 2012
    Posts
    71
    Thats lot of errors, use Unit testing for decreasing headaches and such wall of errors, will help you alot. When i debug my prog's by hand i do such tests and i just google them one by one, easly and organized.

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Solve errors one at a time, starting from the top.
    For the first error, what difference do you notice between lines 87 and 89?
    Next error, play spot the difference between lines 98 and 106.
    ...
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem with tetris game...
    By Sokay in forum C Programming
    Replies: 4
    Last Post: 10-11-2009, 03:16 AM
  2. Tetris game
    By Da-Nuka in forum Game Programming
    Replies: 1
    Last Post: 01-16-2005, 09:27 AM
  3. Try my Tetris game - last version
    By PJYelton in forum Game Programming
    Replies: 5
    Last Post: 06-29-2003, 09:32 AM
  4. My tetris game 2.0
    By PJYelton in forum Game Programming
    Replies: 12
    Last Post: 04-25-2003, 03:40 AM
  5. tetris game
    By mrt in forum Game Programming
    Replies: 2
    Last Post: 04-08-2002, 10:01 AM

Tags for this Thread