I'm creating a matrix containing a struct and I've came across some errors.
game_mat.cpp - displays the matrix in graphics.
CODE
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <graphics.h>
#include "d:\1vs100\game_mat.h"
#include "d:\1vs100\q_game1.h"
#include "d:\1vs100\game.h"
void printmat100(records rec[N][N])
{
int i,j,x=0,y=0;
for( i = 0; i < N; i++)
{
for ( j = 0; j < N; j++)
{
if(rec[i][j].active)
{
setfillstyle(1,RED);
bar(x,y,x+30,y+30);
}
else
{
setfillstyle(1,BLACK);
bar(x,y,x+30,y+30);
}
x+=30;
}
x=0;
y+=30;
}
x=0;y=0;
setlinestyle(0,0,3);
setcolor(BLUE);
for(i=0;i<=N;i++)
{
line (x,y,x,y+300);
x+=30;
}
x=0;y=0;
for(i=0;i<=N;i++)
{
line (x+300,y,x,y);
y+=30;
}
}
void game_mat(char * name,records rec[N][N])
{
int i,j;
char ch;
//records rec[N][N];
/*Random 1-3 number*/
randomize();
for ( i = 0; i < N; i++)
for ( j = 0; j < N; j++)
rec[i][j].ans = rand() %3 +1;
/*All players are active at start*/
for ( i = 0; i < N; i++)
for ( j = 0; j < N; j++)
rec[i][j].active = 1;
printmat100(rec);
q_game(name,rec);
/* put here the call for the function of the questions */
/* and check if (ans!=right_ans){rec[i][j].active=0;} */
ch=getch();
if(ch==27)
{
exit(1);
}
}
game_mat.h
CODE
typedef struct
{
int active;
int ans;
}records;
#define N 10
void game_mat(char * name,records rec[N][N]);
void printmat100(records rec[N][N]);
q_game1.cpp - loads question for the game and display them.
CODE
#include <graphics.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
#include "d:\1vs100\screens.h"
#include "d:\1vs100\menu.h"
#include "d:\1vs100\game.h"
#include "d:\1vs100\game_mat.h"
#include "d:\1vs100\q_game1.h"
#define que_length 7
void q_game(char * name,records rec[N][N])
{
char ch;
int i,j,ans_mone=0;
FILE *fp = fopen("d:\\1vs100\\q\\game.dat","rb");
question que[6];
/*
for ( i = 0; i < N; i++)
for ( j = 0; j < N; j++)
rec[i][j].ans = 0;
*/
setcolor(9); // light blue
settextstyle(4,0,4); // f,d,s
outtextxy(168,50,"1 vs 100");
setfillstyle(8,9); // s,c
bar(15,480,0,0); // left frame
bar(0,15,640,0); // up frame
bar(623,480,640,0); // right frame
bar(0,480,640,465); // down frame
setcolor(3); // turkiz
settextstyle(1,0,2); // f,d,s
outtextxy(255,90,"Hello,");
outtextxy(322,90,name);
fread(que,sizeof(question),6,fp);
fclose(fp);
settextstyle(0,0,0); // f,d,s
setcolor(8);
outtextxy(202,120,"Use the keyboard to answer");
setcolor(7);
outtextxy(102,250,"(1)");
outtextxy(102,300,"(2)");
outtextxy(102,350,"(3)");
setcolor(7);
outtextxy(102,200,que[0].question);
setcolor(8);
outtextxy(130,250,que[0].ans1);
outtextxy(130,300,que[0].ans2);
outtextxy(130,350,que[0].ans3);
for(i=1;i<que_length;i++)
{
ch=getch();
if(!(ch>='1'&&ch<='3')) // if !('1' || '2' || '3') was pressed
{
setcolor(4);
outtextxy(238,400,"Error: Wrong key!");
delay(2000);
setcolor(0);
outtextxy(238,400,"Error: Wrong key!");
i--;
}
else if(ch==((que[i-1].right_ans)+48)) // if right answer
{
ans_mone++;
setcolor(9);
outtextxy(290,400,"Correct");
delay(1500);
setcolor(0);
outtextxy(290,400,"Correct");
outtextxy(102,200,que[i-1].question);
outtextxy(130,250,que[i-1].ans1);
outtextxy(130,300,que[i-1].ans2);
outtextxy(130,350,que[i-1].ans3);
setcolor(7);
outtextxy(102,200,que[i].question);
setcolor(8);
outtextxy(130,250,que[i].ans1);
outtextxy(130,300,que[i].ans2);
outtextxy(130,350,que[i].ans3);
} // if
else
{
setcolor(4);
outtextxy(290,400,"Incorrect");
delay(1500);
setcolor(0);
outtextxy(290,400,"Incorrect");
outtextxy(102,200,que[i-1].question);
outtextxy(130,250,que[i-1].ans1);
outtextxy(130,300,que[i-1].ans2);
outtextxy(130,350,que[i-1].ans3);
setcolor(7);
outtextxy(102,200,que[i].question);
setcolor(8);
outtextxy(130,250,que[i].ans1);
outtextxy(130,300,que[i].ans2);
outtextxy(130,350,que[i].ans3);
}
if(ch==27) // esc
{
closegraph();
sound(250);
delay(4);
nosound();
exit(1);
}
} // for
if(ans_mone>=5)
{
setcolor(0);
outtextxy(102,200,que[10].question);
outtextxy(130,250,que[10].ans1);
outtextxy(130,300,que[10].ans2);
outtextxy(130,350,que[10].ans3);
outtextxy(102,250,"(1)");
outtextxy(102,300,"(2)");
outtextxy(102,350,"(3)");
setcolor(5);
settextstyle(4,0,4); // f,d,s
outtextxy(230,200,"YOU WIN");
delay(680);
setcolor(2);
settextstyle(4,0,4); // f,d,s
outtextxy(230,200,"YOU WIN");
delay(680);
setcolor(3);
settextstyle(4,0,4); // f,d,s
outtextxy(230,200,"YOU WIN");
delay(680);
clearviewport();
game1(0,name);
}
else
{
setcolor(0);
outtextxy(102,200,que[10].question);
outtextxy(130,250,que[10].ans1);
outtextxy(130,300,que[10].ans2);
outtextxy(130,350,que[10].ans3);
outtextxy(102,250,"(1)");
outtextxy(102,300,"(2)");
outtextxy(102,350,"(3)");
setcolor(4);
settextstyle(3,0,4); // f,d,s
outtextxy(230,200,"YOU LOSE");
delay(2000);
clearviewport();
game1(0,name);
}
} // end func q_game
q_game1.h
CODE
void q_game(char * name,records rec[N][N]);
The compiling errors:
1.
Parameter 'rec' is never used2.
Undefined symbol 'rec'I don't understand where i went wrong..
rec is defined and known in each file..
Any thoughts?..