This blog has moved to http://ThePowerShellGuy.com
Greetings /\/\o\/\/
On the 4th day of the scripting games ,
I got the 100 score :-),
as I posted the last script on the second day, I was a bit worried ;-)
also dr Scripto posted the
Dr. Scripto Concentration Game,
I decided to redo this in MSH , you can find the script below,
but you need the Pictures of the original sample in the scripts directory (or change the script for other picures)
Enjoy,
Greetings /\/\o\/\/
Tags : Monad msh# Concentration.msh
# a remake in MSH of Dr. Scripto Concentration
# You need the pictures of the HTA version
#
# /\/\o\/\/ 2006
# htpp://mow001.blogspot.com
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")
$Imagepath = parse-path $MyInvocation.mycommand.path
$rows = 4
$Cols = 4
# Build Form
$form = new-object System.Windows.Forms.form
$Form.text = "MSH Concentration by /\/\o\/\/"
$form.width = ($rows * 55) + 20
$form.Height = ($Cols * 55) + 70
# Build Menu
$MS = new-object System.Windows.Forms.MenuStrip
$Mi = new-object System.Windows.Forms.ToolStripMenuItem("&File")
$Msi1 = new-object System.Windows.Forms.ToolStripMenuItem("&New")
$msi1.add_Click({new-Game})
$Mi.DropDownItems.Add($msi1)
$Msi2 = new-object System.Windows.Forms.ToolStripMenuItem("&Quit")
$msi2.add_Click({$form.close()})
$Mi.DropDownItems.Add($msi2)
$ms.Items.Add($mi)
# Add a MenuLabel for the score
$ml = new-object System.Windows.Forms.ToolStripLabel
$ml.set_foreColor("Red")
$ms.Items.Add($ml)
# Add menu to form
$form.Controls.Add($ms)
# Make Imagelist
$images = @()
1..8 | foreach {
$image = [Drawing.Image]::FromFile("$Imagepath\Scripto_$_.gif")
$image.tag = $_
$images += $image
$images += $image
}
# function to handle ButtonClick
Function OnClick {
$num = $args[0]
if ($map[$num].image -eq $null -and $clicks -lt 3) {
$script:clicks += 1
$map[$num].image = $images[$num]
$map[$num].Refresh()
if ($clicks -eq 1) {
$script:sav = $num
}
if ($clicks -eq 2) {
if ($images[$num].tag -eq $images[$script:sav].tag) {
$map[$num].enabled = $false
$map[$script:sav].enabled = $false
} Else {
sleep 1
$map[$num].image = $null
$map[$script:sav].image = $null
}
$script:clicks = 0
$script:pairs += 1
$ml.text = "Total Pairs Clicked : $pairs"
}
}
}
# Create the PlayField (array of Buttons)
$Button = new-object System.Windows.Forms.Button
[System.Windows.Forms.Control[]]$Map = @()
for ($i = 0;$i -lt $rows;$i++)
{
$row = @()
for ($j = 0;$j -lt $Cols;$j++)
{
$Button = new-object System.Windows.Forms.Button
$Button.width = 55
$Button.Height = 55
$button.top = ($i * 55) + 25
$button.Left = $j * 55
$button.Name = ($i * $cols) + $j
$button.add_click({
[int]$num = $this.name
$this.name
OnClick $num
})
$button.font = new-object system.drawing.font('Microsoft Sans Serif',10,'bold')
#$Button.ForeColor
$Row += $Button
}
$Map += $row
}
$form.controls.addrange($map)
# Function to start a new game
function new-game {
$ml.text = "A new Game has Just started"
$script:clicks = 0
$script:pairs = 0
$script:sav = 0
# Randomize Imagelist
$R = new-object system.random
0..15 | foreach {
$map[$_].image = $null
$map[$_].enabled = $true
$rndNum = $R.next(1,17) - 1
$tmp = ($images[$_])
$images[$_] = ($images[$rndNum])
$images[$rndNum] = $tmp
}
}
# hit the Road
. new-game
$form.topmost = $true
$form.showdialog()