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
|
void logic(struct INFO* info, char **tmp2, enum eDirection* dir)
{
FILE *fptr1, *fptr2, *fptr3;
char score[MAX] = "score.txt";
char temp[MAX];
int lin;
char go[] = {"Game Over"};
int c = 10;
int prevX = tailX[0];
int prevY = tailY[0];
int prev2X, prev2Y;
tailX[0] = x;
tailY[0] = y;
for(int i = 1; i < nTail; i++)
{
prev2X = tailX[i];
prev2Y = tailY[i];
tailX[i] = prevX;
tailY[i] = prevY;
prevX = prev2X;
prevY = prev2Y;
}
switch(*dir)
{
case LEFT:
x--;
break;
case RIGHT:
x++;
break;
case UP:
y--;
break;
case DOWN:
y++;
break;
default:
break;
}
if(x == fruitX && y == fruitY)
{
srand(time(NULL));
PlaySound(MAKEINTRESOURCE(IDW_EAT), NULL, SND_RESOURCE | SND_ASYNC);
Score += 1;
fruitX = rand() % width;
fruitY = rand() % height;
nTail++;
}
if(!mod)
{
if(Map == 1)
{
if(x >= width)
{
x = 0;
}
else if(x < 0 )
{
x = width - 1;
}
if(y >= height)
{
y = 0;
}
else if(y < 0 )
{
y = height - 1;
}
}
....}
..
...
..
..
for(int i = 0; i < nTail; i++)
{
if(tailX[i] == x && tailY[i] == y)
{
alSourceStop(uiSources[0]);
alDeleteSources(MAX_NUM, &uiSources[0]);
alDeleteBuffers(MAX_NUM, &uiBuffer);
play = FALSE;
PlaySound(MAKEINTRESOURCE(IDW_DEAD), NULL, SND_RESOURCE | SND_ASYNC);
gotoxy(36, 34);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 14);
printf("You've touched your tail with the had");
fptr1 = fopen(score, "a+");
rewind(fptr1);
for(lin = 1; fscanf(fptr1, "%19s %i", info->user, &info->score) == 2 && fgets(score, 999, fptr1) != NULL; ++lin)
{
if(strcmp(*tmp2, info->user) == 0 && Score > info->score)
{
fptr3 = fopen("temp1.txt", "a+");
fprintf(fptr3, "%-6s %i\n", *tmp2, Score);
rewind(fptr3);
fgets(temp, 999, fptr3);
fptr2 = fopen("temp.txt", "w");
rewind(fptr1);
for(int lineCtr = 1; fgets(score, 999, fptr1) != NULL; ++lineCtr)
{
fprintf(fptr2, "%s", lineCtr != lin ? score : temp);
}
fclose(fptr1);
fclose(fptr2);
fclose(fptr3);
remove("temp1.txt");
remove("score.txt");
rename("temp.txt", "score.txt");
arrangeGameScore(fptr1, fptr2); // I use it even here I don't get any Warnings
system("attrib +h +s score.txt");
..
..
..
fseek(fptr1, 0, SEEK_END);
fprintf(fptr1, "%-6s %i\n", *tmp2, Score);
fclose(fptr1);
arrangeGameScore(fptr1, fptr2); // <- Here I got the Warning !?
system("attrib +h +s score.txt");
|