i need some hints on whats up with my program. to give you some back ground info, its for my minefield game. specifically this is the part of the code that keeps track of the game stats. the three things to be kept up to date are the score, number of flags and number of mines.
i wrote a simple driver that test the functions responsible for this task. and included only one of the updating function because all three are exactly the same.
Code:
#include "display.h"
#include "stats.h"
#include <stdio.h>
int main()
{
int up_mines = 0;
int up_flags = 0;
int up_score = 0;
char x;
stats(up_mines, up_flags, up_score);
printf("Please enter number:");
while((x = getchar()) != EOF)
{
update_mines(x);
update_flags(x);
update_score(x);
}
}
Code:
void update_mines(int up_mines)
{
char i;
int k = 0;
while((i = getchar(up_mines)) && k < 2)
{
numbers(i);
k++;
}
}
Code:
#include "stats.h"
#define MAX_STAT_ROW 4
#define MAX_STAT_COL 3
/* tests and chooses the number to be printed in the stats board */
void numbers(char x)
{
char num1[MAX_STAT_ROW][MAX_STAT_COL];
int i;
int k;
/* initializes all arrays to blanks */
for(i = 0; i < MAX_STAT_ROW; i++)
{ for(k = 0; k < MAX_STAT_COL; k++)
{num1[i][k] = ' ';}
}
switch(x)
{
case '0':
num1[0][1] = '-';
num1[1][0] = '|';
num1[1][2] = '|';
num1[2][0] = '|';
num1[2][2] = '|';
num1[3][1] = '-';
for(i = 0; i < MAX_STAT_ROW; i++)
{ for(k = 0; k < MAX_STAT_COL; k++)
{printf("%c", num1[i][k]);}
}
break;
case '1':
num1[1][1] = '|';
num1[2][2] = '|';
for(i = 0; i < MAX_STAT_ROW; i++)
{ for(k = 0; k < MAX_STAT_COL; k++)
{printf("%c", num1[i][k]);}
}
break;
case '2':
num1[0][1] = '-';
num1[1][2] = '|';
num1[1][1] = '_';
num1[2][0] = '|';
num1[3][1] = '-';
for(i = 0; i < MAX_STAT_ROW; i++)
{ for(k = 0; k < MAX_STAT_COL; k++)
{printf("%c", num1[i][k]);}
}
break;
case '3':
num1[0][1] = '-';
num1[1][2] = '|';
num1[1][1] = '_';
num1[2][2] = '|';
num1[3][1] = '-';
for(i = 0; i < MAX_STAT_ROW; i++)
{ for(k = 0; k < MAX_STAT_COL; k++)
{printf("%c", num1[i][k]);}
}
break;
case '4':
num1[0][0] = '|';
num1[1][0] = '|';
num1[1][1] = '_';
num1[1][2] = '|';
num1[0][2] = '|';
num1[2][2] = '|';
num1[3][2] = '|';
for(i = 0; i < MAX_STAT_ROW; i++)
{ for(k = 0; k < MAX_STAT_COL; k++)
{printf("%c", num1[i][k]);}
}
break;
case '5':
num1[0][1] = '-';
num1[1][0] = '|';
num1[1][1] = '_';
num1[2][2] = '|';
num1[3][1] = '-';
for(i = 0; i < MAX_STAT_ROW; i++)
{ for(k = 0; k < MAX_STAT_COL; k++)
{printf("%c", num1[i][k]);}
}
break;
case '6':
num1[0][1] = '-';
num1[1][0] = '|';
num1[2][0] = '|';
num1[3][1] = '-';
num1[2][2] = '|';
num1[1][1] = '_';
for(i = 0; i < MAX_STAT_ROW; i++)
{ for(k = 0; k < MAX_STAT_COL; k++)
{printf("%c", num1[i][k]);}
}
break;
case '7':
num1[0][1] = '_';
num1[1][2] = '|';
num1[2][2] = '|';
num1[1][0] = '|';
for(i = 0; i < MAX_STAT_ROW; i++)
{ for(k = 0; k < MAX_STAT_COL; k++)
{printf("%c", num1[i][k]);}
}
break;
case '8':
num1[0][1] = '-';
num1[1][0] = '|';
num1[1][2] = '|';
num1[2][0] = '|';
num1[2][2] = '|';
num1[3][1] = '-';
num1[1][1] = '_';
for(i = 0; i < MAX_STAT_ROW; i++)
{ for(k = 0; k < MAX_STAT_COL; k++)
{printf("%c", num1[i][k]);}
}
break;
case '9':
num1[0][1] = '-';
num1[1][0] = '|';
num1[1][2] = '|';
num1[2][0] = '|';
num1[2][2] = '|';
num1[3][1] = '-';
num1[1][1] = '_';
for(i = 0; i < MAX_STAT_ROW; i++)
{ for(k = 0; k < MAX_STAT_COL; k++)
{printf("%c", num1[i][k]);}
}
break;
}
}