Is there a way to see the code for the tug of war bug game in Lesson 9 from Unit 6? I have a student that is creating a similar game and is struggling with how to code it to say if Player 1 or Player 2 is the winner.
There’s not a way to see that exact code for that puzzle. BUT! With some critical thinking, your student should be able to figure it out. They may also wish to review some lessons from Unit 3 as well as those from earlier in Unit 6 to get some ideas.
There are several ways to go about this so I’m not going to recommend one over the other, but I would have them explain to you how they know when a player has won the game. Is it when the bug reaches a certain part of the screen? Maybe that involves a getProperty() for the bug’s X or Y position. Or maybe there’s a hidden variable that’s initialized to 0 and gets incremented/decremented whenever one of the players pushes their button, and the screen change is triggered when that variable hits +/-100 (or some other value).
I would also ask them when the code should check whether a player has won – every button push? Every time something on the screen is clicked? Another time?
If they think through these questions and explain the answers to you (or, preferably, to their coding buddy), they should be able to figure it out.
Hope that helps. If you need more assistance, comment on here & we’ll follow up.