-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreplay.c
More file actions
52 lines (47 loc) · 1.2 KB
/
replay.c
File metadata and controls
52 lines (47 loc) · 1.2 KB
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
#include <ncurses.h>
#include "prompt.h"
#include "replay.h"
#include "structs.h"
#include "print.h"
#include "save.h"
#include "strings.h"
void showReplay(WINDOW *boardWindow, struct board *board, FILE *file) {
char boardString[SAVELEN + 1];
boardString[SAVELEN] = '\0';
keypad(stdscr, 1);
while (1) {
fscanf(file, "%s\n", boardString);
fseek(file, ftell(file) - SAVELEN - 1, SEEK_SET);
loadBoard(boardString, board);
printDice((*board).move.moves, -1);
printMatchScore(board);
printBoard(boardWindow, board);
switch (getch()) {
case KEY_DOWN:
fseek(file, SAVELEN + 1, SEEK_CUR);
break;
case KEY_UP:
fseek(file, -SAVELEN - 1, SEEK_CUR);
break;
case KEY_LEFT:
rewind(file);
break;
case KEY_RIGHT:
fseek(file, -SAVELEN - 1, SEEK_END);
break;
default:
continue;
}
}
}
void promptReplay(WINDOW *boardWindow, struct board *board) {
char filename[FILENAME_MAXLENGTH];
FILE *file;
int firstAttempt = 1;
do {
prompt(firstAttempt ? PROMPT_REPLAY : PROMPT_LOAD_INVALID, "%s", filename);
file = fopen(filename, "r");
firstAttempt = 0;
} while (!file);
showReplay(boardWindow, board, file);
}