Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
krkane
/
Rüütli Vaev
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
1
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
33f6c6c3
authored
Mar 20, 2024
by
gerann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update main.c
parent
4079f980
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
113 additions
and
25 deletions
Source/main.c
Source/main.c
View file @
33f6c6c3
#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
;
char
*
saveFile
=
"GameSave.txt"
;
printf
(
"Vajutage 1, et mängida!
\n
"
while
(
1
)
"Vajutage 2, et lugeda mängu reegleid!
\n
"
{
"Vajutage 0, et väljuda!
\n
"
);
selection
=
Menu
();
switch
(
selection
)
{
case
1
:
{
int
gameState
=
1
;
Player
player
=
CreatePlayer
();
int
defeatedEnemies
=
0
;
do
while
(
gameState
==
1
)
{
{
scanf
(
"%d"
,
&
choice
);
int
moveResult
=
Move
(
defeatedEnemies
);
if
(
choice
!=
1
&&
choice
!=
0
&&
choice
!=
2
)
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
)
{
{
printf
(
"Palun valige õige valik...
\n
"
);
SaveGame
(
saveFile
,
&
player
,
defeatedEnemies
);
return
EXIT_SUCCESS
;
}
}
}
while
(
choice
!=
1
&&
choice
!=
0
&&
choice
!=
2
);
if
(
choice
==
0
)
else
if
(
moveResult
==
0
)
{
{
printf
(
"
\n
Väljun...
\n
"
);
gameState
=
0
;
return
0
;
}
}
else
if
(
choice
==
2
)
else
if
(
moveResult
==
1
)
{
{
DisplayGameRules
();
if
(
defeatedEnemies
<
NUM_HENCHMEN
)
{
Enemy
enemy
=
CreateEnemy
(
defeatedEnemies
);
printf
(
"
\n
Vastane 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
(
"
\n
Vastane 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
==
1
)
defeatedEnemies
++
;
levelUp
(
&
player
);
}
}
break
;
}
case
2
:
DisplayGameRules
();
break
;
case
3
:
{
{
int
gameState
=
1
;
int
gameState
=
1
;
Player
player
=
CreatePlayer
();
Player
player
;
int
defeatedEnemies
=
0
;
int
defeatedEnemies
;
LoadGame
(
saveFile
,
&
player
,
&
defeatedEnemies
);
while
(
gameState
==
1
)
while
(
gameState
==
1
)
{
{
int
moveResult
=
Move
(
defeatedEnemies
);
int
moveResult
=
Move
(
defeatedEnemies
);
if
(
moveResult
==
LOSE_HP
)
if
(
moveResult
==
-
10
)
{
// Player encountered a trap
{
// Player encountered a trap
handleTrap
(
&
player
);
handleTrap
(
&
player
);
continue
;
// Restart the loop, allowing the player to choose the path again
continue
;
// Restart the loop, allowing the player to choose the path again
}
}
if
(
defeatedEnemies
<
NUM_HENCHMEN
)
{
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
);
Enemy
enemy
=
CreateEnemy
(
defeatedEnemies
);
printf
(
"
\n
Vastane tüübiga %s, %dHP ja rünnaku tugevusega"
printf
(
"
\n
Vastane tüübiga %s, %dHP ja rünnaku tugevusega"
" %d on loodud.
\n
"
,
enemy
.
type
,
enemy
.
health
,
enemy
.
attack
);
" %d on loodud.
\n
"
,
enemy
.
type
,
enemy
.
health
,
enemy
.
attack
);
gameState
=
fight
(
&
player
,
&
enemy
);
gameState
=
fight
(
&
player
,
&
enemy
);
}
else
{
}
else
{
// Generate the final boss
// Generate the final boss
FinalBoss
boss
=
CreateFinalBoss
(
defeatedEnemies
);
FinalBoss
boss
=
CreateFinalBoss
(
defeatedEnemies
);
printf
(
"
\n
Vastane tüübiga %s, %dHP ja rünnaku tugevusega"
printf
(
"
\n
Vastane tüübiga %s, %dHP ja rünnaku tugevusega"
" %d on loodud.
\n
"
,
boss
.
type
,
boss
.
health
,
boss
.
attack
);
" %d on loodud.
\n
"
,
boss
.
type
,
boss
.
health
,
boss
.
attack
);
gameState
=
bossFight
(
&
player
,
&
boss
);
gameState
=
bossFight
(
&
player
,
&
boss
);
}
}
if
(
gameState
==
0
)
{
if
(
gameState
==
0
)
return
0
;
{
return
EXIT_SUCCESS
;
}
if
(
gameState
==
SAVE_GAME
)
{
SaveGame
(
saveFile
,
&
player
,
defeatedEnemies
);
return
EXIT_SUCCESS
;
}
}
defeatedEnemies
++
;
defeatedEnemies
++
;
levelUp
(
&
player
);
levelUp
(
&
player
);
}
}
}
}
break
;
}
case
0
:
printf
(
"VÄLJUN...
\n\n
"
);
return
EXIT_SUCCESS
;
}
}
return
0
;
return
0
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment