-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproblem.php
178 lines (165 loc) · 4.88 KB
/
problem.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
<?php
include('dbconnect.php');
if($_SESSION["in"])
{
$uid=$_SESSION["in"];
}
$pname = mysql_query("select * from users where id = '$uid'");
$prow = mysql_fetch_assoc($pname);
if ($_GET['score']) {
$points = ($_GET['score']);
if($_SESSION["in"]) {
mysql_query("insert into userscore(user_id,points) values('$uid','$points')");
}
}
?>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
<!--START OF TIMER SCRIPT-->
//how much time they get
var time=45;
var timesup=0;
var started=0;
function CountDown() {
if(time>0)
{document.math.timer.value=time;
time=time-1;
var gameTimer=setTimeout("CountDown()", 1000)}
else if (time==0)
{document.math.timer.value="0";
timesup=1;
var next = confirm('Time\'s Up!');
if (next==true) {
var score = document.math.points.value;
window.location.href="problem.php?score=" + score;
}
document.math.firstnum.value="";
document.math.operator.value="";
document.math.secondnum.value="";
document.math.answer.value="";
}
}
<!--END OF TIMER SCRIPT-->
function startgame()
{if (started!=0)
{alert('You\'ve Already Started!');}
else
{
started=1;
CountDown();
getProb();
}
}
<!--START OF RANDOM NUMBER SCRIPT-->
function randnum(min,max)
{
var num=Math.round(Math.random()*(max-min))+min;
return num;
}
<!--END OF RANDOM NUMBER SCRIPT-->
var choose, rightanswer
function getProb()
{
choose=randnum(1,4);
if (choose=="1")
{document.math.operator.value="+";
var choose1=randnum(0,50);
var choose2=randnum(0,50);
document.math.firstnum.value=choose1;
document.math.secondnum.value=choose2;
rightanswer=choose1 + choose2;
}
if (choose=="2")
{document.math.operator.value="-";
var choose2=randnum(0,50);
var choose1=randnum(choose2,50);
document.math.firstnum.value=choose1;
document.math.secondnum.value=choose2;
rightanswer=choose1 - choose2;
}
if (choose=="3")
{document.math.operator.value="x";
var choose1=randnum(0,10);
var choose2=randnum(0,10);
document.math.firstnum.value=choose1;
document.math.secondnum.value=choose2;
rightanswer=choose1 * choose2;
}
if (choose=="4")
{document.math.operator.value="/";
var choose2=randnum(1,10);
var choose1=choose2 * randnum(0,10);
document.math.firstnum.value=choose1;
document.math.secondnum.value=choose2;
rightanswer=choose1 / choose2;
}
}
function answerit()
{
if (started==0)
{alert('You Must Click The Button Labeled \'Start\'!');}
else
{
if (timesup!=0)
{alert('Time Ran Out!');}
else
{
var theiranswer=eval(document.math.answer.value);
var theirpoints=eval(document.math.points.value);
if (theiranswer==null)
{alert('Put Your Answer In The Box To The Left Of The Button Labeled \'Submit Answer\'!');
document.math.answer.select();}
else
{
if (theiranswer==rightanswer)
{
theirpoints++;
document.math.points.value=theirpoints;
}
else
{alert(theiranswer + " is Wrong!\n\n"+rightanswer + " is the correct answer!")}
document.math.answer.select();
getProb();
}
}
}
}
function showHelp()
{
var msg = "Type your answer in the textbox followed by the *Tab* & *Enter* button to save more time!";
alert(msg);
}
function goBack()
{
window.location.href="problem.php";
}
// End -->
</script>
</HEAD>
<BODY>
<table align="center">
<tr>
<td colspan="3" align="center"><input type="button" value="New Game" onClick="location.reload();"></td></tr><tr>
<td colspan="3" align="center"><input type="button" value="Start" size="5" onClick="startgame()"></td>
</tr>
<tr>
<form name="math">
<td colspan="3" align="center"><font face="Arial, Helvetica, Sans Serif" size="3" color="#0000FF"><b>Time Remaining:</b> </font><input type="text" name="timer" size="5"></td>
</tr>
<tr>
<td align="right"><font face="Arial, Helvetica, Sans Serif" size="3" color="#0000FF"><b>Solve:</b> </font><input type="text" name="firstnum" size="5"></td>
<td align="center"><input type="text" name="operator" size="2"></td>
<td align="left"><input type="text" name="secondnum" size="5"></td>
</tr>
<tr>
<td colspan="3" align="center"><hr><font face="Arial, Helvetica, Sans Serif" size="3" color="#0000FF"><b>Put Answer Here:</b></font> <input type="text" name="answer" size="5"> <input type="button" value="Submit Answer" onClick="answerit();"><hr></td>
</tr>
<tr>
<td colspan="3" align="center"><font face="Arial, Helvetica, Sans Serif" size="3" color="#0000FF"><b>Points:</font></b> <input type="text" name="points" size="5" value="0"></td>
</tr>
<tr>
<td colspan="3" align="center"><input id=HelpID onclick='showHelp()' type=button value='Help' name=HelpBtn size=16></td>
</form>
</tr>
</table>