Computer Science Canada Game won't run. |
Author: | Lekegolo killer [ Mon May 11, 2009 11:18 am ] | ||
Post subject: | Game won't run. | ||
What is it you are trying to achieve? I am trying to get my game to run properly. What is the problem you are having? My game stops halfway through and just displays the white background with the green scoreboard. Describe what you have tried to solve this problem I thought it might be the location of the View.UpdateArea, or the exit command in the second loop, but i have no idea how i would correct this. Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Please specify what version of Turing you are using I have no Idea. Any help you guys can give me would be greatly appreciated. |
Author: | DemonWasp [ Mon May 11, 2009 11:47 am ] | ||
Post subject: | RE:Game won\'t run. | ||
You seem to be using View.UpdateArea to update the entire screen, but with hard-coded (specified in your code) values. I recommend you switch these to View.Update calls, which automatically update the whole screen. Secondly, your list of conditionals on x1, x2, y1 and y2 can be more easily done by changing your randomisation (and you should probably use Rand.Int too - it's a little clearer). Specifically, you want: 1. x2 is larger than x1 and y2 is larger than y1 2. x1 and y1 are each at least 50 (this combines with #1 to give x2 > 50 and y2 > 50 3. The differences x2-x1 and y2-y1 are at least 5 and at most 150. 4. x1 and x2 are both less than 800 while y1 and y2 are both less than 600. So if we want to find x1, we know that the only valid values are 50 to 795. Why? Because rule 2 says "at least 50" and rule 3 combines rule 4 to show that if x2 is its maximum (800) then x1 must be at most 795. Similarly for y1, only the upper limit is 595. Once we have x1 and y1, we can find x2 and y2 from their values. We know that x2 is at least x1+5 and at most 800, while y2 is at least y1+5 and at most 600. So we can replace that whole randomisation / if mess with this:
Of course, you can do even better if you keep around variables for the size of the screen and use those instead of the "magical" numbers 795 and 595. The actual problem with your existing code is that you're not re-randomising at each iteration of the loop. You generate x1,x2,y1,y2 once, then check, check, check, check ... you get the point. |
Author: | Lekegolo killer [ Tue May 12, 2009 10:12 am ] |
Post subject: | Re: Game won't run. |
Wow I feel stupid. Thank you very much, I will be sure to put you in the credits. |
Author: | DemonWasp [ Tue May 12, 2009 10:41 am ] |
Post subject: | RE:Game won\'t run. |
Don't feel stupid. Everyone is going through the learning process, everyone has felt kind of stupid when someone further along pointed out a better way of doing things. Eventually you'll be the one making people feel stupid. Instead, feel glad that you're not alone ![]() |