-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPRSGamewithDyn.ps1
201 lines (160 loc) · 4.9 KB
/
PRSGamewithDyn.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
Clear-Host
$NewGame = "True" #This variable controls the game
$UserReply = 0 #
$UserChoice = "" #This variable will hold the letter choice of the user
$RanNum = 0 #This variable will be used to generate a random number for the computer's choice
$CompChoice = "" #This variable will be the converted integer to a letter representing the computer's choice
$AmountPlayed = 0 #Keeps track of how many games the user has played during the session
$Wins = 0 #Keeps track of the User's wins
$Losses = 0 #Keeps track of the User's losses
$Ties = 0 #Keeps track of the User's ties
Write-Host " Welcome to the"
Write-Host "Rock, Paper, Scissors Game!"
Write-Host " WIT Operating Systems"
Write-Host " "
Write-Host "Press Enter to Continue"
Read-Host
while($NewGame -ne "False") {
$RanNum = Get-Random -Minimum 1 -Maximum 4 #Generate a new number between 1 and 3
if ($RanNum -eq 1) {
$CompChoice = "Rock"
}
if ($RanNum -eq 2) {
$CompChoice = "Paper"
}
if ($RanNum -eq 3) {
$CompChoice = "Scissors"
}
While ($UserReply -eq "") {
Clear-Host
Write-Host "Enter one of the following options"
Write-Host "-----------------------------------"
Write-Host " "
Write-Host "R is for Rock"
Write-Host "P is for Paper"
Write-Host "S is for Scissors"
Write-Host "Q is for Quit"
Write-Host " "
Write-Host "-----------------------------------"
$UserReply = Read-Host "Make a move"
}
if($UserReply -eq "Q") {
Clear-Host
Write-Host " "
Write-Host "Game over. Thanks for playing Rock, Paper Scissors."
Write-Host " "
Write-Host "Press enter to view game statistics and quit the game."
Read-Host
Clear-Host
Write-Host "Game Statistics"
Write-Host "------------------------------"
Write-Host "Number of games played: $AmountPlayed"
Write-Host "Number of games won: $Wins"
Write-Host "Number of games lost: $Losses"
Write-Host "Number of games tied: $Ties"
Write-Host " ------------------------------"
Write-Host "Press Enter to continue."
Read-Host
$NewGame = "False"
continue
}
elseif(($UserReply -ne "R") -and ($UserReply -ne "P") -and ($UserReply -ne "S") -and ($UserReply -ne "D")) {
Clear-Host
Write-Host "Invalid input. Please try again."
Read-Host
$UserReply = ""
continue
}
if ($UserReply -eq "R") {
$UserChoice = "Rock"
}
if ($UserReply -eq "P") {
$UserChoice = "Paper"
}
if ($UserReply -eq "S") {
$UserChoice = "Scissors"
}
if ($UserReply -eq "D") {
$UserChoice = "Dynamite"
}
Clear-Host
Write-Host "Results:"
Write-Host "-----------------------------------"
Write-Host " "
Write-Host "The computer picked: $CompChoice"
Write-Host "You picked: $UserChoice"
Write-Host " "
Write-Host "-----------------------------------"
$AmountPlayed += 1
Switch ($CompChoice) {
"Rock" {
if ($UserChoice -eq "Rock") {
$Ties += 1
Write-Host "Tie!"
}
if ($UserChoice -eq "Paper") {
$Wins += 1
Write-Host "You Win!"
}
if ($UserChoice -eq "Scissors") {
$Losses += 1
Write-Host "Computer Wins!"
}
if ($UserChoice -eq "Dynamite") {
$Wins += 1
Write-Host "You always win with DYNAMITE!!!"
}
}
"Paper" {
if ($UserChoice -eq "Paper") {
$Ties += 1
Write-Host "Tie!"
}
if ($UserChoice -eq "Rock") {
$Losses += 1
Write-Host "Computer Wins!"
}
if ($UserChoice -eq "Scissors") {
$Wins += 1
Write-Host "You Win!"
}
if ($UserChoice -eq "Dynamite") {
$Wins += 1
Write-Host "You always win with DYNAMITE!!!"
}
}
"Scissors" {
if ($UserChoice -eq "Scissors") {
$Ties += 1
Write-Host "Tie!"
}
if ($UserChoice -eq "Rock") {
$Wins += 1
Write-Host "You Win!"
}
if($UserChoice -eq "Paper") {
$Losses += 1
Write-Host "Computer Wins!"
}
if ($UserChoice -eq "Dynamite") {
$Wins += 1
Write-Host "You always win with DYNAMITE!!!"
}
}
}
Read-Host
$UserReply = 0 #Reset all variables
$UserChoice = ""
$RanNum = 0
$CompChoice = ""
Clear-Host
Write-Host "Game Statistics"
Write-Host "------------------------------"
Write-Host "Number of games played: $AmountPlayed"
Write-Host "Number of games won: $Wins"
Write-Host "Number of games lost: $Losses"
Write-Host "Number of games tied: $Ties"
Write-Host " ------------------------------"
Write-Host "Press Enter to continue."
Read-Host
}