Answered step by step
Verified Expert Solution
Question
1 Approved Answer
#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 MAXNAMELEN
#define MAXPWLEN
#define MAXSCORES
typedef struct
char firstnameMAXNAMELEN;
char lastnameMAXNAMELEN;
char usernameMAXNAMELEN;
char passwordMAXPWLEN;
int highScoresMAXSCORES; Kullancnn en yksek 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 playerx; Oyuncunun x koordinat
int playery; Oyuncunun y koordinat
int protoncount; P Toplanan proton says
int electroncount; e Toplanan elektron says
int antiprotoncount; p Toplanan kart proton says
int positroncount; E Toplanan kart elektron says
int antimattercount; retilen kart madde says
int gameover; Oyunun bitip bitmediini kontrol etmek iin
int timer;
GameState;
FONKSYONLAR
void registerUserAppState appState;
void loginUserAppState appState;
void displayMenuAppState appState;
int loadUsersAppState appState;
int saveUsersconst AppState appState;
void freeAppStateAppState appState;
void initializeAppStateAppState appState;
int findUserByUsernameconst AppState appState const char username;
void displayGameMenuAppState appState;
int loadMapGameMap gameMap const char filename;
void printMapconst GameMap gameMap;
void freeMapGameMap gameMap;
void startGameAppState appState;
void playGameGameMap gameMap GameState gameState User activeUserAppState appState;
void movePlayerGameMap gameMap GameState gameState int dx int dy;
void collectParticlesGameMap gameMapGameState gameState User activeUser AppState appState ;
void calculateAntimatterAndScoreGameState gameState User activeUser AppState appState;
void updateUserHighScoresUser activeUser int newScore;
void displayUserHighScoresUser activeUser;
void displayAllUserHighScoresconst AppState appState;
int main
AppState appState;
initializeAppState&appState;
if loadUsers&appState
fprintfstderr "Error loading user data.
;
return ;
displayMenu&appState;
freeAppState&appState;
return ;
Yeni kullancy kaydeden fonksiyon
void registerUserAppState appState
User newUser;
printfEnter first name: ;
scanfs newUser.firstname;
printfEnter last name: ;
scanfs newUser.lastname;
printfChoose a username: ;
scanfs newUser.username;
printfChoose a password: ;
scanfs newUser.password;
int i;
for i ; i MAXSCORES; i
newUser.highScoresi; Yeni kaydolan kullancnn skorlarn ile balatlmas
if findUserByUsernameappState newUser.username
printfThis username is already taken.
;
return;
Dinamik
if appStateuserCount appStatecapacity
int newCapacity appStatecapacity ;
User newArray reallocappStateusers, newCapacity sizeofUser;
if newArray NULL
fprintfstderr "Unable to allocate more memory.
;
return;
appStateusers newArray;
appStatecapacity newCapacity;
Yeni kullancy ekleme
appStateusersappStateuserCount newUser;
printfUser registered successfully.
;
saveUsersappState; Kullancy kaydeder
Username ve Password ile kullanc girii
void loginUserAppState appState
char usernameMAXNAMELEN passwordMAXPWLEN;
printfUsername: ;
scanfs username;
printfPassword: ;
scanfs password;
int userIndex findUserByUsernameappState username;
if userIndex strcmpappStateusersuserIndexpassword, password
printfInvalid username or password.
;
else
printfUser logged in successfully.
;
appStateactiveUser &appStateusersuserIndex;
displayGameMenuappState;
Kayt olunan ve giri yaplan ana men
void displayMenuAppState appState
int choice;
do
printf Register
;
printf Login
;
printf Exit
;
printfEnter your choice: ;
scanfd &choice;
if choice
registerUserappState;
else if choice
loginUserappState;
else if choice
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started