-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrucigrama.php
253 lines (191 loc) · 7.57 KB
/
crucigrama.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
<?php
class Record
{
private $server;
private $user;
private $pass;
private $dbname;
public string $name;
public string $surname;
public string $level;
public string $time;
public string $recForm = "";
public string $top10 = "";
function __construct()
{
$this->server = "localhost";
$this->user = "DBUSER2023";
$this->pass = "DBPSWD2023";
$this->dbname = "crucigrama";
$this->recForm = "";
$this->top10 = "";
}
function getRecForm()
{
return $this->recForm;
}
function addData()
{
$db = new mysqli($this->server, $this->user, $this->pass);
// Comprobar la conexion
if ($db->connect_error) {
die("Error de conexión: " . $db->connect_error);
}
if (
isset($_POST["nombre"], $_POST["apellidos"], $_POST["nivel"], $_POST["tiempo"]) &&
!empty($_POST["nombre"]) && !empty($_POST["apellidos"])
) {
if ($db->select_db($this->dbname)) {
// Comando para insertar
$query = $db->prepare("INSERT INTO record (nombre, apellidos, nivel, tiempo) VALUES (?,?,?,?)");
$query->bind_param(
'sssi', $_POST["nombre"], $_POST["apellidos"], $_POST["nivel"], $_POST["tiempo"]);
$query->execute();
// Printear los resultados de la inserción
echo "<p>Filas añadidas: " . $query->affected_rows . "</p>";
$query->close();
}
}
$db->close();
$_SESSION['stored'] = true;
}
function getTopTen()
{
$db = new mysqli($this->server, $this->user, $this->pass);
// Comprobar la conexion
if ($db->connect_error) {
die("Error de conexión: " . $db->connect_error);
}
if ($db->select_db($this->dbname)) {
$query = $db->prepare("SELECT * FROM record WHERE nivel=? ORDER BY tiempo ASC LIMIT 10");
$query->bind_param('s', $_POST['nivel']);
$query->execute();
$res = $query->get_result();
$this->top10 = '<h2>Top 10 mejores resultados</h2>';
$this->top10 .= '<ol>';
while ($row = $res->fetch_assoc()) {
$t = sprintf('%02d:%02d:%02d', $row['tiempo'] / 3600, $row['tiempo'] / 60 % 60, $row['tiempo'] % 60);
$this->top10 .= '<li>' . $row['nombre'] . ' ' . $row['apellidos'] . ' ' . $this->time . '</li>';
}
$this->top10 .= '</ol>';
$query->close();
}
$db->close();
return $this->top10;
}
function showForm($name, $surname, $level, $time)
{
$this->recForm = '<form action="#" method="post">';
$this->recForm += '<p>';
$this->recForm += '<label for="nombre">Nombre:</label>';
$this->recForm += '<input type="text" id="nombre" name="nombre" value="' . $name . '">';
$this->recForm += '</p>';
$this->recForm += '<p>';
$this->recForm += '<label for="apellidos">Apellidos:</label>';
$this->recForm += '<input type="text" id="apellidos" name="apellidos" value="' . $surname . '">';
$this->recForm += '</p>';
$this->recForm += '<p>';
$this->recForm += '<label for="nivel">Nivel:</label>';
$this->recForm += '<input type="text" value="medio" readonly="readonly" id="nivel" name="nivel" value="' . $level . '">';
$this->recForm += '</p>';
$this->recForm += '<p>';
$this->recForm += '<label for="tiempo">Duración del juego:</label>';
$this->recForm += '<input type="text" value="1s" readonly="readonly" id="duracion" name="tiempo" value="' . $time . '">';
$this->recForm += '</p>';
$this->recForm += '<p>';
$this->recForm += '<input type="submit" value="Enviar" name="completo">';
$this->recForm += '</form>';
$this->recForm += '</p>';
}
}
$rec = new Record();
session_start();
if (count($_POST) <= 0) {
$rec->addData();
}
// else {
// if (isset($_POST['completo'])) {
// if (!empty($_POST['nombre']) || !empty($_POST['apellidos'])) {
// $rec->showForm($_POST['nombre'], $_POST['apellidos'], $_POST['nivel'], intval($_POST['tiempo']));
// }
// }
// }
if (isset($_SESSION['stored']) && $_SESSION['stored']) {
$rec->getTopTen();
$_SESSION['stored'] = false;
}
?>
<!DOCTYPE HTML>
<html lang="es">
<head>
<!-- Datos que describen el documento -->
<meta charset="UTF-8" />
<meta name="author" content="Silvia Suárez Prendes" />
<meta name="description" content="Juegos" />
<meta name="keywords" content="Juegos" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Juegos: Crucigrama</title>
<link rel="stylesheet" type="text/css" href="estilo/estilo.css" />
<link rel="stylesheet" type="text/css" href="estilo/layout.css" />
<link rel="stylesheet" type="text/css" href="estilo/botonera.css" />
<link rel="stylesheet" type="text/css" href="estilo/crucigrama.css" />
<link rel="icon" href="multimedia/fotos/icono.jpg" />
<script src="https://code.jquery.com/jquery-3.7.1.min.js"
integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
<script src="js/crucigrama.js"></script>
</head>
<body>
<header>
<h1>Escritorio virtual</h1>
<nav>
<a href="index.html" accesskey="I" tabindex="1">Inicio</a>
<a href="sobremi.html" accesskey="S" tabindex="2">Sobre mí</a>
<a href="noticias.html" accesskey="N" tabindex="3">Noticias</a>
<a href="agenda.html" accesskey="A" tabindex="4">Agenda</a>
<a href="meteorologia.html" accesskey="M" tabindex="5">Meteorología</a>
<a href="viajes.php" accesskey="V" tabindex="6">Viajes</a>
<a href="juegos.html" accesskey="J" tabindex="7">Juegos</a>
<a href="ficheroApi.html" accesskey="M" tabindex="8">Mapa</a>
</nav>
</header>
<section>
<h2>Juegos</h2>
<ul>
<li><a href="memoria.html">Memoria</a></li>
<li><a href="sudoku.html">Sudoku</a></li>
<li><a href="crucigrama.php">Crucigrama</a></li>
</ul>
</section>
<section>
<h2>Crucigrama</h2>
</section>
<main>
</main>
<?php
echo $rec->getTopTen();
echo $rec->getRecForm();
?>
<script>
crucigrama.paintMathWord();
document.addEventListener('keydown', function (event) {
crucigrama.handleKeydown(event);
});
</script>
<section data-type="botonera">
<h2>Botonera</h2>
<button onclick="crucigrama.introduceElement(1)">1</button>
<button onclick="crucigrama.introduceElement(2)">2</button>
<button onclick="crucigrama.introduceElement(3)">3</button>
<button onclick="crucigrama.introduceElement(4)">4</button>
<button onclick="crucigrama.introduceElement(5)">5</button>
<button onclick="crucigrama.introduceElement(6)">6</button>
<button onclick="crucigrama.introduceElement(7)">7</button>
<button onclick="crucigrama.introduceElement(8)">8</button>
<button onclick="crucigrama.introduceElement(9)">9</button>
<button onclick="crucigrama.introduceElement('*')">*</button>
<button onclick="crucigrama.introduceElement('+')">+</button>
<button onclick="crucigrama.introduceElement('-')">-</button>
<button onclick="crucigrama.introduceElement('/')">/</button>
</section>
</body>
</html>