Академический Документы
Профессиональный Документы
Культура Документы
#
# Script Name: TicTacToe.ps1 (The Tic-Tac-Toe Game)
# Version: 2.0
# Author: Nate
# Date: April 8, 2013
#
# Description: This PowerShell script is a two player implementation of the
# popular Tic-Tac-Toe game
#
# *************************************************************************
# Initialization Section
$A1 = "1"
$A2 = "1"
$A3 = "1"
$B1 = "1"
$B2 = " "
$B3 = " "
$C1 = " "
$C2 = " "
$C3 = " "
#This function displays the game board, showing each player's moves
function Display-Board {
$result #Return this value to the statement that called this function
}
#This function displays the game board and the final results of a round
#of play
function Display-Results {
while ($playGame -eq "True") { #This loop controls the logic required to
$move = Display-Board #Call function that displays the game board and
#collects player moves
$validMove = Validate-Move #Call the function that validates player moves
$moves++ #Increment variable that keeps track of the number of valid moves
#Assign the appropriate game board square to the player that selected it
if ($move -eq "A1") {$A1 = $player}
if ($move -eq "A2") {$A2 = $player}
if ($move -eq "A3") {$A3 = $player}
if ($move -eq "B1") {$B1 = $player}
if ($move -eq "B2") {$B2 = $player}
if ($move -eq "B3") {$B3 = $player}
if ($move -eq "C1") {$C1 = $player}
if ($move -eq "C2") {$C2 = $player}
if ($move -eq "C3") {$C3 = $player}
}
if ($winner -eq "X") { #Perform the following actions when Player X wins
if ($winner -eq "O") { #Perform the following actions when Player O wins
Write-Host `a #Make a beep sound
Display-Results #Call function that displays game results
$playGame = "False"
continue #Repeat this loop
}
$response = "False" #Set default value in order to ensure the loop executes
#Reset default variable settings to get ready for a new round of play
$response = "True"
$terminate = "False"
$playGame = "True"
Clear-Board
$player = "X"
$moves = 0
$tie = "False"
}
elseif ($response -eq "N") { #Time to quit