[Gambas-user] Stranges mines

Pozzo mauriiiii3001 at ...325...
Sat Feb 28 21:25:13 CET 2004


Hi All,
I'm writing a Mines Hunter game under Gambas and I've found a real 
strange thing.
first I have realize a Sub that place mines randomly, it works fine but 
is too complicated, I'll modify it in another time, I already now what 
to do :-), for tensting propose it put only two mines in an array of 128 
cells then I've created a sub that check all then cells next to one cell 
per time so I can know how many mines are near to it, the cells with the 
mine are true and the cells without are false and here is the problem, 
the first time the sub find a mine everything is OK but at the next 
cicle a mine born magicaly in the cell at the right of the cell I'm 
woring on.
For example if the mines are in the cells 1,1 and 7,2 when I'm working 
on the 0,0 it find a mine at the 1,1 and this is OK the I move to the 
0,1 and it find a mine in the 1,1 and in the 0,2 next time it find in 
the 1,1, the 0,2 and the 0,3 ....
this is real strange because I never modify the array during the process
this is my sub where we(7) and hi(15) are indicate how many cells there 
are in the array, Harry is the array with all the mines and HarryC is 
the array where i've writen how many mines are near to the cells.

SUB control (We AS Integer, Hi AS Integer)
 
  DIM i AS Integer
  DIM j AS Integer
  DIM y AS Integer
  DIM t AS Integer
  DIM c AS Integer
  DIM debug AS Boolean
  FOR i=0 TO Hi
    FOR j=0 TO We
    c = 0
    FOR y =i-1 TO i+1
        FOR t=j-1 TO j+1
          debug = false
          IF t<0 OR t>We OR y<0 OR y>Hi THEN
          ELSE
            IF Harry[t,y] = true THEN 
            c = c + 1
            ENDIF
          ENDIF
        NEXT
      NEXT
    IF Harry[j,i] = false THEN 
    HarryC[j,i] = c
    ELSE
    HarryC[j,i]= 80011
    ENDIF
    NEXT
  NEXT
END


Maurizio





More information about the User mailing list