Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
introduction to tic tac toe game
#this function converts a value to pixels to create billy
function write-billy{
#these are the pixels(spaces) that make up the ascii image
$billy = ('sb8','nl9','sb6','sl4','sw5','nl4','sb5','sl3','sw9',
'nl3', 'sb4','sl3','sw11','nl3','sb3','sl3','sw3','sr3','sw1',
'sr3','sw3','nl3','sb3','sl3','sw2','sl1','sr1','sl1','sr1','sw1',
'sr1','sl1','sr1','sl1','sw2','nl4','sb2','sl3','sw4','sr3','sw1',
'sr3','sw4','nl3','sb2','sl3','sw1','sr1','sw1','sr1','sw7','sr1',
'sw1','sr1','sw1','nl3','sb1','sl5','sw1','sr1','sw9','sr1','sw1',
'nl5','sb1','sl7','sw1','sr7','sw1','nl7','sb2','sl6','sw2','sl1',
'sw3','sl1','sw2','nl6','sb3','sl4','sr2','sw1','sl1','sw3','sl1',
'sw1','sr2','nl4','sb7','sl1','sr9','nl1','sb5','sl2','sr2','sl2',
'sw3','sl2','sr2','nl2','sb3','sl9','nl9','sb2','nl21','sb1','nl23')
foreach ($i in $billy){
#this part determines how many spaces to print
if ($i.length -eq 3){
$manychars = $i.substring(2,1)}
else {
$manychars = $i.substring(2,2)}
#this next part determines the color to print
if ($i.substring(1,1) -eq 'b'){
$color = ""}
elseif ($i.substring(1,1) -eq 'l'){
$color = ' -backgroundcolor black'}
elseif ($i.substring(1,1) -eq 'w'){
$color = ' -backgroundcolor white'}
else {
$color = ' -backgroundcolor red'}
#this part determines if it needs a -nonewline added
if ($i.substring(0,1) -eq 's'){
$newline = " -nonewline"}
else {
$newline = " "}
Invoke-Expression "write-host (' '*$manychars) $color $newline"}
}
function write-slow ($text, $delay){
$textarray = $text.split(" ")
foreach ($i in $textarray){
$final = $i + " "
Write-Host -NoNewline $final
Start-Sleep -Milliseconds $delay}
write-host}
write-billy
Write-Host
write-slow 'Would you like to play a game?' 125
Write-Host
write-slow 'press enter to fulfill your destiny' 125
read-host
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment