write the following for loop as a while loop

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter6: Looping
Section: Chapter Questions
Problem 5GZ
icon
Related questions
Question

write the following for loop as a while loop 

shoot
12/14
bool Player:shoot(int dir)
{
m_age++;
if (rand() % 3 == 0) // miss with 1/3 probability
{
return false;
}
else if (dir == UP)
{
for (int i = 0; i < MAXSHOTLEN + 1; i++)
{
if (m_arena->nRobotsAt(m_row - i, m_col) > 0 && m_row - i > 0)
{
m_arena->damageRobotAt(m_row - i, m_col);
return true;
}
}
}
>
Transcribed Image Text:shoot 12/14 bool Player:shoot(int dir) { m_age++; if (rand() % 3 == 0) // miss with 1/3 probability { return false; } else if (dir == UP) { for (int i = 0; i < MAXSHOTLEN + 1; i++) { if (m_arena->nRobotsAt(m_row - i, m_col) > 0 && m_row - i > 0) { m_arena->damageRobotAt(m_row - i, m_col); return true; } } } >
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT