Tetris game in c++

For my intro to c++ programming class final project we need to code a game of tetris in c++ using MS visual c++ express 2008 and Dark GDK.

I have started the code and am running into a few problems.

Right now I am getting this error(s):
1
2
3
4
5
6
7
8
1
1>Compiling...
1>Main.cpp
1>Linking...
1>Main.obj : error LNK2019: unresolved external symbol "public: __thiscall Shape::Shape(void)" (??0Shape@@QAE@XZ) referenced in function "public: __thiscall I_Shape::I_Shape(int,int)" (??0I_Shape@@QAE@HH@Z)
1>Debug\Dark GDK - tetris.exe : fatal error LNK1120: 1 unresolved externals
1>Build log was saved at "file://h:\ SCHOOL\ Spring 2012\COMSC-048\tetris code\tetris\Dark GDK - tetris\Dark GDK - tetris\Debug\BuildLog.htm"
1>Dark GDK - tetris - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



Here is the current version of my tetris code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//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(int, int, DWORD);
	void draw();
	void move(int, int);
	void clear();

};

//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::move(int dx, int dy)
{
	x=x+dx;
	y=y+dy;
	draw();
}
//End Method (Block)

class Shape {

private:
	Block blocks[4];
public:
	Shape(void);
	void move_shape(int,int);
	void clear_shape();
	void draw_shape();
};


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;
}

// the main entry point for the application is this function
void DarkGDK ( void )
{
	// turn on sync rate and set maximum rate to 1 fps
	dbSyncOn   ( );
	dbSyncRate ( 1 );

	// our main loop
	while ( LoopGDK ( ) )
	{
		// update the screen
		dbSync ( );
	}

	// return back to windows
	return;
}



How can I fix this? What should I do? I would greatly appecratie any help and/or advise.

Thanks,
shywolf91
closed account (DSLq5Di1)
1>Main.obj : error LNK2019: unresolved external symbol "public: __thiscall Shape::Shape(void)" (??0Shape@@QAE@XZ)
             referenced in function "public: __thiscall I_Shape::I_Shape(int,int)" (??0I_Shape@@QAE@HH@Z)

This line, although a little cryptic, tells you what the error is and where to find it.

Line 88, the I_Shape constructor is initializing it's base class with the call to Shape(). Line 72, Shape() has been declared, but not defined (given a body) anywhere in your code.

move_shape(), clear_shape(), draw_shape() are also undefined, you'll probably wish to declare them virtual as well if you intend to override the base class.
I updated the code and now i'm getting 16 errors which are located here: http://pastebin.com/5WFT56Rq

Here is the updated code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
//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;
}


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 and I think this is the start to all of the errors.

I really need help making the I_Shape.

Thanks,
The first two lines of your errors:

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'

Note it gives a line number: 87. We go to line 87 in your code and see that, just like the error messages say, make_shape is missing a return type.

Maybe you should actually read the error messages, go to the line of code referenced, and see what you can do to correct it. If the error is not on the line of code referenced, it is probably immediately above it. Recompile after you correct the first few errors -- subsequent error messages are often a result of the first.
Last edited on
I've updated the code:

I get these 3 errors:
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(89) : 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(89) : 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(101) : 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(152) : 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 - 3 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Here is the new code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
//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:
	int pos[8];
	DWORD color;
    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,0);

	//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 really need to get the I_Shape completed and printed on the board.
Last edited on
All you need to do is add the return type (as already mentioned) on lines 89, 100, and 141. Line 152 probably should be move_shape.
Last edited on
This makes the shape, but it is not making it 'blue'

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
//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:
	int pos[8];
	DWORD color;
    Shape();
	void 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);
}
void 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()
{
//make_shape(pos[8],color);
	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();
}

// 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,0);

	//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;
}
Topic archived. No new replies allowed.