-
making bejeweled
this is a project i have to do for uni
but i'm not sure if i have to use structs?
i have to create a board with ACSII characters and use 4 jewels as character symbols. i don't see where i have to use structs? but my friend has in his report
i've only learnt stuff like
file i/o
strings
pointers
scanf and printf
while, if, for.
arrays
functions
recursion
so just in case i future questions about the project. in case i'm having trouble with the code.
-
I suppose this is C and not C++ (since you are using printf and scanf). Well if all you are going to do is print a board with a specified size and using jewels as markers I think you can about with an array (2D for simplicity).
-
could i add borders in an an array for the board? it'll be a 6x6 board
-
Either add borders in the array or create a special routine to draw the borders.
-
-
If you need to use structs as part of the requirement for the assignment then adding that to your program should be easy. Just make a struct to hold all of the data for a character, then create an instance for each of your characters.
EDIT:
Do you know what it means to create an instance of something? If not I'll gladly explain better.
-
-
This might get you started. I will use the non-object oriented approach though it will be hard for me.
Code:
#define SQUARE 0x0001
#define CIRCLE 0x0002
#define TRIANGLE 0x0003
#define DIAMOND 0x0004
void DrawBoard(void)
{
char *txt=NULL;
for (int i=-1;i<7;i++)
{
for (int j=-1;j<7;j++)
{
if (i==-1 || i==7 || j==-1 || j==7)
{
int ch=177;
printf("%c",ch);
}
else
{
switch GameBoard[i,j]
{
case SQUARE:
//txt="<jewel_character>"
break;
case CIRCLE:
break;
case TRIANGLE:
break;
case DIAMOND:
break;
}
printf("%s",txt);
}
printf("\n");
}
}
}
There is a much better way to do things but I tried to keep it simple. Using structs would be a much better approach and better yet using C++ classes would be even better. But I leave that to you.