-
Notifications
You must be signed in to change notification settings - Fork 2
/
leaderboard.c
74 lines (64 loc) ยท 1.76 KB
/
leaderboard.c
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
#include <Windows.h>
#include <stdio.h>
#include "declaration.h"
#include "leaderboard.h"
#include "ui.h"
#pragma warning (disable:4996)
void showLeaderBoard(void)
{
FILE* leaderboard;
char player1_name[11] = "\0";
char player2_name[11] = "\0";
char result[11] = "\0";
/* ๋ฆฌ๋๋ณด๋์ ์ผ๊ด์ ์ธ ์ถ๋ ฅ์ ์ํด, ๊ธฐ์ค์ด ๋๋ tab์ ๊ธธ์ด๋ฅผ ์์ ์ ์ธ */
const int TAB_SIZE = 8;
system("cls");
printf("\n\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);
printf("\t\t\t << LEADERBOARD >>\n\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 14);
printf("-------------------------------------------------------------------------\n");
printf("|\tPlayer1\t\t|\tPlayer2\t\t|\tWinner\t\t|\n");
printf("-------------------------------------------------------------------------\n");
leaderboard= fopen("leaderboard.txt", "a+");
checkFile(leaderboard);
fscanf(leaderboard, "%s %s %s", player1_name, player2_name, result);
while (!feof(leaderboard))
{
if ((int)(strlen(player1_name)) < TAB_SIZE)
{
printf("|\t%s\t\t|", player1_name);
}
else
{
printf("|\t%s\t|", player1_name);
}
if ((int)(strlen(player2_name)) < TAB_SIZE)
{
printf("\t%s\t\t|", player2_name);
}
else
{
printf("\t%s\t|", player2_name);
}
if ((int)(strlen(result)) < TAB_SIZE)
{
printf("\t%s\t\t|\n", result);
}
else
{
printf("\t%s\t|\n", result);
}
printf("-------------------------------------------------------------------------\n");
fscanf(leaderboard, "%s %s %s", player1_name, player2_name, result);
}
fclose(leaderboard);
chooseMenu();
}
void checkFile(FILE* file)
{
if (file == NULL)
{
printf("File doesn't linked!\n");
}
}