-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
CC = gcc | ||
CFLAGS = -Wall -Wextra -Wpedantic -no-pie -m64 | ||
|
||
TARGET = game | ||
|
||
all: $(TARGET) | ||
|
||
$(TARGET): $(TARGET).c | ||
$(CC) $(CFLAGS) -o $@ $< | ||
|
||
clean: | ||
rm -f $(TARGET) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <time.h> | ||
|
||
#define MAX_NUMBER 99999 | ||
|
||
void init() { | ||
setvbuf(stdin, NULL, _IONBF, 0); | ||
setvbuf(stdout, NULL, _IONBF, 0); | ||
setvbuf(stderr, NULL, _IONBF, 0); | ||
} | ||
|
||
void banner() { | ||
printf(" ___ * * ** ** ___ ____ ____ \n"); | ||
printf("/ **)( \\/ )( )( )/ **)(_ *)( *__)\n"); | ||
printf("\\__ \\ \\ / )(__)(( (__ )( )__) \n"); | ||
printf("(___/ \\/ (______)\\___) (__) (__) \n"); | ||
printf("\n"); | ||
printf("Welcome to the SVUCTF HELLOWORLD 2024!\n"); | ||
printf("\n"); | ||
} | ||
|
||
void game() { | ||
int secret_number = rand() % MAX_NUMBER + 1; | ||
int guess; | ||
|
||
printf("I've thought of a number between 1 and %d.\n", MAX_NUMBER); | ||
printf("You have only one chance to guess this number. Good luck!\n\n"); | ||
printf("Please enter your guess: "); | ||
|
||
if (scanf("%d", &guess) != 1) { | ||
printf("Invalid input, game over.\n"); | ||
return; | ||
} | ||
|
||
if (guess == secret_number) { | ||
printf("\nCongratulations! You've guessed the number %d!\n", | ||
secret_number); | ||
system("/bin/sh"); | ||
} else { | ||
printf( | ||
"\nSorry, you didn't guess correctly. The right number was %d.\n", | ||
secret_number); | ||
} | ||
} | ||
|
||
int main() { | ||
srand(time(NULL)); | ||
init(); | ||
banner(); | ||
game(); | ||
return 0; | ||
} |