/\/\o\/\/ PowerShelled

This blog has moved to http://ThePowerShellGuy.com Greetings /\/\o\/\/
$AtomFeed = ("Atom.xml")
$PreviousItems = (" scripting games part 3 "," 2006 Winter Scripting Games (part 2) "," Monad hosting "," Get current user in Monad "," Different ways to do things in Monad, and some links "," 2006 Winter Scripting Games "," Check spelling with MSN Search from MSH (Part 3) "," Search with MSNSearch Web API from MSH (Part 2) "," Search with MSNSearch Web API from MSH (Part 1) "," about_Switch Documentation "," ")

Friday, February 17, 2006

 


MSH Concentration (scripting games part 4)



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 :


# 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() 




Comments: Post a Comment



<< Home

Archives

October 2005   November 2005   December 2005   January 2006   February 2006   March 2006   April 2006   May 2006   June 2006   July 2006   August 2006   September 2006   October 2006   November 2006   December 2006  

$Links = ("PowerShell RC1 Docs"," PowerShell RC1 X86"," PowerShell RC1 X64"," Monad GettingStarted guide"," Monad Progamming Guide"," Monad SDK"," Monad videos on Channel 9"," MSH Community Workspace"," scripts.readify.net "," MonadSource"," www.reskit.net"," PowerShell Blog"," Under The Stairs"," computerperformance powershell Home"," proudlyserving"," MSH on wikipedia"," MSHWiki Channel 9"," Keith Hill's Blog"," Precision Computing"," PowerShell for fun"," MSH Memo (Japanese)"," monadblog")

find-blog -about "PowerShell","Monad" | out-Technorati.
find-blog -contains "","" | out-Technorati.
Google
 
Web mow001.blogspot.com

This page is powered by Blogger. Isn't yours?