diff options
| author | Aiden Woodruff <aiden.woodruff@gmail.com> | 2018-04-12 16:54:18 -0500 |
|---|---|---|
| committer | Aiden Woodruff <aiden.woodruff@gmail.com> | 2018-04-12 18:31:36 -0500 |
| commit | 3f0da1f37e0021d08e1b39b710eae64cb283375c (patch) | |
| tree | 23544135b69577774cfbcbd598e7936ddbe70f72 | |
| parent | 0ff426b024d94cfc1852d0090e7a14511e54a524 (diff) | |
| download | sweeper-3f0da1f37e0021d08e1b39b710eae64cb283375c.tar.gz sweeper-3f0da1f37e0021d08e1b39b710eae64cb283375c.tar.bz2 sweeper-3f0da1f37e0021d08e1b39b710eae64cb283375c.zip | |
Fixed the count
Fixed PHP count of mines in index.php
Started converting index.php to all Javascript
Created other.html to test Javascript and HTTP GET
Signed-off-by: Aiden Woodruff <aiden.woodruff@gmail.com>
| -rw-r--r-- | index.php | 25 | ||||
| -rw-r--r-- | other.html | 31 |
2 files changed, 43 insertions, 13 deletions
| @@ -26,23 +26,21 @@ for ($i = 0; $i < count($mines); $i++) { | |||
| 26 | $boardmap[(int)substr($mines[$i], 3, 2)][(int)substr($mines[$i],0,2)] = "M"; | 26 | $boardmap[(int)substr($mines[$i], 3, 2)][(int)substr($mines[$i],0,2)] = "M"; |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | var_dump($boardmap); | ||
| 30 | // Assign numbers | 29 | // Assign numbers |
| 31 | for ($y = 0; $y < $height; $y++) { | 30 | for ($y = 0; $y < $height; $y++) { |
| 32 | for ($x = 0; $x < $width; $x++) { | 31 | for ($x = 0; $x < $width; $x++) { |
| 33 | $count = 0; | 32 | $count = 0; |
| 34 | if ($x > 0 and $boardmap[$y][$x - 1] == "M") $count++; | 33 | if ($x > 0 and $boardmap[$y][$x - 1] === "M") $count++; |
| 35 | if ($y > 0 and $boardmap[$y - 1][$x] == "M") $count++; | 34 | if ($y > 0 and $boardmap[$y - 1][$x] === "M") $count++; |
| 36 | if ($x < $width - 1 and $boardmap[$y][$x + 1] == "M") $count++; | 35 | if ($x < $width - 1 and $boardmap[$y][$x + 1] === "M") $count++; |
| 37 | if ($y < $height - 1 and $boardmap[$y+1][$x] == "M") $count++; | 36 | if ($y < $height - 1 and $boardmap[$y+1][$x] === "M") $count++; |
| 38 | if ($x > 0 and $y > 0 and $boardmap[$y-1][$x - 1] == "M") $count++; | 37 | if ($x > 0 and $y > 0 and $boardmap[$y-1][$x - 1] === "M") $count++; |
| 39 | if ($x > 0 and $y < $height - 1 and $boardmap[$y+1][$x - 1] == "M") $count++; | 38 | if ($x > 0 and $y < $height - 1 and $boardmap[$y+1][$x - 1] === "M") $count++; |
| 40 | if ($x < $width - 1 and $y > 0 and $boardmap[$y-1][$x + 1] == "M") $count++; | 39 | if ($x < $width - 1 and $y > 0 and $boardmap[$y-1][$x + 1] === "M") $count++; |
| 41 | if ($x > 0 and $y > 0 and $boardmap[$y - 1][$x - 1] == "M") $count++; | 40 | if ($x < $width and $y < $height and $boardmap[$y + 1][$x + 1] === "M") $count++; |
| 42 | if ($boardmap[$y][$x] != "M") $boardmap[$y][$x] = $count; | 41 | if ($boardmap[$y][$x] !== "M") $boardmap[$y][$x] = (int) $count; |
| 43 | } | 42 | } |
| 44 | } | 43 | } |
| 45 | var_dump($boardmap); | ||
| 46 | ?> | 44 | ?> |
| 47 | <!DOCTYPE html> | 45 | <!DOCTYPE html> |
| 48 | <html> | 46 | <html> |
| @@ -52,6 +50,7 @@ var_dump($boardmap); | |||
| 52 | <title>Minesweeper</title> | 50 | <title>Minesweeper</title> |
| 53 | <link type="text/css" rel="stylesheet" href="tiles.css"> | 51 | <link type="text/css" rel="stylesheet" href="tiles.css"> |
| 54 | <script type="application/javascript"> | 52 | <script type="application/javascript"> |
| 53 | var width = window.location; | ||
| 55 | var unrevealeds = document.getElementsByClassName('unrevealed'); | 54 | var unrevealeds = document.getElementsByClassName('unrevealed'); |
| 56 | 55 | ||
| 57 | function reveal (object) { | 56 | function reveal (object) { |
| @@ -83,9 +82,9 @@ function reveal (object) { | |||
| 83 | for ($y = 0; $y < $height; $y++) { | 82 | for ($y = 0; $y < $height; $y++) { |
| 84 | echo("<tr>\n"); | 83 | echo("<tr>\n"); |
| 85 | for ($x = 0; $x < $width; $x++) { | 84 | for ($x = 0; $x < $width; $x++) { |
| 86 | if ($boardmap[$y][$x] != "M") { | 85 | if ($boardmap[$y][$x] !== "M") { |
| 87 | echo("<td class='unrevealed n" . $boardmap[$y][$x] . "' onclick='reveal(this)'></td>\n"); | 86 | echo("<td class='unrevealed n" . $boardmap[$y][$x] . "' onclick='reveal(this)'></td>\n"); |
| 88 | } else if ($boardmap[$y][$x] == "M") { | 87 | } else if ($boardmap[$y][$x] === "M") { |
| 89 | echo("<td class='unrevealed mine' onclick='reveal(this)'></td>\n"); | 88 | echo("<td class='unrevealed mine' onclick='reveal(this)'></td>\n"); |
| 90 | } else { | 89 | } else { |
| 91 | echo("<td class='unrevealed null' onclick='reveal(this)'></td>\n"); | 90 | echo("<td class='unrevealed null' onclick='reveal(this)'></td>\n"); |
diff --git a/other.html b/other.html new file mode 100644 index 0000000..e2507db --- /dev/null +++ b/other.html | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | <!DOCTYPE html> | ||
| 2 | <html> | ||
| 3 | <body> | ||
| 4 | <div id="content"></div> | ||
| 5 | <script> | ||
| 6 | var link = window.location; | ||
| 7 | var width = undefined; | ||
| 8 | var height = undefined; | ||
| 9 | |||
| 10 | if (link.search("width") !== -1) { | ||
| 11 | width = parseInt( | ||
| 12 | link.substring( | ||
| 13 | link.search("width") + "width".length + 1, link.indexOf("&", link.search("width")) // indexOf | ||
| 14 | ) // search | ||
| 15 | ) // substring | ||
| 16 | ) // parseInt | ||
| 17 | ; | ||
| 18 | } | ||
| 19 | if (link.search("height") !== -1) { | ||
| 20 | width = parseInt(link.substring(link.search("height") + "height".length + 1, link.indexOf("&", link.search("height"))); | ||
| 21 | } | ||
| 22 | document.getElementById("content").innerHTML += "Width: " + width.toString() + "<br>"; | ||
| 23 | document.getElementById("content").innerHTML += "Height: " + height.toString() + "<br>"; | ||
| 24 | </script> | ||
| 25 | <form method="get" action="other.html"> | ||
| 26 | Width: <input type="text" name="width"><br> | ||
| 27 | Height: <input type="text" name="height"> <br> | ||
| 28 | <input type="submit" value="submit datas"> | ||
| 29 | </form> | ||
| 30 | </body> | ||
| 31 | </html> | ||
