<?php
session_start();
if(!session_is_registered('id') || $_SESSION['id'] == "") {
header("Location:../login.html");
die;
}
?>
<?php
session_start();
include "../includes/config.php";
include "../includes/config_db.php";
$user = $_SESSION['name'];
$id = $_GET['id'];
?>
<?php
$sql = "SELECT * FROM users WHERE name = '$user' LIMIT 1";
$ergebnis = mysql_query($sql);
while($row = mysql_fetch_object($ergebnis)){
$stufe = "$row->stufe";
}
?>
<?php
if ($id == ""){
?>
Gegner suchen kostet:
<br><br>
5
<img style="width: 16px; height: 16px;" alt="" src="img/coins.png">
<br>
<br>
<a href="?id=search"><button name="absenden">Gegner Suchen</button></a>
<?php
}
if ($id == "search"){
?>
<?php
//Geld Abzug
$sql = "SELECT * FROM users WHERE name = '$user' LIMIT 1";
$ergebnis = mysql_query($sql);
while($row = mysql_fetch_object($ergebnis)){
$geld = "$row->geld";
}
if ($geld < "5"){
echo "Sie haben nicht genĂ¼gend Geld!<br>";
}else{
$geld = $geld - 5;
$sql = "UPDATE users SET geld = '$geld' WHERE name = '$user'";
mysql_query($sql);
?>
<?php
$sql = "SELECT * FROM users WHERE stufe = '$stufe' AND name != '$user' ORDER by RAND() LIMIT 1";
$ergebnis = mysql_query($sql);
while($row = mysql_fetch_object($ergebnis)){
$gegner = "$row->name";
$def2 = "$row->def";
$atk2 = "$row->atk";
$leben2 = "$row->leben";
$erfahrung2 = "$row->erfahrung";
}
$sql = "SELECT * FROM users WHERE name = '$user' LIMIT 1";
$ergebnis = mysql_query($sql);
while($row = mysql_fetch_object($ergebnis)){
$def = "$row->def";
$atk = "$row->atk";
$leben = "$row->leben";
$erfahrung = "$row->erfahrung";
}
?>
<?php
session_start();
$_SESSION['gegner'] = $gegner;
$_SESSION['atk2'] = $atk2;
$_SESSION['def2'] = $def2;
$_SESSION['leben2'] = $leben2;
?>
<!--Tabelle Uebersicht-->
<table style="text-align: left; width: 80%;" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td style="width: 20%; text-align: center; background-color: rgb(226, 253, 225);">Username:</td>
<td style="width: 15%; text-align: center; background-color: rgb(210, 235, 209);">Leben:</td>
<td style="width: 15%; text-align: center; background-color: rgb(226, 253, 225);">Angriff:</td>
<td style="width: 15%; text-align: center; background-color: rgb(210, 235, 209);">Verteidigung:</td>
<td style="width: 15%; text-align: center; background-color: rgb(226, 253, 225);">Erfahrung:</td>
</tr>
</tbody>
</table>
<!--Eigener User-->
<table style="text-align: left; width: 80%;" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td style="width: 20%; background-color: rgb(226, 253, 245); text-align: left;"> <?php echo "$user"; ?></td>
<td style="width: 15%; background-color: rgb(211, 237, 229); text-align: left;"> <?php echo "$leben"; ?></td>
<td style="width: 15%; background-color: rgb(226, 253, 245); text-align: left;"> <?php echo "$atk"; ?></td>
<td style="width: 15%; background-color: rgb(211, 237, 229); text-align: left;"> <?php echo "$def"; ?></td>
<td style="width: 15%; background-color: rgb(226, 253, 245); text-align: left;"> <?php echo "$erfahrung"; ?></td>
</tr>
<!-- Gegner-->
<tr>
<td style="width: 20%; background-color: rgb(226, 253, 245); text-align: left;"> <?php echo "$gegner"; ?></td>
<td style="width: 15%; background-color: rgb(211, 237, 229); text-align: left;"> <?php echo "$leben2"; ?></td>
<td style="width: 15%; background-color: rgb(226, 253, 245); text-align: left;"> <?php echo "$atk2"; ?></td>
<td style="width: 15%; background-color: rgb(211, 237, 229); text-align: left;"> <?php echo "$def2"; ?></td>
<td style="width: 15%; background-color: rgb(226, 253, 245); text-align: left;"> <?php echo "$erfahrung2"; ?></td>
</tr>
</tbody>
</table>
<!--Annehmen Button-->
<br>
<a href="?id=annehmen"><button name="absenden">Annehmen</button></a>
<?php
}
}
if ($id == "annehmen"){
$gegner = $_SESSION['gegner'];
$atk = $_SESSION['atk2'];
$def2 = $_SESSION['def2'];
$leben2 = $_SESSION['leben2'];
?>
<?php
if ($gegner == ""){
echo "Fehler!<br>";
}else{
?>
<?php
function attack($atk,$def2,$leben2) {
if ($atk>$def2) {
return $leben2-($atk-$def2);
}
return $leben2;
}
function attack2($atk2,$def,$leben) {
if ($atk2>$def) {
return $leben-($atk2-$def);
}
return $leben;
}
while ($leben >= 0 AND $leben2 >= 0){
$bonus_u = rand(1,2);
// Werte User 1
if ($bonus_u == "1"){
$atk = $atk + 3;
}
// Leben nach dem Angriff
$leben_d = attack($atk,$def2,$leben2);
if ($leben_d < "0"){
$_SESSION['g_v'] = "1";
$block = "1";
}
$leben2 = $leben_d;
if ($block == ""){
// Werte User 2
if ($bonus_u == "2"){
$atk2 = $atk2 + 3;
}
// Leben nach dem Angriff
$leben_d2 = attack2($atk2,$def,$leben);
if ($leben_d2 < "0"){
$_SESSION['g_v'] = "2";
}
$leben = $leben_d2;
}
}
?>
<a href="Neu6.php">»Auswertung«</a>
<?php
}
}
?>