Computer Science Canada Rudimentary turing gmae |
Author: | TipsyCzar [ Thu Nov 10, 2016 12:18 pm ] |
Post subject: | Rudimentary turing gmae |
This is a game I made for a computer science class. It's supposed to take the base principal of Duck hunt (use mouse and graphics VS just text). Tell me what you think of it and what needs work. If possible, look at the code and see if the indent needs work. |
Author: | Insectoid [ Fri Nov 11, 2016 9:52 am ] | ||||||
Post subject: | RE:Rudimentary turing gmae | ||||||
It's funny you asked about the indent because it definitely needs work. That's some crazy unnecessary nesting you've got going on there. Fortunately it's an easy fix. Load up Turing, open your file, and press F2. There, fixed. The automatic indenting will give you the proper indentation. There's no need to come up with your own complicated system. If everyone uses the auto-indent, then everyone's indentation is the same, and everyone can easily read each others' code. Now that we can read this file, take a look at your variable declarations:
Holy moly, what a mess. Fourteen variables! What the heck do you need so many for? I'm seeing a pattern here- maybe we can come up with a mathematical function that just gives us the value we want. Can you think of a formula f(n) where f(1) = 3000, f(2) = 2800, f(2) = 2600, etc? Doing this will save you ~40 lines of code. Now let's look at this part:
Holy smokes, fourteen sets of coordinates! Why? There's only one box on the screen at a time! Why do we need to keep track of fourteen things? Instead of having 14 boxes that pop up and disappear, why not just have one box that moves around? Instead of 14 sets of coordinates, just have one set of coordinates and change it fourteen times. Doing this will save you ~50 lines of code. And now look at this:
You repeat this code 14 times and the only things that change are x1, y1 and delay1. But you just changed your code so there's only one set of x and y coordinates and only one delay right? And if those are the only things that changed, then we now have 14 identical pieces of code! And if we have 14 identical pieces of code, then we can just delete 13 of them and throw the other one in a loop! This saves us a whopping ~180 lines of code! You posted ~360 lines of code, not including blank lines. We're knocking out ~270 of them, which leaves us with 90 lines. 360, to 90. That's a 75% reduction in code size, and a 100% increase in readability, just by eliminating repeated code. Repeated code is generally not a good thing. Makes things messy and hard to edit. Any time you see code that looks the same or nearly the same, see if you can eliminate all the extras and bring it down to just one copy. This will often massively reduce the size of your file and make it much, much easier to edit and debug. |