forked from Lydraine/PsYchoPiQ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
379 lines (327 loc) · 11.5 KB
/
index.php
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
<?php
/************************************************************************
************************************************************************
*Program Name : PsYchoPiQ *
************************************************************************
*Organisation : Lydraine *
************************************************************************
*Version : Nice Nurse <1.5.7> *
************************************************************************
*Contributors : Tobalase Akinyemi <[email protected]> *
* Olumide Olusesi <[email protected]> *
* Ewere Igumbor <[email protected]> *
* Falade Jesutofunmi<[email protected]> *
* <add your name and email here on improvement> *
************************************************************************
*Summary : A guessing game that picks a random number between 0 *
* and 101 and asks you to guess the number inputing *
* guides to making the right guess with colors to signify*
* different alerts *
************************************************************************
*Improvements : *Image buttons added to most pages(pretty) *
* *Email Validation updated(alerts to HTML) *
* *Name has been changed to Nickname(maxlength=12) *
* *Nickname Validtion Added *
* *User Interface Updated[more wallpapers] *
* *Name Recognition on play added *
* *Difficulty stage added *
* *Gender Recognition added *
* *Emoticons Added *
* *Refresh and Session TimeOut bug fixed *
************************************************************************
*License : *Creative Commons *
* Attribution-NonCommercial-ShareAlike 4.0 *
* International License(Link Included in footer) *
************************************************************************
************************************************************************/
?>
<?php
// ***PRE-DISPLAY***
require_once 'functions.php';
require_once 'config.php';
session_start();
persist();
if(isset($_POST['welcome'])) {
$_SESSION['welcome'] = true;
} else {
$color = "purple";
}
// Check if email has been entered just previously.
if(isset($_POST['email'])) {
// Check for empty email field before initializing variables.
if(($_POST['email'] != "" and $_POST['name'] != "")) {
enter_user();
// Initialize variables for number, number of guesses
// and email address respectively.
$_SESSION['name'] = $_POST['name'];
$_SESSION['number'] = rand( 1, 100 );
$_SESSION['tries']= 0;
$_SESSION['email'] = $_POST['email'];
$_SESSION['sex'] = $_POST['sex'];
$_SESSION['difficulty'] = $_POST['difficulty'];
// Update number of game attempts in database.
update_attempts();
}
}
// If user quits during gameplay
if(isset( $_POST['quit_x'] )) {
// Retain still unknown number in a variable
$prev_number = $_SESSION['number'];
// Then unset session value for number
unset( $_SESSION['number'] );
// Set background color to orange
$color = "orange";
}
// Check for affirmative replay.
elseif(isset( $_POST['replay_x'] )) {
// Update number of game attempts in database.
update_attempts();
// Re-initialize variables for number and number of guesses.
$_SESSION['number'] = rand( 1, 100 );
$_SESSION['tries']= 0;
}
// Otherwise in the case of game exit.
elseif(isset( $_POST['exit_x'] )) {
// End User Session.
$_SESSION= array();
setcookie( session_name(), NULL, time() -(60 * 60 * 24 * 7 * 52 * 2000) );
session_destroy();
$color = "purple";
}
?>
<?php
// Set initial page background color to purple.
$color = "purple";
// Check if guess has been submitted and
// set for appropriate error messages for invalid guesses.
if(isset( $_POST['guess'] )) {
// Check if guess is empty.
if($_POST['guess'] == "") {
$errmsg = "Please Enter Your Guess.";
}
// Check if guess is numeric.
elseif(!is_numeric( $_POST['guess'] )) {
$errmsg = "Your guess should be a number!!!";
}
// Check if guess is within the range of 1-100
elseif(($_POST['guess'] < 1) or($_POST['guess'] > 100)) {
$errmsg = "Your Guess should not be less than 1 or more than 100.";
}
// Do not display errors if welcome page hasn't been passed
if(!isset( $_SESSION['welcome'] )) {
unset( $errmsg );
}
// Check if there are errors.
// Unset the guess too if there are errors.
// Changing the background color if there are.
if(isset( $errmsg )) {
$_POST['guess'] = NULL;
$color = "orange";
} else {
$color = "purple";
}
}
// ##Guess Validation##
// Check if there are no errors by checking for presence of guess variable
// and absence of error message.
if((isset( $_POST['submit_x'] ) and isset( $_POST['guess'] )) and !isset( $errmsg )) {
// Set number by getting number variable from cookie.
$number = $_SESSION['number'];
// Set guess from form input.
$guess = $_POST['guess'];
// Set background color to green if guess is correct.
if($number == $guess) {
$color = "green";
}
// Set background color to orange if user quits midway
elseif(isset( $_POST['quit_x'] )) {
$color = "orange";
}
// Guess can only be wrong if it isn't right.
// So set background color to maroon.
else {
$color = "maroon";
}
// Add one to number of guesses.
$_SESSION['tries']++;
}
?>
<?php include 'det.php'; ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>PsYchoPiQ</title>
<!-- External Scripts -->
<script src="jquery/jquery-1.11.1.min.js"></script>
<script src="code.bits/validation.js"></script>
<script src="code.bits/validation2.js"></script>
<!-- Include Bootstrap css -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/bootstrap-theme.min.css" rel="stylesheet">
<style>
<!--<?php include('css/custom.php.css');?>-->
</style>
</head>
<body>
<div class="body">
<img id = "logo" src = "img/logo1/<?php echo $color;?>.png" />
<form
name = "asker"
action = "./"
<?php if(isset($_POST['welcome']) OR isset($_POST['email'])) {echo " onsubmit='return Evalidate()' ";} ?>
method = "POST">
<h2>
<?php
// ***HEADER***
// Check if welcome page has been passed
if(isset($_SESSION['welcome'])) {
// Print greeting message if background color is purple and
// email has been supplied.
if((isset($_SESSION['email']) AND isset($_SESSION['name'])) AND $color == "purple") {
?>
I have chosen a number <b>randomly</b> from 1 to 100
What Do You Think It Is?
<?php
}
// Print previously randomized number if user quits
// ##Addictive PeekBox##
elseif(isset($_POST['quit_x'])) {
echo "Awww... :(" . "<br/>" .
"You Didn't Have To Quit." . "<br/>" .
"The number was {$prev_number}" . "<br/>";
// Set color to green so that replay question is asked. **TRICKY**
$color = "green";
}
// Print error message if there is any.
elseif(isset($errmsg)) {echo "Invalid Input". "<br/>" . $errmsg ; }
// ##Guess Validator - Text Indication##
// Check if email has been set.
elseif((isset($_SESSION['email']) AND isset($_SESSION['name']))) {
// Print "RiGHt" if guess is correct.
if($number == $guess) {
$u = $_SESSION['name'];
?> <img id="emoticon" src="img/emoticons/yolks/grin.png"> <?php
echo "OhYeah!!!, {$u}, You're RiGHT";
}
// Print "wRUNG" if guess is wrong.
else{
?><img id="emoticon" src="img/emoticons/yolks/hope my fake smile works again.png"><?php
echo "wRUNG";
}
}
}else{$color = "purple";}
?>
</h2>
<?php
// ***INPUT FIELDS***
// Check if welcome page has been passed
if(isset($_SESSION['welcome'])) {
// Display input form if guess is incorrect after
// email has been supplied and not before.
if((isset($_SESSION['email']) AND isset($_SESSION['name'])) AND $color != "green") { ?>
<div id = "guessbox">
<input
name = "guess"
<?php if($_SESSION['tries']== 0){ ?>required = "true"<?php } ?>
autofocus = "true"
autocomplete ="off"
type = "number"
min = "1"
max = "100" />
<input
name = "submit"
type = "image"
src = "img/btn/enter0.png"
onMouseOver = "this.src = 'img/btn/enter1.png'"
onClick = "this.src = 'img/btn/enter1.png'; return Nvalidate()"
onMouseOut = "this.src = 'img/btn/enter0.png'" />
<?php if(($color != "purple" AND $color != "orange") OR $_SESSION['tries']> 0) { ?>
<input
name = "quit"
id = "quit"
type = "image"
src = "img/btn/quit1.png"
onMouseOver = "this.src = 'img/btn/quit2.png'"
onClick = "this.src = 'img/btn/quit0.png'"
onMouseOut = "this.src = 'img/btn/quit1.png'" />
<?php
}
?>
</div>
<?php
}
// Display Replay question if guess is correct.
elseif($color == "green") { ?>
<h3>Wanna Try Again?</h3>
<br/>
<input
name = "replay"
type = "image"
src = "img/btn/yes1.png"
height = "25px"
onMouseOver = "this.src = 'img/btn/yes0.png'"
onClick = "this.src = 'img/btn/yes0.png'"
onMouseOut = "this.src = 'img/btn/yes1.png'" />
<input
name = "exit"
type = "image"
src = "img/btn/no1.png"
height = "25px"
onMouseOver = "this.src = 'img/btn/no0.png'"
onClick = "this.src = 'img/btn/no0.png'"
onMouseOut = "this.src = 'img/btn/no1.png'" />
<?php if(isset($prev_number)) {$color = "orange";}
}
// Request email if it hasn't been entered.
else{include 'inform.php';}
}
// Print Welcome Message and Display acknowledgement button
else{ ?>
<h3>Click The Button Below To See How Fast You Are Against A Computer</h3>
<button name = "welcome" type = "submit">ENTER</button>
<?php
}
?>
<h2>
<?php
// ***SUB-MESSAGES***
// Unset number session variable when guess is correct.
// Print number of guesses and unset the related session variable when guess is correct.
if(isset($number) AND(($number == $guess) AND($color == "green"))) {
// Update number of successful game completions in database.
update_plays();
echo "It took you " . $_SESSION['tries'] . " guess";
if($_SESSION['tries'] > 1) {echo "es";}
echo ".";
// Update least number of tries in database.
update_tries();
// Unset session variables for number of tries and number.
unset($_SESSION['tries']);
unset($_SESSION['number']);
}
// If guess is incorrect, print guide if not in difficult mode.
elseif($_SESSION['difficulty'] !== 'difficult') {
if($number > $guess) {echo "Try A Higher Number, {$g}";}
elseif ($number < $guess) {echo "Try A Lower Number, {$g}";}
}
// print out for difficult mode.
elseif($_SESSION['difficulty'] == 'difficult' and $number != $guess) {
echo "Try Again, {$g}";
}
?>
</h2>
</form>
<script src = "js/bootstrap.min.js"></script>
<?php if (file_exists($DEBUG)) {include_once($DEBUG);} ?>
</div>
<?php
//ADD-IN SCRIPT SETTINGS
if($COUNTER == true) {include_once('counter.php');}
if($GANALYTICS == true) {include_once('ganalytics.php');}
?>
<?php include 'license.php';?>
<footer>©<?php echo date('Y'); ?> Lydraine Group</footer>
</body>
</html>