Need help with 2D array problem
Author |
Message |
Paul

|
Posted: Thu Apr 01, 2004 6:04 pm Post subject: Need help with 2D array problem |
|
|
Im suppose to make a program like the carnival ones, where you toss 10 coins onto a mat, the mat is numbered, so you get the same amount of points of the sum of the squares that the coins landed on, I can't seem to get the scoring right, I went to sleep at 3 am today lol, anyone help me find the problem? if you want to see how the squares are originally numbered more clearly, just look at the text file. Also if anyone has any suggestions as to how to make the check easier (other than restructuring my extra if statements), please post. oh yea X means the coin landed there once, Y means the coin landed there twice.
Description: |
|
 Download |
Filename: |
board.txt |
Filesize: |
76 Bytes |
Downloaded: |
256 Time(s) |
Description: |
|
 Download |
Filename: |
pennies.t |
Filesize: |
2.03 KB |
Downloaded: |
255 Time(s) |
|
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Delos

|
Posted: Thu Apr 01, 2004 7:18 pm Post subject: (No subject) |
|
|
Here's a way easier sol'n to it...
Have 2 2-dim arrays. One of them handles the scores...so, you'd put the text file stuff into that one.
The second one handles the scoring. You do the tossing of coins into that one.
Then, you do something like this:
- check coinArray (using a, b)
- if an X is found, then score := 1 * numArray (a, b)
- else if a Y is found, then score := 2 * numArray (a, b)
- display score.
Methinks your problem was that your checking was too lengthy and inefficient, thus you may have missed a couple of boxes.
Using 2 arrays means you can increase/decrease the size of the boards and still get everything you need!
|
|
|
|
|
 |
Paul

|
Posted: Thu Apr 01, 2004 7:24 pm Post subject: (No subject) |
|
|
omg thank you thank you thank you, that was the most obvious way of checking it, yet I hadn't thought about it! damn some kind of brain block, but then Im so spaced out, its like Im typing and I dunno I was typing...
|
|
|
|
|
 |
Paul

|
Posted: Thu Apr 01, 2004 7:45 pm Post subject: (No subject) |
|
|
Ok I just figured it out, there was nothing wrong with my previous really tedious checking code I just figured it out... thanx for helping me reduce 50 lines to 6 lines though, thanx alot. But it all came down to the right checking but wrong display,
this code
code: |
for a : 1 .. 6
for b : 1 .. 6
if b = 1 then
x := 195
end if
Font.Draw (board (a, b), x, y, font, black)
x += 67
end for
y -= 66
end for
|
goes after
code: |
if board (px, py) = "X" then
board (px, py) := "Y"
end if
if board (px, py) not= "X" and board (px, py) not= "Y" then
board (px, py) := "X"
end if
|
this code, b4 that, they were switched, so the last X wouldn't get drawn, and I would think I got the freaking scoring wrong. God damn it I wish there was a way to stop making these damned stupid tiny mistakes that are so freaking time consuming.
|
|
|
|
|
 |
Delos

|
Posted: Thu Apr 01, 2004 8:51 pm Post subject: (No subject) |
|
|
Oh, but there is!
It's called "not staying up until 3 am unless you're not going anywhere the next day (well, that day by then)"
|
|
|
|
|
 |
|
|