Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.02 KB | None | 0 0
  1. <html>
  2.     <head>
  3.         <meta charset="utf-8" />
  4.         <title>Coop Insanity</title>
  5.         <link href="https://fonts.googleapis.com/css?family=Orbitron:400,500,700,900" rel="stylesheet">
  6.         <style type="text/css">
  7.             /* domain reset to /weingut-frick.relaunch/public/  #######*/
  8.             html {
  9.                 background:url('bg.jpg') top center no-repeat;
  10.                 background-size:cover;
  11.                 font-family: 'Orbitron', sans-serif;
  12.             }
  13.            
  14.             #main {
  15.                 position:absolute;
  16.                 width:800px;
  17.                 left:50%;
  18.                 margin-left:-400px;
  19.                 margin-top:100px;
  20.                 border-bottom:1px solid #fff;
  21.                 border-radius:20px 20px 0 0 ;
  22.                 background:#f1f1f1;
  23.                 box-shadow: 10px 10px 5px 0px rgba(0,0,0,0.45);
  24.                 opacity:.85;
  25.                 font-family: 'Orbitron', sans-serif;
  26.             }
  27.            
  28.             p {
  29.             box-sizing: border-box;
  30.             color: rgb(25, 25, 25);
  31.             display: block;
  32.             font-family:Arial;
  33.             font-size: 15px;
  34.             line-height: 20.4px;
  35.             text-align:center;
  36.             width:100%;
  37.             padding-top:10px;
  38.                 font-family: 'Orbitron', sans-serif;
  39.             }
  40.            
  41.         h1 {
  42.             box-sizing: border-box;
  43.             color: rgb(25, 25, 25);
  44.             display: block;
  45.             font-size: 26px;
  46.             line-height: 36.4px;
  47.                 font-family: 'Orbitron', sans-serif;
  48.             text-align:center;
  49.             width:100%;
  50.             }
  51.         h2 {
  52.             box-sizing: border-box;
  53.             color: rgb(25, 25, 25);
  54.             display: block;
  55.             font-size: 22px;
  56.             line-height: 32.4px;
  57.                 font-family: 'Orbitron', sans-serif;
  58.             text-align:center;
  59.             width:100%;
  60.             }
  61.  
  62.             p a {
  63.             color: #10B20A;
  64.                 font-family: 'Orbitron', sans-serif;
  65.             font-size: 14px;
  66.             line-height: 20.4px;
  67.             text-align:center;
  68.             text-decoration:none;
  69.             font-weight:700;
  70.             }
  71.             p a:hover {
  72.                 color:#333;
  73.             }
  74.             p a:after{
  75.                 content:',';
  76.             }
  77.             p a:last-child:after {
  78.                 content:'';
  79.             }
  80.         </style>
  81.     </head>
  82.     <body>
  83.         <div id="main">
  84.             <h1>Coop Commander Insanity</h1>
  85. <?php
  86. $data   = json_decode(file_get_contents("commander.json"),true);
  87. $points = 3;
  88.  
  89. if($_GET["commander"] && $data[$_GET["commander"]]) {
  90.     $_GET["commander"] = urldecode($_GET["commander"]);
  91. ?>
  92. <h2>Take following units:</h2><p><br>
  93. <?php
  94.     $ret = getUnits($data[$_GET["commander"]],$points);
  95.     foreach($ret as $value) {
  96.         echo "<b>" . $value . "<b><br>";
  97.     }
  98. ?>
  99. <br><a href="index.php">back</a></p>
  100. <?php
  101. } else {
  102. ?>
  103. <h2>Choose your Commander:</h2><p>
  104. <?php
  105.     foreach($data as $key => $value) {
  106.         echo "<a href='index.php?commander=" . $key . "' >" . $key . "</a> ";
  107.     }
  108. ?>
  109. </p>
  110. <?php
  111. }
  112.  
  113. function getUnits($stack,$points) {
  114.     $choose = array();
  115.     while(true) {
  116.         $tmp = array();
  117.         foreach($stack as $key => $value) {
  118.             if($value <= $points) {
  119.                 $tmp[$key] = $value;
  120.             }
  121.         }
  122.         $add = roll($tmp,$choose);
  123.         if($add === false) {
  124.             return $choose;
  125.         }
  126.         $choose[] = $add;
  127.         $points = $points - $stack[$add];
  128.     }
  129.    
  130. }
  131.  
  132. function roll($stack,$choose) {
  133.     $tmp = array();
  134.     // firt filter the not allready chosen
  135.     foreach($stack as $key => $value) {
  136.         if(!in_array($key,$choose)) {
  137.             $tmp[] = $key;
  138.         }
  139.     }
  140.     if(count($tmp) < 1) {
  141.         return false;
  142.     }
  143.     // now we mix the array
  144.     return $tmp[rand(0,(count($tmp) - 1))];
  145. }
  146. ?>
  147.  
  148.  
  149.  
  150.         </div>
  151.     </body>
  152. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement