diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-02-24 02:13:59 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-02-24 02:13:59 +0000 |
commit | a6d58bb6052ac8cb01805a48c4ad2f129126116f (patch) | |
tree | dd867a099fcbb263a8009a9fb22695b87855dad6 /doc/scriptexamples/minesweeper | |
download | kvirc-a6d58bb6052ac8cb01805a48c4ad2f129126116f.tar.gz kvirc-a6d58bb6052ac8cb01805a48c4ad2f129126116f.zip |
Added KDE3 version of kvirc
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/kvirc@1095341 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'doc/scriptexamples/minesweeper')
-rw-r--r-- | doc/scriptexamples/minesweeper/Makefile.am | 5 | ||||
-rw-r--r-- | doc/scriptexamples/minesweeper/minesweeper.kvs | 131 |
2 files changed, 136 insertions, 0 deletions
diff --git a/doc/scriptexamples/minesweeper/Makefile.am b/doc/scriptexamples/minesweeper/Makefile.am new file mode 100644 index 00000000..914e3823 --- /dev/null +++ b/doc/scriptexamples/minesweeper/Makefile.am @@ -0,0 +1,5 @@ +############################################################################### +# KVirc IRC client Makefile - 16.12.98 Szymon Stefanek <stefanek@tin.it> +############################################################################### + +EXTRA_DIST = *.kvs diff --git a/doc/scriptexamples/minesweeper/minesweeper.kvs b/doc/scriptexamples/minesweeper/minesweeper.kvs new file mode 100644 index 00000000..24f3b0cb --- /dev/null +++ b/doc/scriptexamples/minesweeper/minesweeper.kvs @@ -0,0 +1,131 @@ + + +class(minelabel,label) +{ + mousePressEvent() + { + $$->$parent()->$mineLabelPressed($this) + } +} + +class(minesweeper,widget) +{ + constructor() + { + $$->$setCaption("KVIrc's Minesweeper (0.1.0)"); + + $$->%rows = 10 + $$->%cols = 10 + $$->%mines = 10 + + $$->%layout = $new(layout,$this) + + for(%i = 0;%i < $$->%rows;%i++) + { + for(%j = 0;%j < $$->%cols;%j++) + { + $$->%label{%i,%j}=$new(minelabel,$this,"%i_%j") + $$->%label{%i,%j}->%row = %i + $$->%label{%i,%j}->%col = %j + $$->%layout->$addWidget($$->%label{%i,%j},%i,%j) + } + } + + $$->$newGame() + } + + destructor() + { + } + + newGame() + { + for(%i = 0;%i < $$->%rows;%i++) + { + for(%j = 0;%j < $$->%cols;%j++) + { + %l = $$->%label{%i,%j} + %l->$setFrameStyle(Raised,WinPanel); + %l->%bIsMine = 0 + %l->%numMines = 0 + %l->%bIsDiscovered = 0 + %l->$setText("") + } + } + # drop the mines + for(%i = 0;%i < $$->%mines;%i++) + { + %row = $rand($($$->%rows - 1)) + %col = $rand($($$->%cols - 1)) + while($$->%label{%row,%col}->%bIsMine != 0) + { + %row = $rand($($$->%rows - 1)) + %col = $rand($($$->%cols - 1)) + } + $$->%label{%row,%col}->%bIsMine = 1 + # increase the mine count for the adiacent cells + if(%row > 0) + { + $$->%label{$(%row - 1),%col}->%numMines++ + if(%col > 0)$$->%label{$(%row - 1),$(%col - 1)}->%numMines++ + if(%col < ($$->%cols - 1))$$->%label{$(%row - 1),$(%col + 1)}->%numMines++ + } + if(%row < ($$->%rows - 1)) + { + $$->%label{$(%row + 1),%col}->%numMines++ + if(%col > 0)$$->%label{$(%row + 1),$(%col - 1)}->%numMines++ + if(%col < ($$->%cols - 1))$$->%label{$(%row + 1),$(%col + 1)}->%numMines++ + } + if(%col > 0)$$->%label{%row,$(%col - 1)}->%numMines++ + if(%col < ($$->%cols - 1))$$->%label{%row,$(%col + 1)}->%numMines++ + } + } + + mineLabelPressed($0 = mine label object that has been pressed) + { + #echo "MINE LABEL PRESSED $0" + if($0->%bIsMine) + { + #echo "IS MINE!" + $0->$setFrameStyle(WinPanel,Sunken) + $0->$setText("*") + } else { + #echo "IS NOT MINE" + $$->$discoverCells($0) + } + } + + discoverCells($0 = mine label that has to be discovered) + { + #echo "Discover cells $0" + if($0->%bIsMine)return; + if($0->%bIsDiscovered)return; + $0->%bIsDiscovered = 1 + $0->$setFrameStyle(WinPanel,Sunken) + if($0->%numMines > 0)$0->$setText($0->%numMines) + else { + if($0->%row > 0) + { + $$->$discoverCells($$->%label{$($0->%row - 1),$0->%col}) + if($0->%col > 0)$$->$discoverCells($$->%label{$($0->%row - 1),$($0->%col - 1)}) + if($0->%col < ($$->%cols - 1))$$->$discoverCells($$->%label{$($0->%row - 1),$($0->%col + 1)}) + } + if($0->%row < ($$->%rows - 1)) + { + $$->$discoverCells($$->%label{$($0->%row + 1),$0->%col}) + if($0->%col > 0)$$->$discoverCells($$->%label{$($0->%row + 1),$($0->%col - 1)}) + if($0->%col < ($$->%cols - 1))$$->$discoverCells($$->%label{$($0->%row + 1),$($0->%col + 1)}) + } + if($0->%col > 0)$$->$discoverCells($$->%label{$0->%row,$($0->%col - 1)}) + if($0->%col < ($$->%cols - 1))$$->$discoverCells($$->%label{$0->%row,$($0->%col + 1)}) + } + } + +} + +alias(mines) +{ + %m = $new(minesweeper) + %m->$show() + +} |