Game Board (overloarding)

I think this is overloading a function but it's the part that confuses me the most.

I have a map that I want pieces to show up in and obviously needs to redraw each iteration.

I've read my book (no examples) and did some research online but found no explanation of how it works or how to put it to code.

It's tetris and I setup all the shapes as functions so I could call them randomly. Also I don't need to do colors or show a window with the next shape.

When I run the program it shows my game board and then below obviously it shows my straight line. I want it so the straight line shows inside the game board.

Thanks

My code so far is below.

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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
  #include<iostream>
#include<string>
#include<conio.h>
#include<Windows.h>
#include<cstdlib>
#include<ctime>

using namespace std;

const int ROWS = 35;
const int COLUMNS = 25; 
char board[ROWS][COLUMNS];

void beginningMap(char m_board[][25]);

void beginningMap(char m_board[][25])
{
	for (int i = 0; i < 36; i++) 
		{
			for (int j = 0; j < 25; j++) 
			{
				m_board[i][j] = ' ';
				m_board[0][j] = '*';
				m_board[35][j] = '*';
				
				m_board[i][0] = '*';
				m_board[i][24] = '*';
				cout << m_board[i][j];
				
				
			}
		cout << '\n';	
		}
}

char leftT()
{
int i,j;
char arr[4][4];
for(i=0;i<4;i++)
  { for(j=0;j<4;j++)
     { 
arr[i][j]=' ';
         }
           }
    arr[1][1]='X';
    arr[2][0]='X';
	arr[2][1]='X';
	arr[3][1]='X';
for(i=0;i<4;i++)
     {  cout<<endl;
for( j=0;j<4;j++)
    {   cout<<" ";
         cout<<arr[i][j];
          }
                }
     return 0;
 }
char rightT()
{
int i,j;
char arr[4][4];
for(i=0;i<4;i++)
  { for(j=0;j<4;j++)
     { 
arr[i][j]=' ';
         }
           }
    arr[0][0]='X';
    arr[1][0]='X';
	arr[1][1]='X';
	arr[2][0]='X';
for(i=0;i<4;i++)
     {  cout<<endl;
for( j=0;j<4;j++)
    {   cout<<" ";
         cout<<arr[i][j];
          }
                }
     return 0;
 }
 char leftL()
 {
int i,j;
char arr[4][4];
for(i=0;i<4;i++)
  { for(j=0;j<4;j++)
     { 
arr[i][j]=' ';
         }
           }
    arr[0][1]='X';
    arr[1][1]='X';
	arr[2][1]='X';
	arr[3][1]='X';
	arr[3][0]='X';
for(i=0;i<4;i++)
     {  cout<<endl;
for( j=0;j<4;j++)
    {   cout<<" ";
         cout<<arr[i][j];
          }
                }
     return 0;
 }
 char rightL()
 {
int i,j;
char arr[4][4];
for(i=0;i<4;i++)
  { for(j=0;j<4;j++)
     { 
arr[i][j]=' ';
         }
           }
    arr[0][0]='X';
    arr[1][0]='X';
	arr[2][0]='X';
	arr[3][0]='X';
	arr[3][1]='X';
for(i=0;i<4;i++)
     {  cout<<endl;
for( j=0;j<4;j++)
    {   cout<<" ";
         cout<<arr[i][j];
          }
                }
     return 0;
 }
 char leftS()
 {
int i,j;
char arr[4][4];
for(i=0;i<4;i++)
  { for(j=0;j<4;j++)
     { 
arr[i][j]=' ';
         }
           }
    arr[0][1]='X';
    arr[1][1]='X';
	arr[2][0]='X';
	arr[3][0]='X';
	
for(i=0;i<4;i++)
     {  cout<<endl;
for( j=0;j<4;j++)
    {   cout<<" ";
         cout<<arr[i][j];
          }
                }
     return 0;
 }
 char rightS()
 {
int i,j;
char arr[4][4];
for(i=0;i<4;i++)
  { for(j=0;j<4;j++)
     { 
arr[i][j]=' ';
         }
           }
    arr[0][0]='X';
    arr[1][0]='X';
	arr[2][1]='X';
	arr[3][1]='X';
for(i=0;i<4;i++)
     {  cout<<endl;
for( j=0;j<4;j++)
    {   cout<<" ";
         cout<<arr[i][j];
          }
                }
     return 0;
 }

char straightLine()
{
int i,j;
char arr[4][4];
for(i=0;i<4;i++)
  { for(j=0;j<4;j++)
     { 
arr[i][j]=' ';
         }
           }
    arr[0][0]='X';
    arr[1][0]='X';
	arr[2][0]='X';
	arr[3][0]='X';
for(i=0;i<4;i++)
     {  cout<<endl;
for( j=0;j<4;j++)
    {   cout<<" ";
         cout<<arr[i][j];
          }
                }
     return 0;
 }


int main()
{
	beginningMap(board);
	straightLine();
	
	
}
There are a lot of problems with your code, which I think you should address before you figure out how to have the "straight line [show] inside the game board".

You have const int ROWS = 35; and const int COLUMNS = 25; on lines 10 and 11, so why don't you use them? The only time you use them is to set the number of elements for the board array. You should be using them in your for loops in the beginningMap() function. Additionally, as you have it now, lines 18 and 24 will attempt to access memory that doesn't belong to the array.

Finally, because your shape functions are too hard to read, I'll just say this:
Can you explain to me how any of the shape functions actually affect the game board?
Last edited on
Its Tetris. Those shapes are supposed to appear randomly and you rotate them to fill in the bottom line as more shapes appear. So the game board is there and the shapes appear inside the game board.
What I meant to hint at, was that the shapes don't affect the game board at all. Each shape function declares, populates and then prints the contents of a 4x4 character array, but they are totally unrelated to the game board. The fact that the straightline() function call on line 206 prints under the game board should have tipped you off.
That is why I was seeking help. Don't mean to be snarky but for the board I am going to change the numbers to match the game board array so that they appear in the middle top of the game board. The problem I am trying to figure out is how to overlay them on the game board once it's been drawn.
closed account (N36fSL3A)
At this time I'd seriously question if 2D arrays were the right way to go here.
Topic archived. No new replies allowed.