Commit ef38fdb8 by grlabu

Upload New File

parent d3fef7b1
Showing with 128 additions and 0 deletions
#include "Header.h"
// gameengine.cpp
#include "gameengine.h"
#include <QDebug>
Enemy CreateEnemy(int defeated_enemies)
{
Enemy enemy;
// Scale enemy health and attack based on defeated enemies
enemy.health = 50 + defeated_enemies * 10; // Base health + 10 for each defeated enemy
// Increase enemy attack proportionally
switch (defeated_enemies)
{
case 0:
strcpy(enemy.type, "Päkapikk"); // Päkapikk
enemy.attack = ELF_BASE_DAMAGE + defeated_enemies * 5; // Base damage + 5 for each defeated enemy
break;
case 1:
strcpy(enemy.type, "Ork"); // Ork
enemy.attack = ORK_BASE_DAMAGE + defeated_enemies * 5; // Base damage + 5 for each defeated enemy
break;
case 2:
strcpy(enemy.type, "Smurf"); // Smurf
enemy.attack = SMURF_BASE_DAMAGE + defeated_enemies * 5; // Base damage + 5 for each defeated enemy
break;
case 3:
strcpy(enemy.type, "Deemon"); // Deemon
enemy.attack = DEEMON_BASE_DAMAGE + defeated_enemies * 5; // Base damage + 5 for each defeated enemy
break;
case 5:
enemy.health = BOSS_HEALTH + defeated_enemies * 20;
enemy.attack = BOSS_DAMAGE + defeated_enemies * 5;
strcpy(enemy.type, "Final Boss");
break;
default:
strcpy(enemy.type, "Bandiit"); // Bandiit
enemy.attack = BANDIIT_BASE_DAMAGE + defeated_enemies * 5; // Base damage + 5 for each defeated enemy
}
// Level up player
return enemy;
}
int Move(int correctChoice)
{
// Generate a random scenario
int scenario = rand() % 2; // Assuming there are three possible scenarios
// Logic based on the generated scenario and correct choice
switch (scenario)
{
case 0:
// Scenario: Player encounters a trap
if (correctChoice == TRAP_SCENARIO)
{
return LOSE_HP; // Player loses health
}
else
{
// Handle other scenarios
// For now, let's return a placeholder value
return 0;
}
case 1:
// Scenario: Player finds a potion
if (correctChoice == POTION)
{
return GAIN_POTION; // Player gains a potion
}
else
{
// Handle other scenarios
// For now, let's return a placeholder value
return 0;
}
default:
// Default scenario
// For now, let's return a placeholder value
return 0;
}
}
int SaveGame(char *file, Player *p, int enemiesDefeated)
{
FILE *fh;
fh = fopen(file, "w");
if (fh == NULL)
{
fprintf(stderr, "Error opening save file!\n");
return 1;
}
fprintf(fh, "%d %d %d\n%d", p->health, p->attack, p->potionCount,
enemiesDefeated);
fclose(fh);
return 0;
}
void LoadGame(char *file, Player *p, int *enemies)
{
FILE *fh;
fh = fopen(file, "r");
if (fh == NULL)
{
fprintf(stderr, "Failed to open file %s\n", file);
exit(1);
}
fscanf(fh, "%d %d %d", &p->health, &p->attack, &p->potionCount);
fscanf(fh, "%d", enemies);
fclose(fh);
}
void levelUp(Player &p)
{
p.health += LEVEL_UP_HP; // Add 20 HP to the player
p.attack += LEVEL_UP_ATTACK; // Add 5 attack power to the player
p.potionCount += 1; // Add 1 potion to the player
printf("Mängija taseme tõus! Sa said 20 lisa HP-d, 5 lisa rünnakuvõimet ja 1 lisa võlujoogi!\n");
printf("Mängija andmed: HP - %d, rünnakuvõime - %d, võlujookide kogus - %d\n\n", p.health, p.attack, p.potionCount);
}
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