hi,
I have this code so far, but how do implement It so the user can roll dice and a random number gets printed on the dice faces instead of the 'xo' the squares currently print?
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define ROW 9
#define COL 9
char image[2][ROW][COL];
// COL
// +----+
// | | ROW
// | |
// +----+
//
// 5x5 X and O images
char shapes[2][5][6] = { { "* *"
, " * * "
, " * "
, " * * "
, "* *" }
, { " *** "
, "* *"
, "* *"
, "* *"
, " *** " }
};
void rectange()
{
for(int k = 0; k < 2; k++)
for(int r = 0; r < ROW; r++)
for(int c = 0; c < COL; c++)
{
image[k][r][c] = ' ';
int top = (r == 0);
int bottom = (r == ROW - 1);
int left = (c == 0);
int right = (c == COL - 1);
// corner
if ((top || bottom) && (left || right))
image[k][r][c] = '+';
else
// top or bottom
if (top || bottom) image[k][r][c] = '-';
else
// left or right
if (left || right) image[k][r][c] = '|';
}
}
void overlay_X_or_O()
{
for(int k = 0; k < 2; k++)
{
int shape = rand() % 2;
for(int r = 0; r < 5; r++)
for(int c = 0; c < 5; c++)
image[k][r + 2][c + 2] = shapes[shape][r][c];
}
}
int main()
{
srand(time(NULL)); // initialise random number generator
rectange(); // initialise the image with a rectange
overlay_X_or_O(); // overlay image of X or O on top
// print the image
for(int r = 0; r < ROW; r++)
{
for(int k = 0; k < 2; k++)
{
for(int c = 0; c < COL; c++)
printf("%c", image[k][r][c]);
printf(" ");
}
printf("\n");
}
return 0;
}