From: kemal Date: Sun, 11 Jul 2021 16:28:18 +0000 Subject: [PATCH] games/mines: some mechanism changes 1. do not put a mine to the first clicked tile. 2. do not allow middle/right clicks at beginning. 3. add a option that will make the game run "faster" :^) (thanks ori for the idea of -f) --- diff c3589ef3cf33189d342a3ab638b558fd9249b220 99536f642160327672971cf8606a64ddd12e02d3 --- a/sys/man/1/mines Sat Jul 10 21:34:22 2021 +++ b/sys/man/1/mines Sun Jul 11 19:28:18 2021 @@ -4,7 +4,7 @@ .SH SYNOPSIS .B games/mines [ -.B -aeqg +.B -aefgq ] .SH DESCRIPTION .I Mines @@ -46,11 +46,16 @@ .B -e Start at expert difficulty. .TP -.B -q -Disable the query marker. +.B -f +It t- +.I ahem +I mean it makes the game faster to solve. .TP .B -g It's a secret to everybody. +.TP +.B -q +Disable the query marker. .SH SOURCE .B /sys/src/games/mines .SH HISTORY --- a/sys/src/games/mines/dat.h Sat Jul 10 21:34:22 2021 +++ b/sys/src/games/mines/dat.h Sun Jul 11 19:28:18 2021 @@ -23,15 +23,15 @@ }; enum { - Empty0 = 0, - Empty1 = 1, - Empty2 = 2, - Empty3 = 3, - Empty4 = 4, - Empty5 = 5, - Empty6 = 6, - Empty7 = 7, - Empty8 = 8, + Empty0, + Empty1, + Empty2, + Empty3, + Empty4, + Empty5, + Empty6, + Empty7, + Empty8, Query, MouseQuery, Mark, --- a/sys/src/games/mines/mines.c Sat Jul 10 21:34:22 2021 +++ b/sys/src/games/mines/mines.c Sun Jul 11 19:28:18 2021 @@ -10,7 +10,7 @@ int MaxX, MaxY, Mines; } Settings[] = { {8, 8, 10}, {16, 16, 40}, {30, 16, 99}, {0, 0, 0} }; -int MaxX, MaxY, Mines, Level, UnknownCell, Playing, MinesRemain, Time, Status, UseQuery = TRUE, UseGhost = FALSE, UseColor = TRUE; +int MaxX, MaxY, Mines, Level, UnknownCell, Playing, MinesRemain, Time, Status, UseQuery = TRUE, UseGhost = FALSE, Trololo = FALSE, UseColor = TRUE; Point Origin; Mouse LastMouse; @@ -159,21 +159,45 @@ } void InitMineField(void) { + int x, y; + /* clean up mine field, make all cells unknown */ - /* clean up mine field, make all cells unknown and place new mines */ - { - int i, x, y; + for(y = 0; y < MaxY; y++) + for(x = 0; x < MaxX; x++) { + MineField[x][y].Mine = FALSE; + MineField[x][y].Picture = Unknown; + } - for(y = 0; y < MaxY; y++) - for(x = 0; x < MaxX; x++) { - MineField[x][y].Mine = FALSE; - MineField[x][y].Picture = Unknown; - } + /* reset status, remaining mines etc. */ + Status = Game; + Playing = FALSE; + MinesRemain = Mines; + Time = 0; + UnknownCell = MaxX * MaxY - Mines; +} - for(i = 0; i < Mines; ) { +void GenMines(int fcx, int fcy) { + srand(time(0)); + /* plant mines */ + { + int i = 0, x, y; + + /* + * this option just trolls the user by increasing + * the chance of a mine in the first click from %0 to %90 + */ + if(Trololo){ + i = nrand(9); + if(i){ + MineField[fcx][fcy].Mine = TRUE; + i = 1; + } + } + while(i < Mines) { x = nrand(MaxX); y = nrand(MaxY); if(MineField[x][y].Mine) continue; + if(x == fcx && y == fcy) continue; MineField[x][y].Mine = TRUE; i++; } @@ -196,12 +220,6 @@ if(x < MaxX - 1 && y < MaxY - 1 && MineField[x + 1][y + 1].Mine) MineField[x][y].Neighbours++; } } - - Status = Game; - Playing = FALSE; - MinesRemain = Mines; - Time = 0; - UnknownCell = MaxX * MaxY - Mines; } void NewMineField(int NewLevel) { @@ -284,12 +302,17 @@ } void LeftClick(Point Cell) { + + int FirstClick; - if(! (Status == Game) || Cell.x < 0 || Cell.y < 0) return; + if(Status != Game || Cell.x < 0 || Cell.y < 0) return; + FirstClick = !Playing; Playing = TRUE; switch(MineField[Cell.x][Cell.y].Picture) { case Query: case Unknown: + if(FirstClick) + GenMines(Cell.x, Cell.y); if(MineField[Cell.x][Cell.y].Mine) { MineField[Cell.x][Cell.y].Picture = Explosion; DrawCell(Cell); @@ -320,8 +343,7 @@ int Neighbours = 0; - if(! (Status == Game) || Cell.x < 0 || Cell.y < 0) return; - Playing = TRUE; + if(Status != Game || Playing == FALSE || Cell.x < 0 || Cell.y < 0) return; switch(MineField[Cell.x][Cell.y].Picture) { case Empty1: case Empty2: @@ -359,9 +381,7 @@ void RightClick(Point Cell) { - if(! (Status == Game) || Cell.x < 0 || Cell.y < 0) return; - - Playing = TRUE; + if(Status != Game || Playing == FALSE || Cell.x < 0 || Cell.y < 0) return; switch(MineField[Cell.x][Cell.y].Picture) { case Unknown: MineField[Cell.x][Cell.y].Picture = Mark; @@ -381,7 +401,7 @@ void Usage(void) { - fprint(2, "Usage: %s [-aeq]\n", argv0); + fprint(2, "Usage: %s [-aefgq]\n", argv0); exits("usage"); } @@ -392,8 +412,9 @@ ARGBEGIN { case 'a': Level = Advanced; break; case 'e': Level = Expert; break; - case 'q': UseQuery = FALSE; break; + case 'f': Trololo = TRUE; break; case 'g': UseGhost = TRUE; break; + case 'q': UseQuery = FALSE; break; default: Usage(); } ARGEND @@ -518,8 +539,6 @@ ImageCell[Fault] = allocimage(display, Rect(0, 0, 15, 15), RGB24, 0, DNofill); loadimage(ImageCell[Fault], ImageCell[Fault]->r, SrcFault, CellBytes); - srand(time(0)); /* initialize generator of random numbers */ - NewMineField(Level); eresized(0); @@ -649,7 +668,7 @@ if(PushButton && CurrentButton) { InitMineField(); eresized(0); - } + } Button = FALSE; PushButton = FALSE;