php ob_start start microtime true db new PDO mysql host 127 dbname swo

  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
<?php
ob_start();
$start = microtime(true);
$db = new PDO('mysql:host=127.0.0.1;dbname=sword;charset=UTF8', 'root', '');
$size = [5, 5];
$_user = $db -> prepare('SELECT * FROM `user` WHERE `id` = ?');
$_user -> execute([1]);
$user = $_user -> fetch();
$_areas = $db -> prepare('SELECT * FROM `areas`');
$_areas -> execute();
$areas = $_areas -> fetchAll();
foreach ($areas as $area) {
$dash[$area['x']][$area['y']] = $area['area'];
}
function check($x, $y, $set = array()) {
global $dash, $size;
if (!isset($dash[$x][$y])) return $set;
if ($dash[$x][$y] == '5') return false;
$set[$x . '_' . $y] = $dash[$x][$y];
if ($dash[$x][$y] == '6') return $set;
$shifts = [
[$x + 1, $y], [$x - 1, $y],
[$x, $y + 1], [$x, $y - 1]
];
for ($i = 0; $i < 4; ++$i) {
$x2 = $shifts[$i][0];
$y2 = $shifts[$i][1];
if ($x2 >= 0 && $x2 <= $size[0] && $y2 >= 0 && $y2 <= $size[1] && isset($dash[$x2][$y2]) && $dash[$x2][$y2] == $dash[$x][$y] && !isset($set[$x2.'_'.$y2])) $set = check($x2, $y2, $set);
}
return $set;
}
$_area = $db -> prepare('SELECT * FROM `area`');
$_area -> execute();
$area = $_area -> fetchAll();
foreach($area as $area2){
if($chanse > $area2['chanse']){
$rand = $area2['id'];
break;
}
}
$chanse = rand(1,100);
if(!$user['area']){
$__user = $db->prepare('UPDATE `user` SET `area` = ? WHERE `id` = ?');
$__user->execute([$rand, $user['id']]);
header('Location:/area.php');
exit;
}
if(isset($_GET['put'])){
$__user = $db->prepare('UPDATE `user` SET `area` = ?, `put` = ? WHERE `id` = ?');
$__user->execute([($user['put'] ? $user['put'] : $rand), $user['area'], $user['id']]);
header('Location:/area.php');
exit;
}
echo '
<style>
a{
border:none;
text-decoration: none;
margin:0;
padding:0;
width:16px;
height:16px;
}
</style>
Ваша сфера: <img src="images/areas/'.$user['area'].'.png" alt="" />
Запасной слот:
<a href="area.php?put">
<img src="images/areas/'.($user['put'] ? $user['put'] : 0).'.png" alt="" />
</a>
<br />
';
if(isset($_GET['x']) and isset($_GET['y'])){
$_areas = $db -> prepare('SELECT * FROM `area` WHERE `id` = ?');
$_areas -> execute([$user['area']]);
$area = $_areas -> fetch();
if($area){
$_check = $db->prepare('SELECT * FROM `areas` WHERE `x` = ? AND `y` = ? LIMIT 1');
$_check -> execute([(int)$_GET['x'], (int)$_GET['y']]);
$check = $_check->fetch();
if($check and $area['id'] != 6){
header('Location:/area.php');
exit;
}
else{
if($area['id'] !== '6'){
$__areas = $db->prepare('INSERT INTO `areas` SET `user` = ?, `area` = ?, `x` = ?, `y` = ?');
$__areas->execute([1,$user['area'],(int)$_GET['x'],(int)$_GET['y']]);
}
$__user = $db->prepare('UPDATE `user` SET `area` = ? WHERE `id` = ?');
$__user->execute([0, $user['id']]);
$dash[(int) $_GET['x']][(int) $_GET['y']] = $user['area'];
$checker = check((int)$_GET['x'], (int)$_GET['y']);
if(count($checker) > 2 or $area['id'] == '6'){
print_r($checker);
foreach($checker as $key=>$value){
$x = $key[0];
$y = $key[2];
$__delete = $db->prepare('DELETE FROM `areas` WHERE `x` = ? AND `y` = ?');
$__delete->execute([$x, $y]);
}
switch($area['type']){
case 'attack':
break;
case 'defense':
break;
case 'heal':
break;
}
}
header('Location:/area.php');
exit;
}
}
}
for ($y = 0; $y < $size[0]; ++$y) {
for ($x = 0; $x < $size[0]; ++$x) {
echo $dash[$x][$y] ? ($user['area'] == '6' ? '
<a href="?x='.$x.'&y='.$y.'">
<img src="images/areas/'.$dash[$x][$y].'.png" />
</a>
':'
<img src="images/areas/'.$dash[$x][$y].'.png" />
'):'
<a href="?x='.$x.'&y='.$y.'">
<img src="images/areas/0.png" />
</a>
';
}
echo '
<br />
';
}
echo '<br />Скрипт выполнялся '.round((microtime(true) - $start), 6).' сек.';
?>