Commit eeb8e691 by grlabu

Replace main.c

parent 89ae5fee
Showing with 22 additions and 158 deletions
#include "Header.h" #include "bossdefeated.h"
#include <stdio.h> #include "ui_bossdefeated.h"
#include <stdlib.h>
#include <time.h>
int main(void) #include <QApplication>
{ #include <QDebug>
srand(time(NULL));
PrintWelcomeMessage();
int selection;
char *saveFile = "GameSave.txt";
while (1)
{
selection = Menu();
switch(selection)
{
case 1:
{
int gameState = 1;
Player player = CreatePlayer();
int defeatedEnemies = 0;
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("\nKohtasid vastast tüübiga %s, %dHP ja rünnaku tugevusega"
" %d.\n", enemy.type, enemy.health,
enemy.attack);
gameState = fight(&player, &enemy);
}
else
{
// Generate the final boss
FinalBoss boss = CreateFinalBoss(defeatedEnemies);
printf("\nOled jõudmas koopa lõppu ning "
"äkitselt märkasid pealikku %s, %dHP ja"
" rünnaku tugevusega"
" %d.\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;
}
defeatedEnemies++;
levelUp(&player);
}
}
break;
}
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) BossDefeated::BossDefeated(QWidget *parent)
{ : QDialog(parent)
SaveGame(saveFile, &player, defeatedEnemies); , ui(new Ui::BossDefeated)
return EXIT_SUCCESS; {
} qDebug() << "boss defeated";
ui->setupUi(this);
else if (moveResult == 0) }
{
gameState = 0;
}
else if (moveResult == 1)
{
if (defeatedEnemies < NUM_HENCHMEN)
{
Enemy enemy = CreateEnemy(defeatedEnemies);
printf("\nKohtasid vastast tüübiga %s, %dHP ja rünnaku tugevusega"
" %d.\n", enemy.type, enemy.health,
enemy.attack);
gameState = fight(&player, &enemy);
}
else
{
// Generate the final boss
FinalBoss boss = CreateFinalBoss(defeatedEnemies);
printf("\nOled jõudmas koopa lõppu ning "
"äkitselt märkasid pealikku %s, %dHP ja"
" rünnaku tugevusega"
" %d.\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;
}
defeatedEnemies++;
levelUp(&player);
}
}
break;
}
case 0: BossDefeated::~BossDefeated()
printf("VÄLJUN...\n\n"); {
return EXIT_SUCCESS; delete ui;
} }
}
return 0; void BossDefeated::on_pushButton_2_clicked()
{
qApp->exit(0);
} }
void BossDefeated::on_pushButton_clicked()
{
qApp->exit(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