onilink_ Modérateur
Messages : 9178 Localisation : Montpellier Projet Actuel : Planet Centauri
OniDev
| Sujet: Demineur en un script Dim 13 Juin 2010 - 14:53 | |
| Voila un démineur sans ressources en 1 script desormais, et a mettre dans draw. Si vous etes sous gm7 supprimez la ligne 10 : version = "gm6" Si vous etes sous gm8 prenez le premier code. Fichier : http://host-a.net/onilink_/demineur1script.gm6Screen sous GM 6.1 Code pour ceux qui sont sous GM8 - Spoiler:
- Code:
-
if(!variable_local_exists('create')) begin //Debut variables parametrables grille_w = 16 grille_h = 16 nbr_mines = 16 xx = 0 yy = 0
//Fin create = 1 game_start = 0 nbr_mines = min(nbr_mines, grille_w*grille_h-1)
for(i=0 ; i<grille_w ; i+=1){ for(j=0 ; j<grille_h ; j+=1){ mine[i,j] = 0 cover[i,j] = 1 mode[i,j] = 0//0:cover, 1:drapeau, 2:?, 3:empty, 4:mine? mines_near[i, j] = 0 }}
for(i=1 ; i<=9 ; i+=1) color = 0 color[1] = c_blue color[2] = c_green color[3] = c_red color[4] = c_maroon
//Creation des sprites draw_set_color( c_silver ) draw_rectangle(16, 16, 32, 32, 0) draw_set_color( make_color(128, 128, 128) ) draw_line(16, 16, 32, 16) draw_line(16, 16, 16, 32) spr_case = sprite_create_from_screen(16, 16, 16, 16, 0, 0, 0, 0)
draw_set_color( c_silver ) draw_rectangle(0, 0, 16, 16, 0) draw_set_color( c_white ) draw_triangle(0, 15, 0, 0, 15, 0, 0) draw_set_color( make_color(128, 128, 128) ) draw_triangle(0, 16, 16, 16, 16, 0, 0) draw_set_color( make_color(192, 192, 192) ) draw_rectangle(2, 2, 13, 13, 0) sprite_add_from_screen(spr_case, 0, 0, 16, 16, 0, 0)
draw_sprite(spr_case, 1, 0, 0) draw_set_color(0) draw_triangle(8, 8, 4, 12, 11, 12, 0) draw_set_color(c_red) draw_triangle(4, 5, 8, 3, 8, 8, 0) sprite_add_from_screen(spr_case, 0, 0, 16, 16, 0, 0)
draw_sprite(spr_case, 1, 0, 0) draw_set_color(c_blue) tmp_font = font_add('Arial', 8, 1, 0, 0, 255) draw_set_font(tmp_font) draw_text(5, 1, '?') sprite_add_from_screen(spr_case, 0, 0, 16, 16, 0, 0) end
mx = max(0, min(grille_w-1, floor( (mouse_x+xx)/16 ))) my = max(0, min(grille_h-1, floor( (mouse_y+yy)/16 )))
if(mouse_check_button_released(mb_left)) { if( !game_start ) begin //on cree la grille de mines mines_count = nbr_mines while(mines_count) { randx = floor( random(grille_w) ) randy = floor( random(grille_h) ) if(!mine[randx, randy] && !(randx==mx && randy==my)){ mine[randx, randy] = 1 mines_count -= 1
for(i=0 ; i<8 ; i+=1) { lx = lengthdir_x(1, i*45) ly = lengthdir_y(1, i*45) lx = sign(lx) * ceil( abs(lx) ) + randx ly = sign(ly) * ceil( abs(ly) ) + randy if( lx>=0 && lx<grille_w && ly>=0 && ly<grille_h) mines_near[lx, ly] += 1 }}} game_start = 1 end
if(mode[mx, my] == 0 || mode[mx,my] == 2){ if( mine[mx, my] == 0 ){ mode[mx, my] = 3 if(!mines_near[mx, my]) { p = ds_stack_create() ds_stack_push(p, mx + grille_w*my)
while(!ds_stack_empty(p)){ top = ds_stack_pop(p) px = top mod grille_w py = top div grille_w for(i=0 ; i<8 ; i+=1) { lx = lengthdir_x(1, i*45) ly = lengthdir_y(1, i*45) lx = sign(lx) * ceil( abs(lx) ) + px ly = sign(ly) * ceil( abs(ly) ) + py if( lx>=0 && lx<grille_w && ly>=0 && ly<grille_h) if(!mine[lx, ly] && mode[lx, ly] == 0) { mode[lx, ly] = 3 if(!mines_near[lx, ly]) ds_stack_push(p, lx + grille_w*ly) }}} ds_stack_destroy(p) }} else { /* game_over */ show_message('You Loose') game_restart() }}}
if(mouse_check_button_pressed(mb_right)) { switch(mode[mx, my]){ case 0 : mode[mx, my] = 1 ; break case 1 : mode[mx, my] = 2 ; break case 2 : mode[mx, my] = 0 ; break }}
for(i=0 ; i<grille_w ; i+=1){ for(j=0 ; j<grille_h ; j+=1){ if(mode[i,j] < 3 && !(i==mx && j==my && mouse_check_button(mb_left) && mode[i,j] != 1) ) draw_sprite(spr_case, mode[i,j]+ 1, 16*i + xx, 16*j + yy)
if(mode[i,j] == 3){ draw_sprite(spr_case, 0, i*16 + xx, j*16 + yy) if(mines_near[i, j]) { draw_set_color( color[ mines_near[i, j] ] ) draw_text(i*16+6, j*16+1, mines_near[i,j]) }} }}
hidden = 0 for(i=0 ; i<grille_w ; i+=1){ for(j=0 ; j<grille_h ; j+=1){ if(mode[i,j] < 3) hidden += 1 }}
if(hidden == nbr_mines) { /* Partie gagnée */ show_message('You win') game_restart() }
- Citation :
- if(!variable_local_exists('create'))
begin //Debut variables parametrables grille_w = 16 grille_h = 16 nbr_mines = 16 xx = 0 yy = 0
//Fin create = 1 game_start = 0 nbr_mines = min(nbr_mines, grille_w*grille_h-1)
for(i=0 ; i<grille_w ; i+=1){ for(j=0 ; j<grille_h ; j+=1){ mine[i,j] = 0 cover[i,j] = 1 mode[i,j] = 0//0:cover, 1:drapeau, 2:?, 3:empty, 4:mine? mines_near[i, j] = 0 }}
for(i=1 ; i<=9 ; i+=1) color = 0 color[1] = c_blue color[2] = c_green color[3] = c_red color[4] = c_maroon
//Creation des sprites draw_set_color( c_silver ) draw_rectangle(16, 16, 32, 32, 0) draw_set_color( make_color(128, 128, 128) ) draw_line(16, 16, 32, 16) draw_line(16, 16, 16, 32) spr_case = sprite_create_from_screen(16, 16, 16, 16, 0, 0, 0, 0, 0, 0)
draw_set_color( c_silver ) draw_rectangle(0, 0, 16, 16, 0) draw_set_color( c_white ) draw_triangle(0, 15, 0, 0, 15, 0, 0) draw_set_color( make_color(128, 128, 128) ) draw_triangle(0, 16, 16, 16, 16, 0, 0) draw_set_color( make_color(192, 192, 192) ) draw_rectangle(2, 2, 13, 13, 0) sprite_add_from_screen(spr_case, 0, 0, 16, 16)
draw_sprite(spr_case, 1, 0, 0) draw_set_color(0) draw_triangle(8, 8, 4, 12, 11, 12, 0) draw_set_color(c_red) draw_triangle(4, 5, 8, 3, 8, 8, 0) sprite_add_from_screen(spr_case, 0, 0, 16, 16)
draw_sprite(spr_case, 1, 0, 0) draw_set_color(c_blue) tmp_font = font_add('Arial', 8, 1, 0, 0, 255) draw_set_font(tmp_font) draw_text(5, 1, '?') sprite_add_from_screen(spr_case, 0, 0, 16, 16) end
mx = max(0, min(grille_w-1, floor( (mouse_x+xx)/16 ))) my = max(0, min(grille_h-1, floor( (mouse_y+yy)/16 )))
if(mouse_check_button_released(mb_left)) { if( !game_start ) begin //on cree la grille de mines mines_count = nbr_mines while(mines_count) { randx = floor( random(grille_w) ) randy = floor( random(grille_h) ) if(!mine[randx, randy] && !(randx==mx && randy==my)){ mine[randx, randy] = 1 mines_count -= 1
for(i=0 ; i<8 ; i+=1) { lx = lengthdir_x(1, i*45) ly = lengthdir_y(1, i*45) lx = sign(lx) * ceil( abs(lx) ) + randx ly = sign(ly) * ceil( abs(ly) ) + randy if( lx>=0 && lx<grille_w && ly>=0 && ly<grille_h) mines_near[lx, ly] += 1 }}} game_start = 1 end
if(mode[mx, my] == 0 || mode[mx,my] == 2){ if( mine[mx, my] == 0 ){ mode[mx, my] = 3 if(!mines_near[mx, my]) { p = ds_stack_create() ds_stack_push(p, mx + grille_w*my)
while(!ds_stack_empty(p)){ top = ds_stack_pop(p) px = top mod grille_w py = top div grille_w for(i=0 ; i<8 ; i+=1) { lx = lengthdir_x(1, i*45) ly = lengthdir_y(1, i*45) lx = sign(lx) * ceil( abs(lx) ) + px ly = sign(ly) * ceil( abs(ly) ) + py if( lx>=0 && lx<grille_w && ly>=0 && ly<grille_h) if(!mine[lx, ly] && mode[lx, ly] == 0) { mode[lx, ly] = 3 if(!mines_near[lx, ly]) ds_stack_push(p, lx + grille_w*ly) }}} ds_stack_destroy(p) }} else { /* game_over */ show_message('You Loose') game_restart() }}}
if(mouse_check_button_pressed(mb_right)) { switch(mode[mx, my]){ case 0 : mode[mx, my] = 1 ; break case 1 : mode[mx, my] = 2 ; break case 2 : mode[mx, my] = 0 ; break }}
for(i=0 ; i<grille_w ; i+=1){ for(j=0 ; j<grille_h ; j+=1){ if(mode[i,j] < 3 && !(i==mx && j==my && mouse_check_button(mb_left) && mode[i,j] != 1) ) draw_sprite(spr_case, mode[i,j]+ 1, 16*i + xx, 16*j + yy)
if(mode[i,j] == 3){ draw_sprite(spr_case, 0, i*16 + xx, j*16 + yy) if(mines_near[i, j]) { draw_set_color( color[ mines_near[i, j] ] ) draw_text(i*16+6, j*16+1, mines_near[i,j]) }} }}
hidden = 0 for(i=0 ; i<grille_w ; i+=1){ for(j=0 ; j<grille_h ; j+=1){ if(mode[i,j] < 3) hidden += 1 }}
if(hidden == nbr_mines) { /* Partie gagnée */ show_message('You win') game_restart() }
Dernière édition par onilink_ le Dim 1 Aoû 2010 - 14:55, édité 12 fois |
|