' ' Miinaharava HD 1.0 by Tertsi 2018 ' ' Pelataan hiirella, ylareunan ruksista lopettaa, plussasta aloittaa uuden pelin ' RANDOMIZE TIMER ' saadetaan pelialueen koko ruudun tarkkuuden mukaan desktop = _SCREENIMAGE: MaxScreenX = _WIDTH(desktop): MaxScreenY = _HEIGHT(desktop) _FREEIMAGE desktop: SCREEN _NEWIMAGE(MaxScreenX, MaxScreenY, 256): _FULLSCREEN _PRINTMODE _KEEPBACKGROUND: GridX = MaxScreenX / 16: GridY = MaxScreenY / 16 DIM Grid&(GridX + 1, GridY + 1) Start: FOR y = 0 TO GridY - 1 ' piirretaan pelialue FOR x = 0 TO GridX - 1 LINE (x * 16, y * 16)-(x * 16 + 14, y * 16 + 14), 15, B LINE (x * 16 + 1, y * 16 + 1)-(x * 16 + 15, y * 16 + 15), 8, B LINE (x * 16 + 1, y * 16 + 1)-(x * 16 + 14, y * 16 + 14), 7, BF Grid&(x + 1, y + 1) = 0 NEXT x NEXT y Grid&(1, 1) = -1 ' maaritellaan ylareunan Grid&(2, 1) = -2 ' nappien paikat Bombs = INT(GridX * GridY / 10) '<- pommien tiheys FOR z = 1 TO Bombs DO y = INT(RND * GridY) + 1 x = INT(RND * (GridX - 1)) + 1 IF Grid&(x, y) = 0 THEN Grid&(x, y) = 9: EXIT DO LOOP NEXT z 'piirretaan ylareunan napit muinaisella DRAW-komennolla DRAW "bm23,7 ta0 bh2 c0 u4r4d4r4d4l4d4l4u4l4u4r4 bf2 p2,0" DRAW "bm7,7 ta45 bh2 c0 u4r4d4r4d4l4d4l4u4l4u4r4 bf2 p4,0" Mode$ = "PLAY" 'PLAY-moodissa pelataan, GAMEOVER-moodissa toimii vain ylareunan napit DO DO WHILE _MOUSEINPUT x = _MOUSEX: GX = INT(x / 16) + 1 y = _MOUSEY: GY = INT(y / 16) + 1 IF GX < GridX AND GY < GridY + 1 THEN IF _MOUSEBUTTON(1) THEN 'hiiren vasen nappi IF Grid&(GX, GY) = -1 THEN SYSTEM IF Grid&(GX, GY) = -2 THEN GOTO Start IF Mode$ = "PLAY" THEN LINE (GX * 16 - 16, GY * 16 - 16)-(GX * 16 - 1, GY * 16 - 1), 8, B LINE (GX * 16 - 16, GY * 16 - 16)-(GX * 16 - 2, GY * 16 - 2), 0, BF IF Grid&(GX, GY) = 9 THEN LINE (GX * 16 - 16, GY * 16 - 16)-(GX * 16 - 2, GY * 16 - 2), 4, BF GOSUB GameOver ELSE GOSUB Check END IF END IF END IF IF _MOUSEBUTTON(2) AND Mode$ = "PLAY" THEN 'hiiren oikea nappi IF POINT(GX * 16 - 8, GY * 16 - 8) = 7 THEN COLOR 4: _PRINTSTRING (GX * 16 - 12, GY * 16 - 15), "?" ELSEIF POINT(GX * 16 - 8, GY * 16 - 8) = 4 THEN LINE (GX * 16 - 15, GY * 16 - 15)-(GX * 16 - 2, GY * 16 - 2), 7, BF END IF END IF END IF LOOP LOOP GameOver: 'piirretaan kaikki pommit ruudulle FOR y = 1 TO GridY FOR x = 1 TO GridX IF Grid&(x, y) = 9 THEN CIRCLE (x * 16 - 9, y * 16 - 9), 5, 0 PAINT (x * 16 - 9, y * 16 - 9), 0 END IF NEXT x NEXT y Mode$ = "GAMEOVER" RETURN Check: ' lasketaan pommit viereisista ruuduista counter = 0 IF Grid&(GX - 1, GY - 1) = 9 THEN counter = counter + 1 IF Grid&(GX, GY - 1) = 9 THEN counter = counter + 1 IF Grid&(GX + 1, GY - 1) = 9 THEN counter = counter + 1 IF Grid&(GX - 1, GY) = 9 THEN counter = counter + 1 IF Grid&(GX + 1, GY) = 9 THEN counter = counter + 1 IF Grid&(GX - 1, GY + 1) = 9 THEN counter = counter + 1 IF Grid&(GX, GY + 1) = 9 THEN counter = counter + 1 IF Grid&(GX + 1, GY + 1) = 9 THEN counter = counter + 1 IF counter > 0 THEN COLOR 8 + counter: _PRINTSTRING (GX * 16 - 20, GY * 16 - 16), STR$(counter) END IF RETURN
Nopealla koodin vilkaisulla pelistä näyttäisi puuttuvan 'flood-fill' tyhjien vierekkäisten ruutujen paljastamiseen? Tuon saisit helposti toteutettua rekursiivisesti, eikä iteratiivinen toteutuskaan monimutkainen ole.
Aihe on jo aika vanha, joten et voi enää vastata siihen.