-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.php
137 lines (98 loc) · 3.21 KB
/
index.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
<?php
require_once "functions.php";
session_start();
?>
<!DOCTYPE html>
<html>
<?php require_once 'elements/head.php';?>
<body class="container background">
<div class="row">
<div class="col-md-2 controllers">
<h2 >Controllers</h2>
<form method="POST" class="block-options">
<h3>Move</h3>
<div class="form-group">
<input class="form-control" type="text" placeholder="Origem Linha" name="origemLinha"/>
<input class="form-control" type="text" placeholder= "Origem Coluna" name="origemColuna"/>
<input class="form-control" type="text" placeholder = "Destino Linha" name="destinoLinha"/>
<input class="form-control" type="text" placeholder="Destino Coluna" name="destinoColuna"/>
</div>
<input class="btn btn-light"type="submit" value="Move!">
</form>
</div>
<div class="col-md-8">
<?php
$x1 = ['-','X','-','0','-','0','-','0'];
$x2 = ['0','-','0','-','0','-','0','-'];
$x3 = ['-','0','-','0','-','0','-','0'];
$x4 = ['-','-','-','-','-','-','-','-'];
$x5 = ['-','-','-','-','-','-','-','-'];
$x6 = ['X','-','X','-','X','-','X','-'];
$x7 = ['-','X','-','X','-','X','-','X'];
$x8 = ['X','-','X','-','X','-','X','-'];
$y = [$x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8];
if(isset($_POST['action']) && $_POST['action'] == "ResetGame"){
session_destroy();
session_start();
$_SESSION["turn"] = 'X';
$_SESSION['tabuleiro'] = $y;
}
if(isset($_POST['origemLinha']) && isset($_POST['origemColuna']) && isset($_POST['destinoLinha']) && isset($_POST['destinoColuna'])){
$origemLinha = $_POST['origemLinha'];
$origemColuna = $_POST['origemColuna'];
$destinoLinha = $_POST['destinoLinha'];
$destinoColuna = $_POST['destinoColuna'];
$y = $_SESSION["tabuleiro"];
$isValid = validaMovimento($y, $origemLinha, $origemColuna, $destinoLinha, $destinoColuna);
if($isValid){
if($_SESSION['turn'] == 'X')
{
$_SESSION['turn'] = "0";
}
else
{
$_SESSION['turn'] = 'X';
}
$_SESSION["tabuleiro"] = fazerMovimento($y, $origemLinha, $origemColuna, $destinoLinha, $destinoColuna);
$y = $_SESSION["tabuleiro"];
$_SESSION["tabuleiro"] = movimentarComBot($y);
$_SESSION["turn"] = 'X';
if ($_SESSION['turn'] == 'X') {
echo "<div class='alert alert-info'> Turn: White </div>";
}
else{
echo "<div class='alert alert-info'> Turn: Black</div>";
}
}
else{
echo '<div class="alert alert-danger">Esse movimento não é válido</div>';
}
for($j = 0; $j < 8; $j++){
if ($y[0][$j] == 'X'){
$_SESSION['tabuleiro'][0][$j] = 'C';
}
}
for($j = 0; $j < 8; $j++){
if ($y[7][$j] == '0'){
$_SESSION['tabuleiro'][0][$j] = 'D';
}
}
}
if(!isset($_SESSION['tabuleiro'])){
$_SESSION['tabuleiro'] = $y;
MontarTabuleiro($_SESSION['tabuleiro'] );
}else{
MontarTabuleiro($_SESSION['tabuleiro']);
}
?>
</div>
<div class="col-md-2 options">
<h2>Game options</h2>
<form method="POST" class="block-options">
<input type="hidden" name='action' value="ResetGame"/>
<input class="btn btn-light" type="submit" value="Reset Game!">
</form>
</div>
</div>
</body>
</html>