Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+13 votes

Hey everyone, I'm working on the practice test that is on Moodle and I'm stuck on the last question (race car problem). I have everything working in my code expect for the part that is supposed to display a message declaring who won at the end of the race. I thought to display text you had to draw it onto the window (which is what I wrote in my code), but I'm starting to think that because draw() is a method in the Car class, that is why it's not working. Can someone let me know if that is what's happening? And if so, how do I fix it? Thank you!

asked in CSC201 Spring 2021 by (1 point)
+1

Hmmm... to display some text, you DO need to create a Text(...) object and draw it in the Window.

Maybe you should post some of your code, so people can give more helpful feedback?

After pasting in code, make sure to highlight it all, and click the { } button on the toolbar to format it all as code.

+2

I first had the following if/elif statements in my while loop, and then I tried taking them out of the while loop to see If that would fix it. Both ways didn't work. Maybe it's something in my getFrontX() method?

if car1.getFrontX() == WINDOW_WIDTH:
   message = Text(Point(WINDOW_WIDTH/2, WINDOW_HEIGHT/2), "Red car wins!")
   message.setSize(10)
   message.draw(window)
elif car2.getFrontX() == WINDOW_WIDTH:
   message = Text(Point(WINDOW_WIDTH/2, WINDOW_HEIGHT/2), "Blue car wins!")
   message.setSize(10)
   message.draw(window)
elif car1.getFrontX() == WINDOW_WIDTH and car2.getFrontX() == WINDOW_WIDTH:
   message = Text(Point(WINDOW_WIDTH/2, WINDOW_HEIGHT/2), "It's a tie!")
   message.setSize(10)
   message.draw(window)
+1

Sorry about the format of the code, I think I messed it up after I pressed the {} button!

Please log in or register to answer this question.

...