You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
3.1 KiB

  1. <?php
  2. session_start();
  3. include 'config.php';
  4. ?>
  5. <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
  6. <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
  7. <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
  8. <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
  9. <?php
  10. if (!isset($_SESSION["team"]))
  11. {
  12. if (isset($_POST["team_minus"]))
  13. {
  14. print "You joined team minus (blue)...";
  15. $_SESSION["team"]="minus";
  16. }
  17. elseif (isset($_POST["team_plus"]))
  18. {
  19. print "You joined team minus (green)...";
  20. $_SESSION["team"]="plus";
  21. }
  22. else
  23. {
  24. print "<h1>Choose your team!</h1>";
  25. ?>
  26. <form action="" method="post">
  27. <input type="submit" name="team_minus" value="Team Minus (Blue)">
  28. <input type="submit" name="team_plus" value="Team Plus (Green)">
  29. </form>
  30. <?php
  31. }
  32. }
  33. if (isset($_SESSION["team"]))
  34. {
  35. ?>
  36. <h1>Pull!!!</h1>
  37. <p>
  38. <?php
  39. if (isset($_GET['cloud_id']))
  40. {
  41. $sql = "SELECT * FROM clouds WHERE cloud_id = " . $_GET['cloud_id'];
  42. foreach ($pdo->query($sql) as $row)
  43. {
  44. if (abs(intval($row["value"])) >= intval($row["max_value"]))
  45. {
  46. unset($_SESSION["team"]);
  47. $_SESSION["finished"] = true;
  48. }
  49. }
  50. if (isset($_POST['pull']))
  51. {
  52. if ($_SESSION["team"] == "plus")
  53. {
  54. print "You pulled for team plus (green)...";
  55. $sql = "UPDATE clouds SET value=value+1 WHERE cloud_id = " . $_GET['cloud_id'];
  56. $result = $pdo->query($sql);
  57. }
  58. if ($_SESSION["team"] == "minus")
  59. {
  60. print "You pulled for team minus (blue)...";
  61. $sql = "UPDATE clouds SET value=value-1 WHERE cloud_id = " . $_GET['cloud_id'];
  62. $result = $pdo->query($sql);
  63. }
  64. }
  65. $sql = "SELECT * FROM clouds WHERE cloud_id = " . $_GET['cloud_id'];
  66. foreach ($pdo->query($sql) as $row)
  67. {
  68. print "<h2>Value: " . $row["value"] . " (Goal: " . $row["max_value"] . ")</h2>";
  69. }
  70. if (!isset($_SESSION["finished"]))
  71. {
  72. ?>
  73. <form action="" method="post">
  74. <input type="submit" name="pull" value="Pull">
  75. </form>
  76. <?php
  77. }
  78. else
  79. {
  80. print "<h2>game over</h2>";
  81. if (intval($row["value"] == intval($row["max_value"])))
  82. {
  83. print "Team plus (green) won!";
  84. }
  85. else
  86. {
  87. print "Team minus (blue) won!";
  88. }
  89. session_destroy();
  90. }
  91. }
  92. }
  93. ?>
  94. <br />
  95. <a href='index.php'>Leave Game</a>