-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
175 lines (157 loc) Β· 6.42 KB
/
script.js
File metadata and controls
175 lines (157 loc) Β· 6.42 KB
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
/*
How many hours did you spend on this assignment?:
More than 10 hours
What part of the assignment did you spend the most time on?:
Game mode and Errors with input validation. errors like My game was adding +1 everytime I click Submit button even while changing game mode.
How comfortable did you feel with this assignment? (1-5):
I could resolve error faster compared to earlier stage, feel pretty comfortable.
Is there anything in this code that you feel pleased about?:.
Counting total games and records, Input validation's placing with else {}.
What's one aspect of your code you would like specific, elaborate feedback on?:
code blocks I think.
Thanks!
*/
var gamemode = "intro";
// game default start in intro mode for inputting name, can be changed into 'Real Game Mode' &'prank mode'.
var PlayerName = "";
var STONE = "stone";
var PAPER = "paper";
var SCISSOR = "scissor";
var totalgamePlayed = 0;
var winS = 0;
var losseS = 0;
var tie = 0;
function WinningRate() {
if (winS == 0) {
return 0;
}else {
return (winS/totalgamePlayed)*100;
}
}
var WinRatee = WinningRate();
console.log(WinRatee);
console.log(WinningRate());
//var myOutputValue = "";
function random() {
var random = Math.floor(Math.random() * 3) + 1;
var result = "";
if (random == 1) {
result = STONE;
} else if (random == 2) {
result = PAPER;
} else if (random == 3) {
result = SCISSOR;
}
return result;
}
var main = function (input) {
if (gamemode == "intro") {
PlayerName = input;
gamemode = "Real Game";
return "YalamBBBa!! " + PlayerName + "<br>Type any one (Paper or Scissor, Stone) for SPS game or <br>'r' real game mode ,'p' for Prank mode and 'e' to END the game";
} else if (gamemode == "Real Game") {
var userInput = input.toLowerCase().trim();
var computer = random();
if (userInput == "r") {
gamemode = "Real Game";
return `Game mode switched to <b>${gamemode}<b/>`;
} else if (userInput == "p") {
gamemode = "Prank";
return `Game mode switched to <b>${gamemode}<b/>`;
} else if (userInput == "e") {
gamemode = "intro";
return "Please type new player's name."
}
console.log("Computer", computer);
console.log("Player", userInput);
console.log(WinRatee);
if (gamemode == "Real Game") {
if (userInput == computer) {
totalgamePlayed++;
tie++;
var output1 = "";
if (computer == STONE) {
output1 = "stone π₯";
} else if (computer == PAPER) {
output1 = "paper π";
} else {
output1 = "scissor βοΈ";
}
console.log("Tie is working");
myOutputValue = `<b>Its a Tie!! <br> Computer ${output1} You ${output1}`;
} else if (userInput == PAPER && computer == SCISSOR) {
totalgamePlayed++;
myOutputValue = `You lose! <br> Computer βοΈ ${computer.toUpperCase()} You π ${userInput.toUpperCase()}`;
losseS++;
} else if (computer == PAPER && userInput == SCISSOR) {
totalgamePlayed++;
winS++;
myOutputValue = `You Win! <br> Computer π ${computer.toUpperCase()} You βοΈ ${userInput.toUpperCase()}`;
} else if (computer == STONE && userInput == SCISSOR) {
totalgamePlayed++;
myOutputValue = `You lose! <br> Computer π₯ ${computer.toUpperCase()} You βοΈ ${userInput.toUpperCase()}`;
losseS++;
} else if (computer == SCISSOR && userInput == STONE) {
totalgamePlayed++;
winS++;
myOutputValue = `You Win! <br> Computer βοΈ${computer.toUpperCase()} You π₯ ${userInput.toUpperCase()}`;
} else if (computer == STONE && userInput == PAPER) {
totalgamePlayed++;
winS++;
myOutputValue = `You Win! <br> Computer π₯ ${computer.toUpperCase()} You π ${userInput.toUpperCase()}`;
} else if (computer == PAPER && userInput == STONE) {
totalgamePlayed++;
losseS++;
myOutputValue = `You lose! <br> Computer π ${computer.toUpperCase()} You π₯ ${userInput.toUpperCase()}`;
} else {
return "Type any one (Paper or Scissor, Stone)";
}
return `<b>${PlayerName},${gamemode} <br>${myOutputValue} <br> Game Played: ${totalgamePlayed} *Wins: ${winS} *Tie: ${tie} *Loss: ${losseS} *Win Rate: ${WinRatee.toFixed(2)}%<br> Press 'r' for Actual SPS game and 'p' for Prank mode`;
}
}
if (gamemode == "Prank") {
var userInput = input.toLowerCase();
var computer = random();
if (computer == userInput) {
totalgamePlayed++;
tie++;
var output2 = "";
if (computer == STONE) {
output2 = "stone π₯";
} else if (computer == PAPER) {
output2 = "paper π";
} else {
output2 = "scissor βοΈ";
}
console.log("Prank Tie is working");
myOutputValue = `<b>Its a Tie!! <br> Computer ${output2} You ${output2}`;
} else if (computer == SCISSOR && userInput == STONE) {
totalgamePlayed++;
myOutputValue = `You lose! <br> Computer βοΈ ${computer.toUpperCase()} You π₯ ${userInput.toUpperCase()}`;
losseS++;
} else if (computer == PAPER && userInput == STONE) {
totalgamePlayed++;
winS++;
myOutputValue = `You Win! <br> Computer π ${computer.toUpperCase()} You π₯ ${userInput.toUpperCase()}`;
} else if (computer == STONE && userInput == PAPER) {
totalgamePlayed++;
myOutputValue = `You lose! <br> Computer π₯ ${computer.toUpperCase()} You π ${userInput.toUpperCase()}`;
losseS++;
} else if (computer == SCISSOR && userInput == PAPER) {
totalgamePlayed++;
winS++;
myOutputValue = `You Win! <br> Computer βοΈ ${computer.toUpperCase()} You π ${userInput.toUpperCase()}`;
} else if (computer == STONE && userInput == SCISSOR) {
totalgamePlayed++;
winS++;
myOutputValue = `You Win! <br> Computer π₯ ${computer.toUpperCase()} You βοΈ ${userInput.toUpperCase()}`;
} else if (computer == PAPER && userInput == SCISSOR) {
totalgamePlayed++;
losseS++;
myOutputValue = `You lose! <br> Computer π ${computer.toUpperCase()} You βοΈ ${userInput.toUpperCase()}`;
} else {
return "Type any one (Paper or Scissor, Stone)";
}
return `<b>${PlayerName},${gamemode} <br>${myOutputValue} <br> Game Played: ${totalgamePlayed} *Wins: ${winS} *Tie: ${tie} *Loss: ${losseS} *Win Rate: ${WinRatee.toFixed(2)}%<br> Press 'r' for Actual SPS game and 'p' for Prank mode`;
}
};