/\/\o\/\/ PowerShelled

This blog has moved to http://ThePowerShellGuy.com Greetings /\/\o\/\/
$AtomFeed = ("Atom.xml")
$PreviousItems = (" when to change your clock ? ask Monad !! "," AD Infastructure exploring with MSH "," Get Current dir in MSH consoleTtitle "," MSH ASCII translator "," red MSH> prompt "," Monad presentation on PDC05 available, "," A guided tour of the MSH on arstechnica.com "," Lets Query WMI from MSH "," Getting and using a SecurityPrincipal from MSH "," Line Breaks "," ")

Saturday, October 29, 2005

 


Thow Dices in MSH



Bored, ore just into some fun ?
Ask Monad to throw you some dices ;-)

Just load this script and type :

MSH> Throw-Dices

or

MSH> td 5

Have fun,

gr /\/\o\/\/


#ThrowDices.msh
# throws some dices
#/\/\o\/\/ 2005
function Throw-Dices{
Param ([int] $NumOfDice = 1)
  $R = new-object system.random([datetime]::now.Millisecond)
  $raw  = $host.ui.rawui
  $pos  = $raw.windowposition
  $size = $raw.buffersize

  # save old info 
  $rect = "system.management.automation.host.rectangle"
  $posOld = $pos
  $re = new-object $rect $pos.x,$pos.y,$size.width,($pos.y + 5)
  $buffer = $raw.getbuffercontents($re)
 
  #make some dice :
  for ( $i = 1; $i -le $NumOfDice; $i++ ){

    # get a Random number
    $dice = $R.next(1,7)

    # Write the Dice
    WriteDice $pos $dice
    # Move a bit   
    $pos.x = $pos.x + 6
    trap {"To many dices";$host.ui.rawui.SetBufferContents($posOld,$buffer);break}
  }
  # wait
  [void]$host.ui.rawui.ReadKey()
  # put back old info
  $host.ui.rawui.SetBufferContents($posOld,$buffer)
}

Function WriteDice {

  $pos = $args[0]
  $Num = $args[1]
  #possible Rows

  $rt0 = "     "
  $rt1 = " o   "
  $rt2 = "  o  "
  $rt3 = "   o "
  $rt4 = " o o "

  Switch ($num){
    1 {$r1 = $rt0; $r2 = $rt2; $r3 = $rt0}
    2 {$r1 = $rt1; $r2 = $rt0; $r3 = $rt3}
    3 {$r1 = $rt1; $r2 = $rt2; $r3 = $rt3}
    4 {$r1 = $rt4; $r2 = $rt0; $r3 = $rt4}
    5 {$r1 = $rt4; $r2 = $rt2; $r3 = $rt4}
    6 {$r1 = $rt4; $r2 = $rt2; $r3 = $rt4}
  }

  WriteDiceLine $rt0
  WriteDiceLine $r1
  WriteDiceLine $r2
  WriteDiceLine $r3
  WriteDiceLine $rt0

}
Function WriteDiceLine {
  $fgc = [system.consolecolor]"gray"
  $bgc = [system.consolecolor]"red"
  $row = $host.ui.rawui.NewBufferCellArray($args[0],$fgc,$bgc)
  $host.ui.rawui.SetBufferContents($pos,$row)
  $pos.y = $pos.y +1
}

Set-Alias td Throw-Dices



Comments: Post a Comment

Links to this post:

Create a Link



<< 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?