Computer Science Canada Grade 10 ICS Summative - Minesweeper |
Author: | Nathan4102 [ Sat Jul 06, 2013 4:48 pm ] | ||
Post subject: | Grade 10 ICS Summative - Minesweeper | ||
Hey guys, This is my final summative for grade 10 ICS this year. The task was to make a game, with most people doing a graphical Rock Paper Scissors. I'm really only posting this to see what I could improve on in my code, but I'll post the full package aswell so you can try it out. Let me know what you think of it! Note: There is a cheat constant at the top of the program used for bug testing. If all the cells are highlighted, thats why! Code:
|
Author: | Raknarg [ Sat Jul 06, 2013 10:07 pm ] | ||
Post subject: | RE:Grade 10 ICS Summative - Minesweeper | ||
Just a cool way to write findzeroes: Recursion!
|
Author: | Raknarg [ Sat Jul 06, 2013 10:09 pm ] |
Post subject: | RE:Grade 10 ICS Summative - Minesweeper |
Also, for the purpose of this game, I think it'd be cool if you learned to make your own buttons |
Author: | Nathan4102 [ Mon Jul 08, 2013 3:55 pm ] |
Post subject: | RE:Grade 10 ICS Summative - Minesweeper |
What do you mean by the buttons? Like make a full button class or something? Im not using the GUI.Button buttons, so I kind of made my own! |
Author: | Zren [ Mon Jul 08, 2013 4:05 pm ] | ||||||||||||||
Post subject: | RE:Grade 10 ICS Summative - Minesweeper | ||||||||||||||
Use constants for the number of rows/coloumns instead of hardcoding the ranges. This way you could later abstract away difficulty/size. Seeing as you used an uncommon number (16), you could probably get away with a Find/Replace.
What are these (-3, 28, -5, 26) magic numbers you're pulling out of your hat? You use 25 a lot. Is that the size of each cell? If so, make it a constant.
These are pure evil. There is no situation where you want a fake loading screen. Ever. If there isn't a noticeable pause during code execution (that isn't caused from loading the Turing environment), then perish the thought. Some of the best games are those without an actual loading screen. Instead of forcing a pause on the user, try animating static menus/screens. ~
There's no point in doing 8 comparisons against x and y if button isn't pressed. This might be inconsequential in code this small, but getting in the habit is good.
Perhaps you should expand on what you were trying to achieve with lastbutton. The following is a little code snippet that works for a single button. You'd have to expand on it to get it working for multiple buttons, but it's the same concept of looking at the previous state.
There's a much better way of doing this. Look into div and mod. Note how you divide milliseconds by a 1000 to get the number of seconds, but the remainder of that division aught to be the number of milliseconds.
The div operation will return an integer, so the rounding is pointless. |
Author: | Raknarg [ Mon Jul 08, 2013 4:37 pm ] |
Post subject: | RE:Grade 10 ICS Summative - Minesweeper |
I was thinking more teaching him classes |
Author: | Nathan4102 [ Mon Jul 08, 2013 6:35 pm ] |
Post subject: | Re: RE:Grade 10 ICS Summative - Minesweeper |
"What are these (-3, 28, -5, 26) magic numbers you're pulling out of your hat? " To be honest, I don't remember where those numbers came from... I wrote this a couple months ago, just forgot to post it. I'm sure they have some sort of meaning though! "You use 25 a lot. Is that the size of each cell? If so, make it a constant. " 25 is the width/height of a cell, so in the future, Ill use constants for these things "These are pure evil. There is no situation where you want a fake loading screen. Ever. If there isn't a noticeable pause during code execution (that isn't caused from loading the Turing environment), then perish the thought. Some of the best games are those without an actual loading screen. Instead of forcing a pause on the user, try animating static menus/screens. " I know that these aren't very practicial, and I probably shouldn't use them in real programs. My class had this weird thing with fake loading screens though, every single one of us added one. It kind of makes it look like you have a complex program! "There's no point in doing 8 comparisons against x and y if button isn't pressed. This might be inconsequential in code this small, but getting in the habit is good. " Thats a good point, I should have just checked if button = 1 first, and then check all the other stuff. "The following is a little code snippet that works for a single button. You'd have to expand on it to get it working for multiple buttons, but it's the same concept of looking at the previous state. " It kind of looks just like what I've used, except it checks when the mouse is released. I'm not sure why I didn't do that "There's a much better way of doing this. Look into div and mod. Note how you divide milliseconds by a 1000 to get the number of seconds, but the remainder of that division aught to be the number of milliseconds." That could have shortened that code quite a bit... thanks! Thanks for all the suggestions Zren! And Raknarg, I'll learn classes one day! |
Author: | Raknarg [ Mon Jul 08, 2013 6:52 pm ] |
Post subject: | RE:Grade 10 ICS Summative - Minesweeper |
Don't wait. They can help a lot in the future and they'll impress people For me it was kindof like arrays, at first I didn't understand them or why they were useful. ONce things clicked into place, I started realizing how useful they really were and coming up with all these applications for them. I had the same epiphany when I learned how to use classes. |
Author: | Nathan4102 [ Mon Jul 08, 2013 6:55 pm ] |
Post subject: | RE:Grade 10 ICS Summative - Minesweeper |
I remember learning arrays, it made everything SOO much easier! I was supposed to be learning a language this summer, so I'll learn arrays when I get into a language. |
Author: | Raknarg [ Mon Jul 08, 2013 7:01 pm ] |
Post subject: | RE:Grade 10 ICS Summative - Minesweeper |
http://processing.org/ Same feel as turing, power and syntax like java. More dynamic. |
Author: | Nathan4102 [ Mon Jul 08, 2013 7:41 pm ] |
Post subject: | RE:Grade 10 ICS Summative - Minesweeper |
I considered looking into that earlier, but I'm starting java in school next month anyways, so is it really worth learning this? |
Author: | Raknarg [ Mon Jul 08, 2013 8:21 pm ] |
Post subject: | RE:Grade 10 ICS Summative - Minesweeper |
I would say so. First, it's not the same. It's a lot easier to deal with (I find), and plus getting an early start with a java like environment means less potential headaches in the future. Gives you more time to learn finer details instead of just the basics. Before processing, I used Turing for most of my programs, when I wanted to test anything or do any small projects. Now, i can just use Processing, which is easier to use in a lot of ways and much, much more powerful. |
Author: | BrookeTookie [ Mon May 26, 2014 9:48 am ] |
Post subject: | RE:Grade 10 ICS Summative - Minesweeper |
Why are the mines coloured purple and not grey like the rest? so the user cant tell which cell has a mine or not. |
Author: | Nathan4102 [ Mon May 26, 2014 2:33 pm ] |
Post subject: | RE:Grade 10 ICS Summative - Minesweeper |
Change constant "CHEAT" at the top to false. True is debug mode, and shows where the mines are located. |