This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
GopherAtl's profile picture

Minesweeper v1.7! (advanced computer/monitor only)

Started by GopherAtl, 17 January 2013 - 11:16 PM
GopherAtl #1
Posted 18 January 2013 - 12:16 AM
Update: v 1.7 1.6 partially broke monitor support without me realising it, but that is fixed now, as well as some more cosmetic overhauling and a refinement of the way it flood-clears around 0-count tiles.

I decided to work on something quick and easy tonight, to take a break from big projects that require lots of planning and design and etc, so I did something I've meant to do for a while: I threw together Minesweeper!

Requires an advanced computer or monitor; if there's an advanced monitor attached you can run it from a basic computer, tho an advanced computer is recommended for the right-clicking. On a monitor, you switch between showing and flagging a tile by clicking the show/flag button at the top-right.

Two convenience dealies: left-click (or click in "show" mode) a tile that is already revealed and if the number of flags around it equals it's count of mines, all the non-flagged tiles are revealed. (This is like clicking left and right buttons together in windows minecraft). Right-click has the opposite, if the number of unrevealed neighbors equals the count, then they are all flagged. If you care about speed, learn to use these two to your full advantage!



If you play on a single advanced monitor, you will only be able to play easy or medium; the hard board won't fit. It takes an advanced computer or a 2x2 advanced monitor to play hard.

(note to lyqyd: no window_resize event handleing - yet!)

pastebin get nsKrHTbN minesweep
theoriginalbit #2
Posted 18 January 2013 - 12:21 AM
Very nice!
remiX #3
Posted 18 January 2013 - 04:20 AM
I was planning to make this game sometime but I guess it's too late :[

Very nice btw.

When you lose, could you make it show all the mines?
Left4Cake #4
Posted 18 January 2013 - 04:33 AM
Considering the number of door locks on the fourm. I am sure another version of minesweeper wont be that big a deal.
GopherAtl #5
Posted 18 January 2013 - 07:11 AM
haha. Yeah, I should really make it show them, and add a game timer and high score table. Some other night I'll sit and work on a version 2.0!
Lyqyd #6
Posted 18 January 2013 - 07:20 AM
no window_resize event handleing

:(/>

- yet!

:D/>

Looks excellent, Gopher! Perhaps version 2.0 could also make use of the grey colors instead of black and white for revealed/hidden tiles.
GopherAtl #7
Posted 18 January 2013 - 07:28 AM
I was thinking light gray for hidden tiles, leaving revealed black, and doing the empty screen area dark gray, so you can tell what's what more easily.

re: window resize events, it'd be a lot easier to handle if there were a way to set the minimum size it can resize to :P/> basically going to have to write it to use my gui code, or re-implement scrollable client areas with scroll bars, to make it properly work with resizing windows. Of course, scroll bars would let you do larger maps, and all maps even on a single monitor, so might be worth doing that anyway. I don't like the idea of adding dependencies to this project, tho, I deliberately did it without them. Ah well. 2.0 will probably be a while.
NeverCast #8
Posted 18 January 2013 - 07:46 AM
Oh No I'm pressed with a situation.. do I continue making my own minesweeper for my os, Or use this one!
DUN DUN DUN!!


Either way, It looks nice Gopher! Excellent work.
NeverCast #9
Posted 18 January 2013 - 02:00 PM
Why only diagonals here?

if x~=x2 or y~=y2 then
func(x2,y2)
end

Would have thought it would've been a x ~= x2 and y ~= y2
GopherAtl #10
Posted 18 January 2013 - 02:05 PM
it's a check to exclude the center, so x ~= centerX or y~=centerY, it could also be written not (x==centerX and y==centerY), but just "x~=x2 and y~=y2" would be the one that only did diagonals :)/>
NeverCast #11
Posted 18 January 2013 - 02:56 PM
What? *contemplates getting another Coffee*

Don't you have to confirm that x2 and y2 are both not x and y, else x2 might be x and y not be y2 and it still fail?
GopherAtl #12
Posted 18 January 2013 - 03:09 PM
eh? I'm exclusing only the center, where x==x2 and y==y2. Lemme a'splain again…
Spoiler

if x==x2 and y==y2 then
  --code here for center
else
  --code here for everywhere but center
end

natually, this reverses by wrapping the entire original conditional in not ( )

if not (x==x2 and y==y2) then
  --code here for everywhere but center
end

if you distribute the not, it changes the == to ~= and the and to an or, because that's how it works

if x~=x2 or y~=y2 then
  --code for everywhere but center
end

in english, one more time, if x is not the center or y is not the center, then x,y is not the center. Only one of the two has to be off-center for the whole thing to be not the center.

Also, updated version. Timer, mine count, and a new feature.where right-click on a revealed number to auto-flag neighbors when the number of hidden tiles around it is is equal to the count. Ex, if there's only 2 unrevealed tile left by a "2", right-click the 2 and it is flagged.
GopherAtl #13
Posted 18 January 2013 - 08:22 PM
1.7 update, 50% less ugly now, also 10% less crashy (1.6 partially broke monitor support, and introduced another crashy bug as well…<_</>)
crazyguymgd #14
Posted 18 January 2013 - 08:43 PM
Very cool. Add me to the list of people who have now removed "Make minesweeper" from the list of things to do.
remiX #15
Posted 19 January 2013 - 01:49 AM
Wow, looks much better:P the whiteness was hurting my eyes…
Tinyboss #16
Posted 19 January 2013 - 03:02 AM
re: window resize events, it'd be a lot easier to handle if there were a way to set the minimum size it can resize to :P/> basically going to have to write it to use my gui code, or re-implement scrollable client areas with scroll bars, to make it properly work with resizing windows. Of course, scroll bars would let you do larger maps, and all maps even on a single monitor, so might be worth doing that anyway. I don't like the idea of adding dependencies to this project, tho, I deliberately did it without them. Ah well. 2.0 will probably be a while.

Wouldn't it be better to implement the scrollbars in LyqydOS, not in each client separately? Or maybe that's what you meant…

Maybe LOS should offer something like term.setSize(x,y), and add scrollbars to the window as needed.
Lyqyd #17
Posted 19 January 2013 - 10:48 AM
I like the minimum window size idea. I will add that, and maximums as well.
GopherAtl #18
Posted 20 January 2013 - 06:32 AM
the ability for the program to resize/reposition it's own window would be nice too, if it's not already planned.
Lyqyd #19
Posted 20 January 2013 - 12:07 PM
Indeed, and a fullscreen "mode" will be available as well, eventually.
GopherAtl #20
Posted 06 March 2015 - 12:04 PM
bump for long overdue update to … whichever cc update it was that changed the term functions (1.6?) and removed term.restore(), which was causing this to crash on exit if you used it's built-in ability to run on a monitor.
Lyqyd #21
Posted 02 May 2015 - 07:33 PM
Hey, some recent changes in LyqydOS ended up breaking the version of minesweeper you built for it (whoops!). The necessary change to fix it is to change line 87 to local trueW,trueH=process.compositor.target.getSize(). I'd send you a pull request, but you've got this one on pastebin, not github! :P/>