This blog has moved to http://ThePowerShellGuy.com
Greetings /\/\o\/\/
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