Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cpp-project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
David Maul
cpp-project
Commits
8d77c11b
Commit
8d77c11b
authored
5 months ago
by
Lorenz Martin Diel
Browse files
Options
Downloads
Patches
Plain Diff
first integration of XML to units
parent
325cecb3
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/unit.cpp
+55
-14
55 additions, 14 deletions
src/unit.cpp
with
55 additions
and
14 deletions
src/unit.cpp
+
55
−
14
View file @
8d77c11b
...
@@ -76,7 +76,7 @@ namespace advanced_wars
...
@@ -76,7 +76,7 @@ namespace advanced_wars
MatchupTabel
damageMatrix
;
MatchupTabel
damageMatrix
;
std
::
vector
<
Unit
*>
units
;
std
::
vector
<
Unit
*>
units
;
/*
void Unit::attack(Unit& enemy) {
void Unit::attack(Unit& enemy) {
int offDamage = 50;
int offDamage = 50;
...
@@ -88,6 +88,47 @@ namespace advanced_wars
...
@@ -88,6 +88,47 @@ namespace advanced_wars
this->health = this->health - defDamage;
this->health = this->health - defDamage;
std::cout << "Health ally:" << this->health << std::endl;
std::cout << "Health ally:" << this->health << std::endl;
}
}
}*/
void
Unit
::
attack
(
Unit
&
enemy
)
{
// Zuerst die Tabel für die primäre Waffe der angreifenden Einheit holen
auto
&
attackerSecondaryWeaponTable
=
secWeapon
[
id
];
// Schadenswert für die angreifende Einheit gegen die verteidigende Einheit berechnen
if
(
attackerSecondaryWeaponTable
.
find
(
enemy
.
id
)
!=
attackerSecondaryWeaponTable
.
end
())
{
int
attackerDamageValue
=
attackerSecondaryWeaponTable
[
enemy
.
id
];
// Berechne den Schaden in Abhängigkeit der Gesundheit der angreifenden Einheit
int
offDamage
=
attackerDamageValue
*
(
static_cast
<
float
>
(
health
)
/
max_health
);
// Schaden auf den Gegner anwenden
enemy
.
health
-=
offDamage
;
std
::
cout
<<
"Enemy health after attack: "
<<
enemy
.
health
<<
std
::
endl
;
// Prüfen, ob der Gegner noch am Leben ist um zurückzuschlagen
if
(
enemy
.
health
>
0
)
{
// Tabelle für die primäre Waffe der verteidigenden Einheit holen
auto
&
defenderSecondaryWeaponTable
=
secWeapon
[
enemy
.
id
];
if
(
defenderSecondaryWeaponTable
.
find
(
this
->
id
)
!=
defenderSecondaryWeaponTable
.
end
())
{
int
defenderDamageValue
=
defenderSecondaryWeaponTable
[
this
->
id
];
int
defDamage
=
defenderDamageValue
*
(
static_cast
<
float
>
(
enemy
.
health
)
/
enemy
.
max_health
);
// Schaden auf die angreifende Einheit anwenden
this
->
health
-=
defDamage
;
std
::
cout
<<
"Ally health after retaliation: "
<<
this
->
health
<<
std
::
endl
;
}
}
}
else
{
std
::
cerr
<<
"No damage value found for attack from unit "
<<
static_cast
<
int
>
(
id
)
<<
" against unit "
<<
static_cast
<
int
>
(
enemy
.
id
)
<<
std
::
endl
;
}
}
}
void
Unit
::
update_position
(
int
posX
,
int
posY
)
void
Unit
::
update_position
(
int
posX
,
int
posY
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment