#C++ - Stuck on task 5 of Ellen's Alien Game

57 messages · Page 1 of 1 (latest)

old robin
#

Hello there everyone, in the Classes exercise Ellen's Alien Game, I can't figure out a way to compare 2 Aliens Classes Objects. I've asked around with friends that know about programming, but they give out answers that use for loops, arrays and vectors. I know the array and vectors comes after, but the for loops is on the same level, should I do the for loops first then the classes after? (The tips on the task 5 doesn't mention anything too).

Thanks for everything!

winter moon
#

The exercise doesn't ask you to do anything with loops nor to write a comparison function.

#

The collision function needs to check if two objects have the same coordinates.

#

What needs to be true for two objects to have the same coordinates?

old robin
#

for 2 objects have the same coordinates

#

ops

#

sorry i misread

winter moon
#

👍

old robin
#

but how to call objects

#

i'm kinda lost

winter moon
#

"call" objects?

old robin
#

i mean

#

the exercise give the Alien lrrr and Alien ndnd

#

how do I check their coordinates?

#

if they doesn't exist yet

#

while I write the code

#

thats im kinda lost

winter moon
#

How do you check if the alien is alive if the alien doesn't exist when you write the code?

old robin
#

if their health is > 0

winter moon
#

Classes can have member variables and member functions. They are accessed by the member selection operator ..

#

Check if the coordinates of the two are the same

#

Logically, how would you check if the coordinates are the same?

old robin
#

if 2 aliens have the same x and y

winter moon
#

Do you know how to access the x and y of the two aliens?

old robin
#

calling the alien class?

#

like Alien(int x, int y) ?

winter moon
#

That creates a new Alien

#

How do you access the health of the alien?

old robin
#

get_health() command

winter moon
#

How does get_health() access the health of the alien?

old robin
#

sorry if I'm being kinda dumb btw

#

return health

winter moon
#

So you can directly access the health variable, right?

old robin
#

yes

winter moon
#

And you can do the same for the coordinates?

old robin
#

yes

winter moon
#

So that's how you'd get the "self" Alien coordinates, right?

old robin
#

return x_coordinates?

winter moon
#

...without a return.

#

And you can use the . to access attributes of the other Alien

old robin
#

im going to try something here, I will return if I did it soon

#

thanks very much

winter moon
#

Good luck

old robin
#

I passed

#

i will try adding the y_coordinate just to be more correct

winter moon
#

Hah. I'm surprised the tests let you pass by checking only the x

old robin
#

welp, at least you know it can get fixed hahah

winter moon
#

Please use codeblocks and not images to share code. Some people have a hard time reading pixels.

old robin
#

oh

#

ok

#

sorry

#

but thanks very much

winter moon
#

No worries. Live and learn!

old robin
#

and sorry for being kinda thick skulled also

winter moon
#

You're very welcome

#

We all had to learn it at some point!