clsif(!(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)
##################### # # # # ### ######### ### ### # # # # # # ### ##### # # ### ### # # # # # # # # ### ##### # # # # # # # # # # ##### ### ### ### # # # # # # # # # # # ##### # # # # # # # # # # # # # # # ### # # ### ##### # # # # # # # ### ### # # ### # # # # # # # # # # ### ##### ### ### # # # # # # # # # # # ####### ### # # # S # # # # # #######F#############