Question: #include #include #include #include #include #define MAX _ NAME _ LEN 5 0 #define MAX _ PW _ LEN 2 0 #define MAX _ SCORES

#include
#include
#include
#include
#include
#define MAX_NAME_LEN 50
#define MAX_PW_LEN 20
#define MAX_SCORES 5
typedef struct {
char firstname[MAX_NAME_LEN];
char lastname[MAX_NAME_LEN];
char username[MAX_NAME_LEN];
char password[MAX_PW_LEN];
int highScores[MAX_SCORES]; // Kullancnn en yksek 5 skoru
} User;
typedef struct {
User *users; // Dinamik olarak ayrlan kullanclar iin pointer
int userCount;
int capacity; // Maksimum kullanc kapasitesi
User *activeUser; // Aktif kullanc
} AppState;
typedef struct {
char **map;
int rows;
int cols;
} GameMap;
typedef struct {
int player_x; // Oyuncunun x koordinat
int player_y; // Oyuncunun y koordinat
int proton_count; // P Toplanan proton says
int electron_count; // e Toplanan elektron says
int antiproton_count; // p Toplanan kart proton says
int positron_count; // E Toplanan kart elektron says
int antimatter_count; //retilen kart madde says
int game_over; // Oyunun bitip bitmediini kontrol etmek iin
int timer;
} GameState;
/* FONKSYONLAR */
void registerUser(AppState *appState);
void loginUser(AppState *appState);
void displayMenu(AppState *appState);
int loadUsers(AppState *appState);
int saveUsers(const AppState *appState);
void freeAppState(AppState *appState);
void initializeAppState(AppState *appState);
int findUserByUsername(const AppState *appState, const char *username);
void displayGameMenu(AppState *appState);
int loadMap(GameMap *gameMap, const char *filename);
void printMap(const GameMap *gameMap);
void freeMap(GameMap *gameMap);
void startGame(AppState *appState);
void playGame(GameMap *gameMap, GameState *gameState, User *activeUser,AppState *appState);
void movePlayer(GameMap *gameMap, GameState *gameState, int dx, int dy);
void collectParticles(GameMap *gameMap,GameState *gameState, User *activeUser, AppState *appState) ;
void calculateAntimatterAndScore(GameState *gameState, User *activeUser, AppState *appState);
void updateUserHighScores(User *activeUser, int newScore);
void displayUserHighScores(User *activeUser);
void displayAllUserHighScores(const AppState *appState);
int main(){
AppState appState;
initializeAppState(&appState);
if (loadUsers(&appState)!=0){
fprintf(stderr, "Error loading user data.
");
return 1;
}
displayMenu(&appState);
freeAppState(&appState);
return 0;
}
// Yeni kullancy kaydeden fonksiyon
void registerUser(AppState *appState){
User newUser;
printf("Enter first name: ");
scanf("%49s", newUser.firstname);
printf("Enter last name: ");
scanf("%49s", newUser.lastname);
printf("Choose a username: ");
scanf("%49s", newUser.username);
printf("Choose a password: ");
scanf("%19s", newUser.password);
int i;
for (i =0; i < MAX_SCORES; i++){
newUser.highScores[i]=0; // Yeni kaydolan kullancnn skorlarn0 ile balatlmas
}
if (findUserByUsername(appState, newUser.username)!=-1){
printf("This username is already taken.
");
return;
}
// Dinamik
if (appState->userCount >= appState->capacity){
int newCapacity = appState->capacity *2;
User *newArray = realloc(appState->users, newCapacity * sizeof(User));
if (newArray == NULL){
fprintf(stderr, "Unable to allocate more memory.
");
return;
}
appState->users = newArray;
appState->capacity = newCapacity;
}
// Yeni kullancy ekleme
appState->users[appState->userCount++]= newUser;
printf("User registered successfully.
");
saveUsers(appState); // Kullancy kaydeder
}
// Username ve Password ile kullanc girii
void loginUser(AppState *appState){
char username[MAX_NAME_LEN], password[MAX_PW_LEN];
printf("Username: ");
scanf("%49s", username);
printf("Password: ");
scanf("%19s", password);
int userIndex = findUserByUsername(appState, username);
if (userIndex ==-1|| strcmp(appState->users[userIndex].password, password)!=0){
printf("Invalid username or password.
");
} else {
printf("User logged in successfully.
");
appState->activeUser = &appState->users[userIndex];
displayGameMenu(appState);
}
}
// Kayt olunan ve giri yaplan ana men
void displayMenu(AppState *appState){
int choice;
do {
printf("1. Register
");
printf("2. Login
");
printf("3. Exit
");
printf("Enter your choice: ");
scanf("%d", &choice);
if (choice ==1){
registerUser(appState);
} else if (choice ==2){
loginUser(appState);
} else if (choice

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!