Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Computer Science Final Project Simon Says Game
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Gaming Lyfe




PostPosted: Fri Dec 16, 2016 7:36 pm   Post subject: Computer Science Final Project Simon Says Game

A game I made that took a long ass time but not that long. The answering is kind of buggy (ie. if u put "g" as all your answers even though you should only be choosing colors, it might give you 1 or 2 correct). You will see what I mean. However it generally works very well.


Comp Sci ISP Final Version 8 Colors.t
 Description:

Download
 Filename:  Comp Sci ISP Final Version 8 Colors.t
 Filesize:  58.24 KB
 Downloaded:  382 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Sat Dec 17, 2016 9:47 am   Post subject: RE:Computer Science Final Project Simon Says Game

My god, two thousand lines of code for Simon Says? I'm glad I'm not marking this!

2000 lines is a hell of a lot of code! I guarantee every single bug in this program comes from having way too much code. You can't possibly debug this. There's no way. Your funky wrong answers bug is almost certainly a typo somewhere, but I'll be damned if I'm going to sift through that much stuff to find it, and I'm sure you feel the same way!

That much code is bad. Let's fix it!

simonsays1 looks like your first truly monstrous procedure. You're gonna wanna change that procedure name, by the way. 'simonsays1' doesn't tell me anything about what this chunk of code actually does, and since it's hundreds of lines long, I can't even read the code to figure it out!

The first thing I notice is you have a ton of similar variables- coloring1, coloring2, cont1, cont2, etc. These generally work a lot better as arrays.

var coloring : array 1..8 of int
var cont1 : array 1..8 of int

You've used arrays elsewhere in your code, so I dunno why you didn't use them here. Any time you see numbered variables like that, it should be an array (or similar data structure). Every single time. You will never, at this stage of the game, have a legitimate reason to have numbered variables like you've done here. It's bad news and will cause bugs.


The next thing I see is giant crazy loops. There's no comments saying what they do and I can't figure it out. If I was your teacher, I'd give you a failing mark for that alone. Comment your code!

Inside those crazy giant nested loops are ridiculous giant if statements dealing with coloring1 and col1. I'm not 100% sure, but it looks like you're trying to pick a random color. There is an easier way. You've got eight colors corresponding to the numbers 1 through 8. Hang on, don't we have a convenient data structure that stores things in a list? Oh yeah, an array! Let's chuck all these colors in an array!

var colors : array := init {14, 12, 10, 13, 35, 42, 76}

Now to pick a random color, just pick a random number from that array!

var color := colors (Math.Random (1, 8))

Now instead of 18 lines of code, we only used two!

Further down, we have another giant if statement. I dunno what it's doing, but I can see that all of the elsifs are almost identical. Maybe we can toss all the identical stuff into a function?
code:

proc a (x : int, y : int) % I'd use a better proc name, but I don't know what this does so I can't.
    drawfill (x, y, coloring1, black)
    delay (1000)
    drawfill (x, y, coloring1, black)
    cont1 += 1
end a



And you call it like this:

if randSpace = 1 then
a (425-79, 225+24)
elsif randSpace = 2 then %etc

We've saved a ton more space doing this. But wait! There's more! Further down, I see code nearly identical to the coloring1 code I looked at earlier! By this point the code is already way too complex for me. I don't have the patience to sort through two thousand lines. But you could use the practise. I guarantee this program can be reduced to less than 100 lines (that's a 95% reduction in code). Any time you see big chunks of code that look almost identical, you should be able to rewrite it as a function or a procedure, reducing the amount a code and increasing the legibility.

By the way, it's pretty likely that all of your bugs are due to typos and you couldn't fix them because it's hard to find typos in 2000 lines of code. Reducing your code in the way I've described will involve deleting those typos, which has the side-effect of fixing your bugs for free!

Reduce your code as much as you can (don't worry if you get stuck) and post it back here. I'll take a look and give you more suggestions for improvement.
Gaming Lyfe




PostPosted: Tue Dec 20, 2016 9:17 pm   Post subject: RE:Computer Science Final Project Simon Says Game

Thanks! This was a total pain in the ass and I just figured the easiest way was to copy/paste code and just do the same thing for each color section. But you are right about WAYYYY to much coding. I just looked at it after a year, and I had no idea what was going on. I am sure I can easily reduce the code. Thanks! (Other than the code, how is the game in terms of function?)
Insectoid




PostPosted: Wed Dec 21, 2016 4:49 pm   Post subject: RE:Computer Science Final Project Simon Says Game

You said it yourself, it's buggy. In terms of function, it doesn't work. In terms of gameplay, well, it's Simon Says. There is no gameplay. I'm not really interested in critiquing the design, only the code that implements it.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: