This repository was archived by the owner on Jun 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgra.php
121 lines (101 loc) · 3.14 KB
/
gra.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
<?php
include 'includes/header.php';
session_start();
if(!isset($_SESSION['login'])) {
redirect('index.php');
}
$zalogowany = $_SESSION['login'];
if (isset($_POST['nowa_gra'])) {
if(mozeStworzycKolejne($zalogowany)) {
$id_gra = stworzNowaGre($zalogowany);
redirect("gra.php?id=$id_gra");
}
else {
redirect('dashboard.php?error=true');
}
}
if (isset($_POST['dolacz'])) {
$id_gra = $_POST['gra_id'];
dolaczDoGry($zalogowany, $id_gra);
redirect("gra.php?id=$id_gra");
}
if (!isset($_GET['id']) || !graczJestWGrze($zalogowany, $_GET['id'])) {
redirect('dashboard.php');
}
$id_gra = $_GET['id'];
$gracze = pobierzUzytkownikowGry($id_gra);
?>
<script src="/js/jquery.js"></script>
<script>
function pobierzStan() {
$.get("stan.php?id=" + <?php echo $id_gra; ?>, function(res) {
let json = JSON.parse(res);
let stan = JSON.parse(json[0]);
let graAktywna = json[1];
let gracz = json[2];
for (let i in stan) {
for(let j in stan[i]) {
$(`#wartosc_${i}_${j}`).html(stan[i][j]);
}
}
$('input').removeClass('btn-success');
$(`#${gracz}`).addClass('btn-success');
if(!graAktywna) {
$('#stan_gry').html('Gra została zakończona!');
}
});
}
setInterval(pobierzStan, 2000);
</script>
<script>
$(document).ready(function() {
$("table td").click(function() {
let row_num = parseInt($(this).parent().index());
let column_num = parseInt($(this).index());
$.ajax({
type: "POST",
url: "stan.php",
data: {
id: <?php echo $id_gra; ?>,
row_num: row_num,
column_num: column_num
}
});
});
});
</script>
<p>Twój login: <b><?php echo $zalogowany?></b>.</p>
<a href="dashboard.php">Wróć do widoku gier. </a>
<div class="mt-5">
<div class="text-center">
<input id="host" class="text-center btn" readonly="readonly" onclick="this.blur();" value="Gracz: <?php echo $gracze['host'];?> - X">
<input id="gosc" class="text-center btn" readonly="readonly" onclick="this.blur();" value="Gracz: <?php echo $gracze['gosc'] ?: '....'?> - O">
</div>
<div class="d-flex justify-content-around mt-3">
<div class="col-md-4">
<form id="plansza" method="post" action="stan.php">
<table class="table table-bordered">
<tbody>
<tr>
<td id="wartosc_0_0" class="text-center"></td>
<td id="wartosc_0_1" class="text-center"></td>
<td id="wartosc_0_2" class="text-center"></td>
</tr>
<tr>
<td id="wartosc_1_0" class="text-center"></td>
<td id="wartosc_1_1" class="text-center"></td>
<td id="wartosc_1_2" class="text-center"></td>
</tr>
<tr>
<td id="wartosc_2_0" class="text-center"></td>
<td id="wartosc_2_1" class="text-center"></td>
<td id="wartosc_2_2" class="text-center"></td>
</tr>
</tbody>
</table>
<input type="submit" hidden="hidden" name="zagraj">
</form>
</div>
</div>
</div>
<p id="stan_gry" class="text-center"></p>