-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart_run.php
141 lines (122 loc) · 4.97 KB
/
start_run.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
<?php
session_start();
unset($_SESSION['uploadedName']);
unset($_SESSION['img_ready']);
if(!isset($_SESSION['answer_quest'])){
$_SESSION['answer_quest'] = 1;
}
if(!isset($_SESSION['count'])){
$_SESSION['count'] = 0;
}
if(!isset($_SESSION['score'])){
$_SESSION['score'] = 0;
}
if(!isset($_SESSION['choosed_vb'])){
$_SESSION['choosed_vb'] = "";
}
?>
<html>
<head><title>單字背誦王-今日背誦</title></head>
</html>
<script>
function back_menu(){
window.location.href = 'eng_learning.php';
}
</script>
<body>
<?php
function handle_part_of($convert){
switch($convert){
case "verb":
return "動詞";
break;
case "noun":
return "名詞";
break;
case "adj":
return "形容詞";
break;
case "prep":
return "介係詞";
break;
case "adv":
return "副詞";
break;
case "aux":
return "助詞";
break;
}
}
function problem1($vb_data){
$choosed_vb = array_rand($vb_data);
$_SESSION['choosed_vb'] = $choosed_vb;
print "<form action='handle_anwser.php' method='post'>請輸入此單字:<input type='text' name='vb_anwser' >"."<br>"."詞性: ".handle_part_of($vb_data[$choosed_vb][1])."<br>"."中文: ".$vb_data[$choosed_vb][2]."<br><br><input type='submit' name='vb' value= '送出答案' >"."</form>";
}
function problem2($vb_data){
$choosed_vb = array_rand($vb_data);
$_SESSION['choosed_vb'] = $choosed_vb;
print "<br><img src='upload/".$vb_data[$choosed_vb][3]."'width = 500px alt=''> <br>";
print "<form action='handle_anwser.php' method='post'>請看圖輸入此單字:<input type='text' name='vb_anwser' >"."<br><br><input type='submit' name='vb' value= '送出答案' >"."</form>";
}
function problem3($vb_data){
$choosed_vb = array_rand($vb_data);
$_SESSION['choosed_vb'] = $choosed_vb;
print "<form action='handle_anwser.php' method='post'>單字: ".$vb_data[$choosed_vb][0]."<br>"."詞性: ".handle_part_of($vb_data[$choosed_vb][1])."<br>"."請輸入此中文: "."<input type='text' name='ch_anwser' >"."<br><br><input type='submit' name='vb' value= '送出答案' >"."</form>";
}
?>
<?php
if(!isset($_SESSION['Id'])){
print "請先登入!<br> 即將為您導向";
?>
<script>setTimeout("window.location.href='eng_learning.php'",2000); </script>
<?php
}else{
$file_name = $_SESSION['Id']."vbData.txt";
$fp = fopen($file_name,'rb');
$current_vb_count = 0;
$now_vb = array();
while((!feof($fp))&&($line = fgets($fp))){
$line = trim($line);
$info = explode('|',$line);
$current_vb_count++;
$now_vb[$info[0]]= array($info[0],$info[1],$info[2],$info[3]);
}
ksort($now_vb);
$_SESSION['now_vb'] = $now_vb;
print "目前已建立".$current_vb_count."個單字<br>";?>
<h4>您好,<?php print $_SESSION['username']; ?></h4>
<br>
歡迎來到 今日背誦 系統
<br>
<br>
<?php
if( $current_vb_count<5){
print "<p><b>請先將您的字庫充滿到5個以上<br>再使用本服務進行遊戲呦!</b></p>";
}else{
if($_SESSION['count'] == 5){
print "恭喜完成今日訓練!<br><br>";
print "總分: ".$_SESSION['score']."<br>";
print "<input type='button' onclick='back_menu()' value='回到主選單'>";
unset($_SESSION['count']);
unset($_SESSION['answer_quest']);
unset($_SESSION['score']);
unset($_SESSION['choosed_vb']);
}else{
$choose_quest = rand(1,3);
$_SESSION['count'] ++;
print "回合:".$_SESSION['count']."/5";
print "<br>累積分數:".$_SESSION['score']."<br><br><br>";
if($choose_quest == 1){
$_SESSION['answer_quest'] = 1;
problem1($now_vb);
}else if($choose_quest == 2){
$_SESSION['answer_quest'] = 2;
problem2($now_vb);
}else{
$_SESSION['answer_quest'] = 3;
problem3($now_vb);
}
}
}
} ?>
</body>