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
3f871b72
Commit
3f871b72
authored
5 months ago
by
Max Cherris
Browse files
Options
Downloads
Patches
Plain Diff
Add function prototypes for combat, updating position and movement
parent
9df4dc5f
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/unit.cpp
+23
-1
23 additions, 1 deletion
src/unit.cpp
src/unit.hpp
+22
-1
22 additions, 1 deletion
src/unit.hpp
with
45 additions
and
2 deletions
src/unit.cpp
+
23
−
1
View file @
3f871b72
#include
"unit.hpp"
#include
"unit.hpp"
Unit
::
Unit
(
int
x
,
int
y
)
:
x
(
x
),
y
(
y
)
{};
Unit
::
Unit
(
std
::
string
name
,
int
health
,
int
speed
,
int
attack
,
std
::
pair
<
int
,
int
>
range
,
MovementType
movement
,
WeaponType
weapon
)
:
name
(
std
::
move
(
name
)),
health
(
health
),
speed
(
speed
),
attack
(
attack
),
range
(
range
),
movement
(
movement
),
weapon
(
weapon
)
{}
//TODO: IF necessary, implement scaling attack by remaining health
void
Unit
::
init_combat
(
Unit
defender
)
{
//Attacker gets first move, inflicts its damage upon the the defender
defender
.
setHealth
(
defender
.
getHealth
()
-
this
.
getAttack
());
//if defender survives, it gets to inflict its damage upon the attacker
if
(
defender
.
getHealth
()
>
0
)
{
this
.
setHealth
(
this
.
getHealth
()
-
defender
.
getAttack
());
}
else
{
//if ded, defender gets deleted
defender
.
~
Unit
();
}
}
void
Unit
::
update_position
(
int
posX
,
int
posY
)
{
this
.
setX
(
posX
);
this
.
setY
(
posY
);
}
This diff is collapsed.
Click to expand it.
src/unit.hpp
+
22
−
1
View file @
3f871b72
...
@@ -90,6 +90,27 @@ private:
...
@@ -90,6 +90,27 @@ private:
{{
MovementType
::
SHIPENGINE
,
TerrainType
::
STREET
},
999
},
{{
MovementType
::
SHIPENGINE
,
TerrainType
::
STREET
},
999
},
{{
MovementType
::
SHIPENGINE
,
TerrainType
::
WATER
},
1
}
{{
MovementType
::
SHIPENGINE
,
TerrainType
::
WATER
},
1
}
};
};
/*
The attacker will move towards the defender and thus initiate combat
@params Takes a reference to the defender
Will Update the health for both units
Attacker deals damage to the defender first
*/
void
init_combat
(
Unit
defender
);
/*
@params Takes the desired position of the unit and updates its values
*/
void
update_position
(
int
posX
,
int
posY
);
/*
This function needs to be able to determine the possible movement-paths the unit can take
MUST take into consideration that different units behave differently on certain terrain
MUST show all movements possible
*/
void
calculate_movement
();
};
};
#endif // UNIT_HPP
#endif // UNIT_HPP
\ No newline at end of file
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