Author Topic: Windows PowerShell?  (Read 588 times)

What is this? My computer just updated and now there is this thing in accessories called "Windows PowerShell." It looks like command prompt but more newer looking. 

Tom

I think it's pretty much a newer command prompt with better scripting.

The same thing happened to me too... i dunno. i hope it's useful.

Hey I see it too

It's so purdy @___@

Powershell is basically a scripting language. I've written some stuff in it before.
The only productive thing I've used it for though is checking out process details.

MazeTest.ps1
Code: [Select]
cls

if(!(test-path $args[0]))
{
"Error: Must provide an existing file to read from."
return
}

$map  = get-content $args[0]
$xdim = $map[0].Length + 1
$ydim = $map.Length + 1
$ypos = 0
$key  = ""

foreach($line in $map)
{
if($line.IndexOf("S") -ne -1)
{
$xpos = $line.IndexOf("S")
break
}

$ypos++
}

$xorg = [console]::WindowWidth
$yorg = [console]::WindowHeight

[console]::SetWindowSize($xdim,$ydim)
[console]::SetBufferSize($xdim,$ydim)
[console]::CursorVisible = $false

$map
[console]::setCursorPosition($xpos,$ypos); ">"

while($key -ne "Escape")
{
$key  = [console]::ReadKey($true).Key
$xdir = 0
$ydir = 0

switch($key)
{
"UpArrow"    { $ydir = -1 }
"DownArrow"  { $ydir =  1 }
"LeftArrow"  { $xdir = -1 }
"RightArrow" { $xdir =  1 }
}

if($xdir -ne 0 -or $ydir -ne 0)
{
$newx = $xpos + $xdir
$newy = $ypos + $ydir

if($newx -ge 1 -and $newx -lt ($xdim - 1) -and $newy -ge 1 -and $newy -lt ($ydim - 1))
{
$chr = $map[$newy].Substring($newx,1)

if($chr -eq " " -or $chr -eq "S")
{
[console]::setCursorPosition($xpos,$ypos); " "

$xpos = $newx
$ypos = $newy

[console]::setCursorPosition($xpos,$ypos)

switch($xdir * 2 + $ydir)
{
-2 { "<" }
-1 { "^" }
1 { "V" }
2 { ">" }
}
}

if($chr -eq "F")
{
cls

$xpos = [console]::WindowWidth  / 2 - 4
$ypos = [console]::WindowHeight / 2 - 1

[console]::setCursorPosition($xpos,$ypos); "You won!"

$temp = $key

while($temp -eq $key)
{
$temp = [console]::ReadKey($true).Key
}

cls

[console]::SetWindowSize($xorg,$yorg)
[console]::SetBufferSize($xorg,$yorg)

return
}
}
}
}

cls

[console]::SetWindowSize($xorg,$yorg)
[console]::SetBufferSize($xorg,$yorg)

10x10.dat
Quote
                     
 #####################
 #       #       #   #
 ### ######### ### ###
 #       # # #   #   #
 ### ##### # # ### ###
 #       #         # #
 # # # # ### ##### # #
 # # # #       # #   #
 # ##### ### ### ### #
 # #     #     # # # #
 # # # ##### # # # # #
 # # # #   # #     # #
 # # ### # # ### #####
 # # #   #   #       #
 # ### ### # # ### # #
 # #     # # # #   # #
 ### ##### ### ### # #
 # # #       # #   # #
 # # ####### ### # # #
 S   #       #   # # #
 #######F#############

Then run ./MazeTest.ps1 10x10.dat to try it.