-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
80 lines (54 loc) · 2.03 KB
/
index.php
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
<?php
$manyDiceToRoll = 0;
$typeOfDice = "";
$outputDiceRolled = [];
if (isset($_POST["roll"]) && isset($_POST["roll"]) ) {
$roll = (int)$_POST["roll"];
$dice = (int)$_POST["dice"];
$manyDiceToRoll = $roll;
$typeOfDice = "d".$dice;
for($i = 1 ; $i <= $roll; $i++){
array_push($outputDiceRolled, rand(1, $dice));
}
}
?>
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="center">
<h1>ROLL DICE</h1>
<hr>
<!-- INPUT DICE -->
<form name="form" action="" method="POST">
ROLL : <input type="number" name="roll" size="4">
DICE :
<select name="dice">
<option value="4">d4</option>
<option value="6">d6</option>
<option value="10">d10</option>
<option value="12">d12</option>
<option value="20">d20</option>
</select>
<br><br>
<input type="submit" name = "submit" value="roll">
</form>
<!-- OUTPUT DICE -->
<?php
if (isset($_POST['submit'])) {
if ($manyDiceToRoll != 0) {
echo "Many dice to roll : ". $manyDiceToRoll ."<br>";
echo "Type of Dice : " . $typeOfDice ."<br><br>";
$number = 1;
foreach($outputDiceRolled as $value){
echo "output of the dice thrown at ". $number++ ." is " . $value . "<br>";
echo "<br><br>";
}
} else {
echo '<b class="error"> roll the dice at least 1 <b>';
}
}?>
</div>
</body>
</html>