![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#41 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 825
Rep Power: 4
![]() |
Yep, that looks right, aside from indenting and extra brackets (which are personal preference), its exactly how I would have done it.
|
|
|
|
|
|
#42 |
|
Hobbyist Programmer
Join Date: Nov 2006
Posts: 111
Rep Power: 2
![]() |
Oops, m_sources, m_nsources are indeclared.
Also this error: left of '->col' must point to class/struct/union/generic type ![]() -'m_nsources' : undeclared identifier -'m_sources' : undeclared identifier -error C2227: left of '->col' must point to class/struct/union/generic type -left of '->row' must point to class/struct/union/generic type - 'energySourceAt' : modifiers not allowed on nonmember functions |
|
|
|
|
|
#43 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 825
Rep Power: 4
![]() |
Change
bool energySourceAt(int r, int c) const bool Valley::energySourceAt(int r, int c) const |
|
|
|
|
|
#44 |
|
Hobbyist Programmer
Join Date: Nov 2006
Posts: 111
Rep Power: 2
![]() |
Alright, I get the change. My next step is not working, I try to build on an idea, now that I have energySourceAt working.
The following fills the grid with dots, and my TODO is to place * at every energy source. Why don't this work? // fill the grid with dots
for (r = 0; r < NROWS; r++)
for (c = 0; c < NCOLS; c++)
{
grid[r][c] = '.';
if (energySouceAt(r,c))
grid[r][c] = '*';
}The red is an error. I'm saying ' if there's an energy source at (r,c)', then replace that dot with a *. |
|
|
|
|
|
#45 | |
|
Expert Programmer
Join Date: Jun 2005
Posts: 825
Rep Power: 4
![]() |
Quote:
energySourceAt. |
|
|
|
|
|
|
#46 |
|
Hobbyist Programmer
Join Date: Nov 2006
Posts: 111
Rep Power: 2
![]() |
Oops
But this doesn't compile well either:// If as a result of the attempt to move, the robot is at an energy // source, it's recharged to the FULL_ENERGY level. if (energySourceAt(m_row, m_col)) m_energy = FULL_ENERGY; This is under the Robot:step() |
|
|
|
|
|
#47 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 825
Rep Power: 4
![]() |
The energySourceAt method is a method of Valley, so you must call it either from within another Valley method or using -> or . with a valley object.
The robot has a pointer to the Valley it is in in the m_valley member variable. |
|
|
|
|
|
#48 | ||
|
Hobbyist Programmer
Join Date: Nov 2006
Posts: 111
Rep Power: 2
![]() |
Quote:
Quote:
|
||
|
|
|
|
|
#49 |
|
Hobbyist Programmer
Join Date: Nov 2006
Posts: 111
Rep Power: 2
![]() |
Never mind, how about this:
m_valley -> energySourceAt(m_row, m_col) |
|
|
|
|
|
#50 |
|
Hobbyist Programmer
Join Date: Nov 2006
Posts: 111
Rep Power: 2
![]() |
Yeah, that compiles so great!
Just wondering if .. Robot* otherRobotAt(Robot* rp) const
// If there is at least one robot (other than the one rp points to)
// at the same (r,c) coordinates as the one rp points to, return a
// pointer to the one of those other robots with the least amount
// of energy remaining (if there's a tie, any one of the tied robots
// will do); otherwise, return NULL.
//
{
}would follow the same idea as bool Valley::energySourceAt(int r, int c) const
{
for (int k = 0; k < m_nsources; k++)
{
if ((m_sources[k]->row()== r)
&& (m_sources[k]->col()== c))
return true;
}
return false;
} |
|
|
|
![]() |
| 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 |