Today I arrived to class knowing that I would have to solve the problem from last class.
I went on greenfoot.com and tried to find a solution but I couldn't find it.
I then went on to call Mr. Daly and we worked together on it. I told him that the program only worked the first time, and then never again. He told me to put , instead of lettuceEaten == 30, to make it >= 30, which means greater than or equal to 30. That worked at the beginning, and then without resetting it, we went on, and the game stopped after turtles ate one lettuce. We were confused... and then Mr. Daly managed to figure out what the problem was. When I first started Greenfoot, everything started from 0, including the counter. The program worked the first time, and it stopped after eating 6. But we learned that even once we resetted the game, the counter would continue from last game, meaning it didn't stop because it was always more than 30 and never actually equal to it. When we changed the == to >=, it stopped after each lettuce eaten because that lettuce counted + the lettuce from last game played, which equalled 35 ( which is more than 30) and so the game stopped.
What Mr. Daly told me to do was to add a line of code that looked like this:
public Turtle ()
{
points = 0;
}
This told the system: every time that we restart a game, reset the counter to 0. And that turned out to be the solution.
About 10 minutes later, Tommy taps me on the shoulder and says listen to this. It was a video and Michael Kolling was coding something that included variables, and he mentions for 3 seconds that the == had been a problem and that we should put >= instead. I was a bit frustrated to hear that after having spent a class and a half trying to solve that problem.
After we had found that solution to the problem, I went back to work. I started to fix a few things, such as the number of lettuces that actually had to be eaten for the game to finish, and I added a few sounds to my code as I didn't like the ones that Michael suggested we put in.
Towards the end of class, I watched a video that explained how to add another bug, and once a bug was eaten, another one would automatically be put into the world. I found that video a bit confusing, so I will re watch it over the weekend to get a better understanding. But apart from that, the video gave me an idea for my game:
I will add babies to the world. These babies do not eat anyone, and they just move randomly across the world. The point of the game is still the same: for the snake to eat all the turtles before the turtles eat all the lettuce- but now, there will be babies in the world. If a snake passes a baby, it will eat it automatically, but he must NOT do that. If a snake eats a baby, I will program for a deduction of points, and the addition of a new turtle into the world. So if by accident the snake eats the baby, then the player will lose points and the game will become harder by a new turtle coming in to the world to eat the lettuce.
Next class, I hope to be able to develop this game idea even more.
No comments:
Post a Comment