Commit 33f6c6c3 by gerann

Update main.c

parent 4079f980
Showing with 142 additions and 54 deletions
#include "Header.h" #include "Header.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void) int main(void)
{ {
srand(time(NULL)); srand(time(NULL));
int choice;
PrintWelcomeMessage(); PrintWelcomeMessage();
int selection;
printf("Vajutage 1, et mängida!\n" char *saveFile = "GameSave.txt";
"Vajutage 2, et lugeda mängu reegleid!\n"
"Vajutage 0, et väljuda!\n"); while (1)
do
{ {
scanf("%d", &choice); selection = Menu();
if (choice != 1 && choice != 0 && choice != 2)
switch(selection)
{ {
printf("Palun valige õige valik...\n"); case 1:
} {
} while (choice != 1 && choice != 0 && choice != 2); int gameState = 1;
Player player = CreatePlayer();
int defeatedEnemies = 0;
if (choice == 0) while (gameState == 1)
{ {
printf("\nVäljun...\n"); int moveResult = Move(defeatedEnemies);
return 0; if (moveResult == LOSE_HP)
} { // Player encountered a trap
handleTrap(&player);
continue; // Restart the loop, allowing the player to choose the path again
}
if (moveResult == SAVE_GAME)
{
SaveGame(saveFile, &player, defeatedEnemies);
return EXIT_SUCCESS;
}
else if (moveResult == 0)
{
gameState = 0;
}
else if (moveResult == 1)
{
if (defeatedEnemies < NUM_HENCHMEN)
{
Enemy enemy = CreateEnemy(defeatedEnemies);
printf("\nVastane tüübiga %s, %dHP ja rünnaku tugevusega"
" %d on loodud.\n", enemy.type, enemy.health,
enemy.attack);
gameState = fight(&player, &enemy);
}
else
{
// Generate the final boss
FinalBoss boss = CreateFinalBoss(defeatedEnemies);
printf("\nVastane tüübiga %s, %dHP ja rünnaku tugevusega"
" %d on loodud.\n", boss.type, boss.health,
boss.attack);
gameState = bossFight(&player, &boss);
}
if (gameState == 0)
{
return EXIT_SUCCESS;
}
if (gameState == SAVE_GAME)
{
SaveGame(saveFile, &player, defeatedEnemies);
return EXIT_SUCCESS;
}
else if (choice == 2) defeatedEnemies++;
{ levelUp(&player);
DisplayGameRules(); }
} }
break;
else if (choice == 1)
{
int gameState = 1;
Player player = CreatePlayer();
int defeatedEnemies = 0;
while (gameState == 1)
{
int moveResult = Move(defeatedEnemies);
if (moveResult == -10) { // Player encountered a trap
handleTrap(&player);
continue; // Restart the loop, allowing the player to choose the path again
}
if (defeatedEnemies < NUM_HENCHMEN) {
Enemy enemy = CreateEnemy(defeatedEnemies);
printf("\nVastane tüübiga %s, %dHP ja rünnaku tugevusega"
" %d on loodud.\n", enemy.type, enemy.health, enemy.attack);
gameState = fight(&player, &enemy);
} else {
// Generate the final boss
FinalBoss boss = CreateFinalBoss(defeatedEnemies);
printf("\nVastane tüübiga %s, %dHP ja rünnaku tugevusega"
" %d on loodud.\n", boss.type, boss.health, boss.attack);
gameState = bossFight(&player, &boss);
} }
case 2:
DisplayGameRules();
break;
case 3:
{
int gameState = 1;
Player player;
int defeatedEnemies;
LoadGame(saveFile, &player, &defeatedEnemies);
while (gameState == 1)
{
int moveResult = Move(defeatedEnemies);
if (moveResult == LOSE_HP)
{ // Player encountered a trap
handleTrap(&player);
continue; // Restart the loop, allowing the player to choose the path again
}
if (moveResult == SAVE_GAME)
{
SaveGame(saveFile, &player, defeatedEnemies);
return EXIT_SUCCESS;
}
else if (moveResult == 0)
{
gameState = 0;
}
else if (moveResult == 1)
{
if (defeatedEnemies < NUM_HENCHMEN)
{
Enemy enemy = CreateEnemy(defeatedEnemies);
printf("\nVastane tüübiga %s, %dHP ja rünnaku tugevusega"
" %d on loodud.\n", enemy.type, enemy.health,
enemy.attack);
gameState = fight(&player, &enemy);
}
else
{
// Generate the final boss
FinalBoss boss = CreateFinalBoss(defeatedEnemies);
printf("\nVastane tüübiga %s, %dHP ja rünnaku tugevusega"
" %d on loodud.\n", boss.type, boss.health,
boss.attack);
gameState = bossFight(&player, &boss);
}
if (gameState == 0)
{
return EXIT_SUCCESS;
}
if (gameState == SAVE_GAME)
{
SaveGame(saveFile, &player, defeatedEnemies);
return EXIT_SUCCESS;
}
if (gameState == 0) { defeatedEnemies++;
return 0; levelUp(&player);
}
}
break;
} }
defeatedEnemies++; case 0:
levelUp(&player); printf("VÄLJUN...\n\n");
return EXIT_SUCCESS;
} }
} }
return 0; return 0;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment