Update play-pong.ps1

This commit is contained in:
Markus Fleschutz 2023-09-18 12:22:26 +02:00
parent 9cdcf3c303
commit bee97e90c6

View File

@ -2,7 +2,8 @@
.SYNOPSIS .SYNOPSIS
Play the Pong game Play the Pong game
.DESCRIPTION .DESCRIPTION
This PowerShell script lets you play the Pong game. This PowerShell script lets 2 players play the famous Pong game.
NOTE: Player 1: <W> moves up, <S> moves down | Player 2: <UP> or <DOWN> | <ESC> to quit
.EXAMPLE .EXAMPLE
PS> ./play-pong.ps1 PS> ./play-pong.ps1
.LINK .LINK
@ -12,13 +13,13 @@
#> #>
function DrawScores { function DrawScores {
$middle = [System.Console]::WindowWidth / 2 $x = [System.Console]::WindowWidth / 2 - 4
[System.Console]::SetCursorPosition($middle - 4, 1) [System.Console]::SetCursorPosition($x, 1)
[System.Console]::Write("$($script:scorePlayer1) - $($script:scorePlayer2)") [System.Console]::Write("$($script:scorePlayer1) - $($script:scorePlayer2)")
} }
function DrawFooter { function DrawFooter {
$text = "| Player 1: <W> for up, <S> for down | Player 2: <UP> or <DOWN> | ESC key to quit |" $text = "| Player 1: <W> moves up, <S> moves down | Player 2: <UP> or <DOWN> | <ESC> to quit |"
$x = ([System.Console]::WindowWidth - $text.Length) / 2 $x = ([System.Console]::WindowWidth - $text.Length) / 2
$y = [System.Console]::WindowHeight - 1 $y = [System.Console]::WindowHeight - 1
[System.Console]::SetCursorPosition($x, $y) [System.Console]::SetCursorPosition($x, $y)
@ -54,7 +55,7 @@ function DrawBall($x, $y) {
return return
} }
[System.Console]::SetCursorPosition($x, $y) [System.Console]::SetCursorPosition($x, $y)
[System.Console]::Write("O") Write-Host "o" -foregroundColor red -noNewline
} }
function ClearBall($x, $y) { function ClearBall($x, $y) {
@ -152,4 +153,5 @@ while ($true) {
Start-Sleep -Milliseconds 100 Start-Sleep -Milliseconds 100
} }
[System.Console]::Clear() [System.Console]::Clear()
exit 0 # success