-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgameTest
More file actions
149 lines (131 loc) · 4.09 KB
/
Copy pathgameTest
File metadata and controls
149 lines (131 loc) · 4.09 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
var outputObj = document.getElementById("output");
var outputObj2 = document.getElementById("output2");
var outputObj3 = document.getElementById("hintText");
var rand;
var numGuesses;
var maxNum;
var user;
var guess;
var count =0;
var themeNum=1;
function start(){
window.location.href = 'game.html';
}
function instructions(){
window.location.href = 'instructions.html';
}
function initialize() {
var status = true;
while (status) {
user = prompt("What is your name");
if (user !== null && user.trim() !== "") {
status = false;
}
else{
alert("Please input a username!");
}
}
status = true;
while (status) {
numGuesses = parseInt(prompt("How many guesses do you want?"));
if (numGuesses !== null && !isNaN(numGuesses)) {
status = false;
}
else{
alert("Please input a number!");
}
}
status = true;
while (status) {
maxNum = parseInt(prompt("What is the max number you want to guess up until (1-x)?"));
if (maxNum !== null && !isNaN(maxNum)) {
status = false;
}
else{
alert("Please input a number!");
}
}
rand = randomNum(parseInt(maxNum));
outputObj2.innerHTML = "You have "+numGuesses+ " guesses left!";
document.getElementById('output').textContent = "Welcome "+user+"!";
}
function userGuess() {
count +=1
if (count==1){
outputObj3.innerHTML ="";
}
guess = parseInt(document.getElementById("N").value);
numGuesses -=1;
if(guess<0||guess>maxNum){
document.getElementById('output').textContent = "Please put a number in range!";
document.getElementById('output').style.color = '#FFC0CB';
numGuesses +=1;
}
else if(numGuesses===0){
alert("You Lost! The number was "+rand);
if (themeNum=1){
window.open("loserSea.html", "_blank");
}
else if(themeNum =2){
window.open("loserSea.html", "_blank");
//MAKE OTHER 2 LOSING SCREENS AND INSERT
}
else if(themeNum=3){
window.open("loserSea.html", "_blank");
//MAKE OTHER 2 LOSING SCREENS AND INSERT
}
//insert functoiin that takes user to losing page based on which theme is selected;
}
else if (guess===rand){
alert("Correct!!");
if (themeNum=1){
window.open("loserSea.html", "_blank");
}
else if(themeNum =2){
window.open("winnerAutumn.html", "_blank");
//MAKE OTHER 2 LOSING SCREENS AND INSERT
}
else if(themeNum=3){
window.open("winnerMagic.html", "_blank");
//MAKE OTHER 2 LOSING SCREENS AND INSERT
}
//insert functoiin that takes user to losing page based on which theme is selected;
}
else{
document.getElementById('output').textContent = "Incorrect!";
document.getElementById('output').style.color = '#e74c3c';
}
outputObj2.innerHTML = "You have "+numGuesses+" guesses left";
}
function randomNum(num) {
rand = Math.floor(Math.random() * num)+1;
return rand
}
function hint() {
count =0;
numGuesses -=1;
if (guess > rand) {
outputObj3.innerHTML = "Your last guess is bigger than the number I have";
}
else{
outputObj3.innerHTML = "Your last guess is lower than the number I have";
}
outputObj2.innerHTML = "You have "+numGuesses+" left";
}
function theme(n){
if(n==1){
themeNum=1;
document.getElementById('theme').href='game1.css';
document.getElementById('nameOfGame').innerHTML='🪼🌊GUESS THE NUMBER🌊🪼';
}
if(n==2){
themeNum =2;
document.getElementById('theme').href='game2.css';
document.getElementById('nameOfGame').innerHTML='🍁🍂GUESS THE NUMBER🍂🍁';
}
if(n==3){
themeNum=3;
document.getElementById('theme').href='game3.css';
document.getElementById('nameOfGame').innerHTML='⋆˖⁺‧₊☽GUESS THE NUMBER☾₊‧⁺˖⋆';
}
}