![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#71 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 825
Rep Power: 4
![]() |
You also need to fix up your Valley:~Valley destructor to loop through the m_robots and m_sources arrays and delete them individually. Do not try to delete the arrays.
|
|
|
|
|
|
#72 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 825
Rep Power: 4
![]() |
In this code:
// If at this spot there's another robot whose energy level is 0,
// then if we have at least SHARE_THRESHHOLD units of energy,
// transfer SHARE_AMOUNT units to that other robot. (If there
// are two or more dead robots here, we donate to only one.)
// Return true, indicating the robot attempted to move.
Robot* otherRobot = m_valley->otherRobotAt(this);
if (otherRobot != NULL)
{
if ((m_energy > SHARE_THRESHHOLD))
{
m_energy -= SHARE_AMOUNT;
otherRobot-> m_energy = SHARE_AMOUNT;
return true;
}
} |
|
|
|
|
|
#73 |
|
Hobbyist Programmer
Join Date: Nov 2006
Posts: 111
Rep Power: 2
![]() |
1. I fixed up the switch statement, I think this would be more logical.
// Attempt to move one step in the direction we're currently facing.
// (E.g., to move north, decrement the row coordinate.) If we can't
// move in that direction, don't move.
switch (m_dir)
{
case NORTH:
// TODO: Move one step north, if possible.
if (m_row-- < 0 || m_row-- >= NROWS)
{
break; // do nothing don't move
}
m_row--; // otherwise, decrement row coordinate
break;
// TODO: Implement the other movements
case SOUTH:
if (m_row++ < 0 || m_row++ >= NROWS)
{
break;
}
m_row++;
break;
case WEST:
if (m_col-- < 0 || m_col-- >= NCOLS)
{
break;
}
m_col--;
break;
case EAST:
if (m_col++ < 0 || m_col++ >= NCOLS)
{
break;
}
m_col++
break;
default:
cout << " ***** Direction must be valid" << endl;
}
}2. I changed my destructor for valley too. I realizede that I hadn't deleted each element inside the array I allocated. So I fixed that. // TODO: Implement the destructor
// Delete any dynamically allocated objects held by the Valley.
Valley::~Valley()
{
for (int f = 0; f < m_nrobots; f++)
delete [] m_robots[f];
for (int g = 0; g < m_nsources; g++)
delete [] m_sources[g];
}3. Oops, forgot that. How's this now. Robot* otherRobot = m_valley->otherRobotAt(this);
if (otherRobot != NULL)
{
if ((otherRobot -> m_energy == 0) && (m_energy > SHARE_THRESHHOLD))
{
m_energy -= SHARE_AMOUNT;
otherRobot-> m_energy = SHARE_AMOUNT;
return true;
}
}
return true;
} |
|
|
|
|
|
#74 |
|
Hobbyist Programmer
Join Date: Nov 2006
Posts: 111
Rep Power: 2
![]() |
Never mind, The Dark. I fixed all my errors. I'll PM you the code if you want me to.
|
|
|
|
|
|
#75 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 825
Rep Power: 4
![]() |
Good job. Hope it all goes well.
I hope you got rid of a few of those "--"s in 1 and the "[]"s in 2. Its fun to watch those robots walk around. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Wierd compile Error. Need help please. | Keiyentai | Java | 7 | Aug 19th, 2006 1:35 AM |
| What is: "Oriented programming (OO)?" | BrinyCode | C++ | 12 | Nov 22nd, 2005 7:40 AM |
| Java programmers, game developers, artists, be ware! RPG game team is recruiting! | atcomputers.us | Paid Job Offers | 7 | Sep 25th, 2005 7:25 PM |
| User Input for Number Format | ericelysia1 | Java | 0 | Jul 21st, 2005 3:41 PM |
| Programmers Needed! Online Game | troy_eisert | C++ | 2 | Jan 29th, 2005 12:51 PM |