post #1 of 1
Thread Starter 
In my AP computer science class we are require to make a game for a final project. My plan was to make "FloodIt!" and also run it on android. My question is:

What is the best way to sort and compare items within a matrix. I only need to compare items next to CERTAIN items in a grid and not every item.

I have already constructed a class that will contain all the data for each object in the grid. First I will use text to indicate colors within the grid R G Y P B and then later replace with boxes when I implement graphics.

My idea was to use an arrayList of all boxes in the grid that have already been "conquered" I guess you can call it. Then I can test surrounding boxes such as (x-1,y) , (x+1,y) , (x,y-1) , (x,y+1). If the box I test has the same color I would then add it to the arrayList.

It seems inefficient? I hope there is a better way. Thanks

Quote:
Sample Output:
B G R P G G B Y B G
G B R Y R R R R Y P
R B Y G G P R B P P
G G Y R B P P P G P
R Y Y P Y P G G G Y
Y P Y G B P G Y R Y
R G B Y Y P B B Y B
B Y G G P P B P G R
R Y Y Y P B B B Y R
Y Y R G G P P Y P R

choose: G

G G R P G G B Y B G
G B R Y R R R R Y P
R B Y G G P R B P P
G G Y R B P P P G P
R Y Y P Y P G G G Y
Y P Y G B P G Y R Y
R G B Y Y P B B Y B
B Y G G P P B P G R
R Y Y Y P B B B Y R
Y Y R G G P P Y P R

choose: R
R R R P G G B Y B G
R B R Y R R R R Y P
R B Y G G P R B P P
G G Y R B P P P G P
R Y Y P Y P G G G Y
Y P Y G B P G Y R Y
R G B Y Y P B B Y B
B Y G G P P B P G R
R Y Y Y P B B B Y R
Y Y R G G P P Y P R

Edited by da tick 07 - 3/4/11 at 8:25pm
Mitx Love
(13 items)
 
  
CPUMotherboardRAMHard Drive
Pentium G6950 Zotac H55 ITX 2x2GB Kingston 500GB Hitachi 
OSPowerMouseMouse Pad
Windows Server 2008 R2 Lite-on 300w Logitech Wireless Laser ULTRA wrist rest 
  hide details  
Reply
Mitx Love
(13 items)
 
  
CPUMotherboardRAMHard Drive
Pentium G6950 Zotac H55 ITX 2x2GB Kingston 500GB Hitachi 
OSPowerMouseMouse Pad
Windows Server 2008 R2 Lite-on 300w Logitech Wireless Laser ULTRA wrist rest 
  hide details  
Reply