Question: I ' m writing a call function in a C + + program and most of it is done. Its function is to complete battles
Im writing a call function in a C program and most of it is done. Its function is to complete battles between adjacent letters in a D map matrix.
I hope that if the final health of the target letter is reduced to or less, the target letter will be replaced by the attacking letter, and the attacker's original position will be Replacement.
If the final health of the target letter is greater than both positions remain unchanged.
Please help me check the following call function and make it possible for it to fulfill the above requirements.
StatusFightAction updateMapAndHealthPointsForFightActionint healthPointsMAXNUMWARRIORS
char mapMAXROWSMAXCOLS
int mapRows, int mapCols,
const int fightPointsMAXNUMWARRIORS
char letter,
DirectionType direction,
char &targetLetter,
int &targetOriginalHealthPoint,
int &targetUpdatedHealthPoint
int attackerIndex letter; Assuming letters map to indices like AB
int attackerFP fightPointsattackerIndex; Attacker's fight points
Step : Find the position of the attacker letter in the map
int attackerRow attackerCol ;
for int i ; i mapRows; i
for int j ; j mapCols; j
if mapij letter
attackerRow i;
attackerCol j;
break;
if attackerRow break; Exit once attacker is found
If attacker not found in the map, return invalid status
if attackerRow attackerCol
return STATUSACTIONFIGHTNOTIMPLEMENTED;
Step : Determine the target position based on the direction
int targetRow attackerRow, targetCol attackerCol;
switch direction
case DIRECTIONNORTH: targetRow attackerRow ; break;
case DIRECTIONSOUTH: targetRow attackerRow ; break;
case DIRECTIONWEST: targetCol attackerCol ; break;
case DIRECTIONEAST: targetCol attackerCol ; break;
Check if the target position is within the bounds of the map
if targetRow targetRow mapRows targetCol targetCol mapCols
return STATUSACTIONFIGHTFAIL; Out of bounds
Step : Check if the target is a valid warrior must be a letter
char potentialTarget maptargetRowtargetCol;
if potentialTarget potentialTarget A potentialTarget Z
return STATUSACTIONFIGHTFAIL; No valid target
Step : Update the health points of the target
int targetIndex potentialTarget A; Convert target letter to index
targetLetter potentialTarget;
targetOriginalHealthPoint healthPointstargetIndex;
targetUpdatedHealthPoint targetOriginalHealthPoint attackerFP;
Update the health points array
healthPointstargetIndex targetUpdatedHealthPoint;
Step : Check if target's health reaches zero or below
if targetUpdatedHealthPoint
maptargetRowtargetCol;
targetUpdatedHealthPoint ; Target defeated, update map
return STATUSACTIONFIGHTSUCCESS;
return STATUSACTIONFIGHTSUCCESS;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
