-
Notifications
You must be signed in to change notification settings - Fork 1
/
random.php
170 lines (147 loc) · 5.35 KB
/
random.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
<?php
/*
Kremica was coded entirely by Ryan Johnston, a senior at the University
of Pittsburgh. Kremica is meant to be an enjoyable (yet frustrating)
game that will not over-burden a student. Rather, the game functions as
something to do on a quick study break. Make a character, play until the
character dies, go back to studying.
Copyright (C) 2010 Ryan Johnston
For a copy of the GNU GPL, visit:
http://www.gnu.org/licenses/gpl.html
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
session_start();
if (!isset($_SESSION['randomencounter'])) {
//header( 'Location: http://www.kremica.com' ) ;
header( 'Location: index.php' ) ;
exit;
}
if (isset($_SESSION['name']) && (isset($_SESSION['monstername']) || ($_SESSION['strength']+$_SESSION['defense']<(3*$_SESSION['level'])-1))) {
//header( 'Location: http://www.kremica.com' ) ;
header( 'Location: fight.php' ) ;
exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Kremica: Random Encounter</title>
<link rel="stylesheet" type="text/css" href="stylesheet.css" />
</head>
<body>
<div id="wrapper">
<div id="header">
<?php
include 'inc_userheader.php';
?>
</div>
<div id="conent">
<?php
//If character is coming back from a quest battle, re-direct them to their current quest page
if (isset($_SESSION['questfight'])) {
include($_SESSION['questfile']);
}
else {
//If character is not currently on a quest
if (!isset($_SESSION['questfile'])) {
include 'inc_connection.php';
//First, see which quests the character has done (questscompleted table)
$questcompletequery="SELECT questscompleted.questID FROM questscompleted, characters WHERE characters.characterid=questscompleted.characterID AND characters.name='" . $_SESSION['name'] . "'";
$questcompleteresult=mysql_query($questcompletequery);
include 'inc_close_connection.php';
//Next put the IDs of all quests completed by this character into an array
$questcompletearray=array();
while ($row=mysql_fetch_assoc($questcompleteresult)) {
$questcompletearray[]=$row['questID'];
}
//Now what will happen: we'll try picking quests from the folder until we hit one the character hasn't completed yet,
//aka one that is not in the $questscompletearray
$directory = "questincludes/1/";
//Count number of quests in the directory
$filecount = count(glob("inc_quest*.php"));
//Put these numbers into an array
$filecountarray=array();
while ($filecount>0) {
$filecountarray[]=$filecount;
$filecount--;
}
//Now, randomly pick a number from the array until you hit one the character hasn't completed yet.
//If you find one the character has completed, remove it from the array
$questfound=FALSE;
$nomorequests=FALSE;
$random=0;
while (!$questfound) {
//If we got through the entire $filecountarray and found nothing (aka the count is now 0, exit the while loop
if (count($filecountarray)==0) {
$questfound=TRUE;
$nomorequests=TRUE;
break;
}
//Pick a random number from the quests left
$random = array_rand($filecountarray);
//If the quest is not in the $questcompletearray[], set $questfound to TRUE;
if (!in_array($filecountarray[$random], $questcompletearray)) {
$questfound=TRUE;
}
//If the quest is in the $questcompletearray[], remove the quest number from $filecountarray[]
else {
foreach($filecountarray as $key => $value) {
if ($filecountarray[$random]==$value) {
unset($filecountarray[$key]);
$filecountarray=array_values($filecountarray);
break;
}
}
}
}
//If a quest was found, include it.
if (!$nomorequests) {
//Pick the folder appropriate to the character's level
//Normally, these would be put into folders. However, for the purpose of the assignment,
//the quests are just in the current folder at all times.
/*$levelfolder=1;
if ($_SESSION['level']>=5) {
$levelfolder=5;
}
else if ($_SESSION['level']>=10) {
$levelfolder=10;
}
else if ($_SESSION['level']>=15) {
$levelfolder=15;
}*/
include(/*'questincludes/' . $levelfolder . '/*/'inc_quest' . $filecountarray[$random] . '.php');
}
//If not, tell the character they've done all the quests for now.
else {
echo "Sorry, you've done all the quests for now!";
unset($_SESSION['randomencounter']);
//Continue button
echo "<form name='formvictory' action='index.php' method='post'>
<input type='submit' name='continue' value='Continue'/></form>";
}
}
//If a character is on a quest
else {
include(/*'questincludes/' . */$_SESSION['questfile']);
}
}
?>
</div>
<div id="footer">
<div id="footer_inner">
<?php include('inc_footer.html'); ?>
</div>
</div>
</div>
</body>
</html>