Computer Science Canada Array questions |
Author: | Nathan4102 [ Fri May 17, 2013 3:08 pm ] |
Post subject: | Array questions |
I'm making a minesweeper game for my summative, and I'm kind of stuck on something. What would be the most efficient way to store data for each individual cell(Click/Notclicked, number displayed, contains mine/doesn't)? I've taken a look at records, but i'm not sure if it'll work with what I need. Another possibility is a 2d array of strings, with each string containing info for the cell that could be dissected when needed, but if there's a better way, I don't want to get into all that string manipulation stuff. Thanks! Nathan |
Author: | Raknarg [ Fri May 17, 2013 3:15 pm ] | ||
Post subject: | RE:Array questions | ||
Sure, array of records would do just the trick. For instance, you could do this:
Lets say you wanted to see if the cell 45, 30 is clicked. You can call the variable there by calling: grid (45, 30).clicked So records in this case would be very useful. Not to mention, it's good to learn because it helps you understand the use of classes later (which are super useful, which you should aslo learn at some point soon) |
Author: | Nathan4102 [ Fri May 17, 2013 3:19 pm ] |
Post subject: | RE:Array questions |
Oh, sweet! I didn't think records would work with arrays, but if they do, I'll use them. I'll learn classes next year when I need them in ICS, for now, I'll stick with procedural programming. |
Author: | Raknarg [ Fri May 17, 2013 3:26 pm ] |
Post subject: | RE:Array questions |
gridData is a type the same way int or real are types, so they can be used in the same ways. You can result gridData, or take it in as a parameter if you want to |
Author: | Raknarg [ Fri May 17, 2013 3:28 pm ] |
Post subject: | RE:Array questions |
You don't have to wait btw. Do you code stuff for fun on your own time? |
Author: | Nathan4102 [ Fri May 17, 2013 3:32 pm ] |
Post subject: | RE:Array questions |
Man, I wish I knew about records earlier. I could have used them in some old projects. I usually have a couple projects going for fun, but my main focus is on schoolwork. |
Author: | Raknarg [ Fri May 17, 2013 3:34 pm ] |
Post subject: | RE:Array questions |
That happens all the time. Once i learned array, once I learned records, once I learned classes, or random algorithms |
Author: | Nathan4102 [ Fri May 17, 2013 3:41 pm ] |
Post subject: | RE:Array questions |
I'd like to learn classes, but I haven't seen any practical use of them where they are superior to procedures/functions! I tried learning about them once, but all this Dog.Bark and Dog.Walk stuff seemed pointless to me. |
Author: | Raknarg [ Fri May 17, 2013 3:47 pm ] |
Post subject: | RE:Array questions |
It's useful if you have things that are actual objects. They can have all their own variables, and do all their calculations within the class. For instance, have you ever tried making a button in turing? It's a tedious process, especially if you have more than one button. Hoever, you can create a class that handles everything for you. You want to know if the button is clicked? The class will perform calculations that are in the class, and call button -> is_clicked. You're done. Want to draw the button? button -> draw What if you have an entire page full of buttons? JUst call a procedure to initialize them all, and you're done. It's easy, and clean, and very useful. You can check this out if you want: http://compsci.ca/v3/viewtopic.php?t=30797 |
Author: | Nathan4102 [ Fri May 17, 2013 3:50 pm ] |
Post subject: | RE:Array questions |
Buttons are a pain in turing... I guess classes do have a use, but you can't use classes in turing, can you?? |
Author: | Raknarg [ Fri May 17, 2013 3:52 pm ] |
Post subject: | RE:Array questions |
Absolutely you can |
Author: | Nathan4102 [ Fri May 17, 2013 3:55 pm ] |
Post subject: | RE:Array questions |
![]() |
Author: | Raknarg [ Fri May 17, 2013 3:56 pm ] | ||
Post subject: | RE:Array questions | ||
super redundant,. but yeah |
Author: | Nathan4102 [ Fri May 17, 2013 4:02 pm ] |
Post subject: | RE:Array questions |
That's pretty neat... and confusing! Is that foo part necessary? or can you not call Word.set_s without it? |
Author: | Raknarg [ Fri May 17, 2013 4:06 pm ] | ||
Post subject: | RE:Array questions | ||
You can't do that. Class is pretty similar to the type thing we talked about earlier. This is like a template for what you want each pointer to hold (a pointer is a variable that uses the class, btw). We can set 100 variables to this class, and they'd all have the same functions, but we could make them different.
|
Author: | Nathan4102 [ Fri May 17, 2013 4:09 pm ] |
Post subject: | RE:Array questions |
Oh, now I see how classes can be really useful. I'll probably dive into this stuff when I learn Java sometime soon hopefully. Thanks for the advice and examples! |
Author: | Raknarg [ Fri May 17, 2013 4:12 pm ] |
Post subject: | RE:Array questions |
IF you ever get to that stage, you should look this up: http://processing.org/ It's simple like turing and it's structured very similarly, but it has the power and syntax of Java. Learn turing first though |
Author: | Nathan4102 [ Fri May 17, 2013 4:16 pm ] |
Post subject: | RE:Array questions |
Well I'm going to need to learn Java too, since my co-op in 8 months will be using Java, plus my computers course in the fall will be in Java, so I'd like to get a bit of a head start before that class starts. The questions isn't IF I get to that stage, it's WHEN. ![]() |
Author: | Raknarg [ Fri May 17, 2013 4:17 pm ] |
Post subject: | RE:Array questions |
Well in that case, you're probably better off actually learning Java rather than something close to java ![]() also yay 1000 posts |
Author: | Nathan4102 [ Fri May 17, 2013 4:44 pm ] |
Post subject: | RE:Array questions |
That's what I was thinking, and gratz! I'll catch up to ya soon! |
Author: | Panphobia [ Fri May 17, 2013 8:45 pm ] | ||||
Post subject: | Re: Array questions | ||||
This here was one of my major OOP assignments in grade 12 compsci, it isn't that hard but its just to give a feel on what it looks like
|
Author: | Nathan4102 [ Fri May 17, 2013 9:56 pm ] |
Post subject: | RE:Array questions |
It looks like they've written half the thing for you! Interesting though, thanks for posting. |