-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.c
69 lines (57 loc) · 1.78 KB
/
game.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
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#define MATRIX_ROWS 6
#define MATRIX_COLS 5
#define COUNTDOWN_SECONDS 30
void printMatrix(int matrix[MATRIX_ROWS][MATRIX_COLS]) {
printf("Find and count 1-30 in 30 sec.:\n");
for (int i = 0; i < MATRIX_ROWS; i++) {
for (int j = 0; j < MATRIX_COLS; j++) {
printf("%3d ", matrix[i][j]);
}
printf("\n");
}
}
void countdownTimer() {
printf("Countdown Timer:\n");
for (int seconds = COUNTDOWN_SECONDS; seconds > 0; seconds--) {
// printf("%d ", seconds);
fflush(stdout); // Flush the output to ensure it's displayed immediately
sleep(1); // Sleep for 1 second
}
char success;
printf("Could you make it or not.? y/n : ");
scanf("%c", &success);
if (success == 'y'){
printf("Congratulations.. Your mind seems sharp. \n");
}else
printf("C'mon, you are trying.. keep practicing..\n");
}
int main() {
int matrix[MATRIX_ROWS][MATRIX_COLS] = {0};
int uniqueNumbers[MATRIX_ROWS * MATRIX_COLS] = {0};
int uniqueCount = 0;
srand(time(NULL));
while (uniqueCount < MATRIX_ROWS * MATRIX_COLS) {
int randomNumber = rand() % (MATRIX_ROWS * MATRIX_COLS) + 1;
int isUnique = 1;
for (int i = 0; i < uniqueCount; i++) {
if (uniqueNumbers[i] == randomNumber) {
isUnique = 0;
break;
}
}
if (isUnique) {
matrix[uniqueCount / MATRIX_COLS][uniqueCount % MATRIX_COLS] = randomNumber;
uniqueNumbers[uniqueCount] = randomNumber;
uniqueCount++;
}
}
// Print the generated matrix
printMatrix(matrix);
// Start the countdown timer
countdownTimer();
return 0;
}