Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Powershell Scripting | Switch Statements

$
0
0

Hello! I'm a student and currently am taking powershell. We are finally doing scripting, and I have to make a rock paper scissors game. This is my first ever language, so sorry if I sound braindead. lmao

Instructions: "Determine results. Display the player's move and the computer's move to the screen. Using a switch statement, analyze the results of the game. (Remember Paper beats Rock, Rock beats Scissors, Scissors beats Paper - otherwise, if the selections are the same, it's a tie.) "

# 
# Script Name: RockPaperScissors.ps1 (Rock, Paper, Scissors Game)
#
# Creator:     
#
# Date:        03/31/2019
#
# Descrption:  This is a game of rock paper scissors. The player goes against the computer
#

Clear-Host
$gameControlTrueFalse = "True" # This variable controls the game play
$cpuMoveNumber = 0             # This variable keepts track of computer's move number
$playerMoveLetter = ""         # This variable represents the player's move letter
$cpuMoveWord = ""              # This variable is the computer's move word
$playerMoveWord = ""           # This variable is the player's move word
$gamesPlayed = 0               # This variable is the total amount of games played
$playerWins = 0                # This variable is the amount of games the player has won
$playerLosses = 0              # This variable is the amount of games the player has lost
$playerTies = 0                # This variable is the amount of games the player has tied

Write-Output "`n`n`n`t`t`t`tWELCOME TO THE`n`n`n`n`t`t   ROCK, PAPER, SCISSORS GAME`n`n`n`n`n`nPress Enter to continue."
#This line above displays the welcome screen to users.
Read-Host

$cpuMoveNumber = Get-Random -minimum 1 -maximum 4
#1 is Rock 2 is Paper 3 is Scissors

if ($cpuMoveNumber -eq 1) {$cpuMoveWord = "Rock"}
if ($cpuMoveNumber -eq 2) {$cpuMoveWord = "Paper"}
if ($cpuMoveNumber -eq 3) {$cpuMoveWord = "Scissors"}
Clear-Host

Write-Output "`n`n`n`t`t`tEnter one of the following options:`n`n`t`t`t--------------------`n`n`t`t`tR = Rock`n`t`t`tP = Paper`n`t`t`tS = Scissors`n`t`t`tQ = Quit`n`n`t`t`t---------------------`n`n`t`t`tMake a move:"
Read-Host
$userReply += $playerMoveLetter

if ($playerMoveLetter -eq "R") {$playerMoveWord = "Rock"}
elseif ($playerMoveLetter -eq "P") {$playerMoveWord = "Paper"}
elseif ($playerMoveLetter -eq "S") {$playerMoveWord = "Scissors"}
elseif ($playerMoveLetter -eq "Q") {Clear-Host 
Write-Output "Thank's for playing."
$gameControlTrueFalse = "False"}
else {Write-Output "Invalid input. Please try again."
Read-Host
$playerMoveLetter = ""}

Switch ($cpuMoveNumber)
{
    1 {Write-Host "this is a test"}  

In my direction, i am being asked about 2 different variables. Can I put 2 different variables? If so then how, I've tried to google but I can't really find anything close to what I'm looking for. 

If anyone could just tell me what I should do and like explain to me step my step, and what everything does and means, I would appreciate it. 


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>