Yahtzee in PHP
Kan iemand me verder helpen?
Code (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
session_start();
//Yahtzee functies
function RollDice($iDiceID){
$__iDice = rand(1,6);
$_SESSION['Yahtzee']['dice'][$iDiceID] = $__iDice;
return;
}
function PrintDices(){
echo "<tr><td>";
echo "<form action=?a=yatzee method=post><input type=Hidden name=submit value=yes>";
echo "<table cellspacing=3 cellpadding=2>";
echo "<tr><td colspan=5>Your Dice:</td></tr>";
echo "<tr>
<td><img src=\"images/Yathzee2/". $_SESSION['Yahtzee']['dice']['1'] .".png\"></td>
<td><img src=\"images/Yathzee2/". $_SESSION['Yahtzee']['dice']['2'] .".png\"></td>
<td><img src=\"images/Yathzee2/". $_SESSION['Yahtzee']['dice']['3'] .".png\"></td>
<td><img src=\"images/Yathzee/". $_SESSION['Yahtzee']['dice']['4'] .".png\"></td>
<td><img src=\"images/Yathzee/". $_SESSION['Yahtzee']['dice']['5'] .".png\"></td>
</tr>";
if(isset($_SESSION['Yahtzee']['status']) AND $_SESSION['Yahtzee']['status'] < 2){
echo "<tr>";
for($i=1;$i<6;$i++){
echo'<td><input type=checkbox name="dice['.$i.']" value="1"';
if(isset($_POST['dice'][$i])){
echo' FALSE';
}
echo'></td>';
}
echo"</tr>";
echo "<tr><td colspan=6><input style=color:#000000 type=submit name=Yahtzee value='Next roll..'></form></td></tr>";
}
echo "</table>";
echo "</td></tr>";
return;
}
function CheckDices(){
//Initialiseer de getallen.
for($i=1;$i<=6;$i++){
$aCheck[$i] = 0;
}
//Bekijk de dobbelstenen, en tel het aantal van elk getal.
for($i=1;$i<7;$i++){
$iValue = $_SESSION['Yahtzee']['dice'][$i];
for($j=1;$j<=6;$j++){
if($iValue == $j){
$aCheck[$j] = $aCheck[$j]+1;
}
}
}
.
$sFinal['text'] = 'Loser!';
$sFinal['mode'] = -4;
dezelfden zijn.
for($i=1;$i<=6;$i++){
if($aCheck[$i] == 3){ $sFinal['text']='Three of a kind!'; $sFinal['mode']=1; }
if($aCheck[$i] == 4){ $sFinal['text']='Four of a kind!'; $sFinal['mode']=1.3; }
if($aCheck[$i] == 5){ $sFinal['text']='Yahtzee!'; $sFinal['mode']=3; }
}
gemaakt.
if($aCheck['1'] == 1 AND $aCheck['2'] == 1 AND $aCheck['3'] == 1 AND $aCheck['4'] == 1 AND $aCheck['5'] == 1){
$sFinal['text']='Large straight!'; $sFinal['mode']=1.5;
}
if($aCheck['6'] == 1 AND $aCheck['2'] == 1 AND $aCheck['3'] == 1 AND $aCheck['4'] == 1 AND $aCheck['5'] == 1){
$sFinal['text']='Large straight!'; $sFinal['mode']=1.5;
}
if($sFinal['mode'] == 1 AND ($aCheck['1'] == 2 OR $aCheck['2'] == 2 OR $aCheck['3'] == 2 OR $aCheck['4'] == 2 OR $aCheck['5'] == 2 OR $aCheck['6'] == 2)){
$sFinal['text']='Full house!'; $sFinal['mode']=1.2;
}
//print_r($aCheck);
return $sFinal;
}
//EIND Yahtzee functies
if(isset($_POST['Yahtzee'])){
if(isset($_SESSION['Yahtzee']['status']) && $_SESSION['Yahtzee']['status'] == 1){
//Kijk welke dices wel en niet opnieuw gerold mogen worden.
for($i=1;$i<6;$i++){
if(!isset($_POST['dice'][$i])){
RollDice($i);
}
}
//Print de dobbelstenen
PrintDices();
//De tweede keer rollen
$_SESSION['Yahtzee']['status'] = 2;
}elseif(isset($_SESSION['Yahtzee']['status']) && $_SESSION['Yahtzee']['status'] == 2){
//De derde keer, uitbetalen en alles resetten.
//Kijk welke dices wel en niet opnieuw gerold mogen worden.
for($i=1;$i<6;$i++){
if(!isset($_POST['dice'][$i])){
RollDice($i);
}
}
//Print de dobbelstenen
PrintDices();
//Hier controleren wat er gewonnen is.
$aFinal = CheckDices();
echo $aFinal['text'];
if($aFinal['mode'] > 0){
echo '<br />You won: $'. ($_SESSION['Yahtzee']['money'] * $aFinal['mode']) ."<br />";
}else{
echo '<br />You lost: $'. ($_SESSION['Yahtzee']['money']) ."<br />";
}
// Reset de sessie Yahtzee voor een volgend potje
unset($_SESSION['Yahtzee']);
echo '<a href="Yahtzee.php?">New game.</a>';
}else{
//De eerste keer
if(isset($_POST['Yahtzeemoney']) AND is_numeric($_POST['Yahtzeemoney']) AND $_POST['Yahtzeemoney'] > 100 AND $_POST['Yahtzeemoney'] <= 3000000){
}else{
header('Location: Yahtzee.php');
exit;
}
$_SESSION['Yahtzee']['status'] = 1;
$_SESSION['Yahtzee']['money'] = $_POST['Yahtzeemoney'];
//Rol de dobbelstenen
RollDice(1);
RollDice(2);
RollDice(3);
RollDice(4);
RollDice(5);
//Print de dobbelstenen
PrintDices();
}
}else{
?>
session_start();
//Yahtzee functies
function RollDice($iDiceID){
$__iDice = rand(1,6);
$_SESSION['Yahtzee']['dice'][$iDiceID] = $__iDice;
return;
}
function PrintDices(){
echo "<tr><td>";
echo "<form action=?a=yatzee method=post><input type=Hidden name=submit value=yes>";
echo "<table cellspacing=3 cellpadding=2>";
echo "<tr><td colspan=5>Your Dice:</td></tr>";
echo "<tr>
<td><img src=\"images/Yathzee2/". $_SESSION['Yahtzee']['dice']['1'] .".png\"></td>
<td><img src=\"images/Yathzee2/". $_SESSION['Yahtzee']['dice']['2'] .".png\"></td>
<td><img src=\"images/Yathzee2/". $_SESSION['Yahtzee']['dice']['3'] .".png\"></td>
<td><img src=\"images/Yathzee/". $_SESSION['Yahtzee']['dice']['4'] .".png\"></td>
<td><img src=\"images/Yathzee/". $_SESSION['Yahtzee']['dice']['5'] .".png\"></td>
</tr>";
if(isset($_SESSION['Yahtzee']['status']) AND $_SESSION['Yahtzee']['status'] < 2){
echo "<tr>";
for($i=1;$i<6;$i++){
echo'<td><input type=checkbox name="dice['.$i.']" value="1"';
if(isset($_POST['dice'][$i])){
echo' FALSE';
}
echo'></td>';
}
echo"</tr>";
echo "<tr><td colspan=6><input style=color:#000000 type=submit name=Yahtzee value='Next roll..'></form></td></tr>";
}
echo "</table>";
echo "</td></tr>";
return;
}
function CheckDices(){
//Initialiseer de getallen.
for($i=1;$i<=6;$i++){
$aCheck[$i] = 0;
}
//Bekijk de dobbelstenen, en tel het aantal van elk getal.
for($i=1;$i<7;$i++){
$iValue = $_SESSION['Yahtzee']['dice'][$i];
for($j=1;$j<=6;$j++){
if($iValue == $j){
$aCheck[$j] = $aCheck[$j]+1;
}
}
}
.
$sFinal['text'] = 'Loser!';
$sFinal['mode'] = -4;
dezelfden zijn.
for($i=1;$i<=6;$i++){
if($aCheck[$i] == 3){ $sFinal['text']='Three of a kind!'; $sFinal['mode']=1; }
if($aCheck[$i] == 4){ $sFinal['text']='Four of a kind!'; $sFinal['mode']=1.3; }
if($aCheck[$i] == 5){ $sFinal['text']='Yahtzee!'; $sFinal['mode']=3; }
}
gemaakt.
if($aCheck['1'] == 1 AND $aCheck['2'] == 1 AND $aCheck['3'] == 1 AND $aCheck['4'] == 1 AND $aCheck['5'] == 1){
$sFinal['text']='Large straight!'; $sFinal['mode']=1.5;
}
if($aCheck['6'] == 1 AND $aCheck['2'] == 1 AND $aCheck['3'] == 1 AND $aCheck['4'] == 1 AND $aCheck['5'] == 1){
$sFinal['text']='Large straight!'; $sFinal['mode']=1.5;
}
if($sFinal['mode'] == 1 AND ($aCheck['1'] == 2 OR $aCheck['2'] == 2 OR $aCheck['3'] == 2 OR $aCheck['4'] == 2 OR $aCheck['5'] == 2 OR $aCheck['6'] == 2)){
$sFinal['text']='Full house!'; $sFinal['mode']=1.2;
}
//print_r($aCheck);
return $sFinal;
}
//EIND Yahtzee functies
if(isset($_POST['Yahtzee'])){
if(isset($_SESSION['Yahtzee']['status']) && $_SESSION['Yahtzee']['status'] == 1){
//Kijk welke dices wel en niet opnieuw gerold mogen worden.
for($i=1;$i<6;$i++){
if(!isset($_POST['dice'][$i])){
RollDice($i);
}
}
//Print de dobbelstenen
PrintDices();
//De tweede keer rollen
$_SESSION['Yahtzee']['status'] = 2;
}elseif(isset($_SESSION['Yahtzee']['status']) && $_SESSION['Yahtzee']['status'] == 2){
//De derde keer, uitbetalen en alles resetten.
//Kijk welke dices wel en niet opnieuw gerold mogen worden.
for($i=1;$i<6;$i++){
if(!isset($_POST['dice'][$i])){
RollDice($i);
}
}
//Print de dobbelstenen
PrintDices();
//Hier controleren wat er gewonnen is.
$aFinal = CheckDices();
echo $aFinal['text'];
if($aFinal['mode'] > 0){
echo '<br />You won: $'. ($_SESSION['Yahtzee']['money'] * $aFinal['mode']) ."<br />";
}else{
echo '<br />You lost: $'. ($_SESSION['Yahtzee']['money']) ."<br />";
}
// Reset de sessie Yahtzee voor een volgend potje
unset($_SESSION['Yahtzee']);
echo '<a href="Yahtzee.php?">New game.</a>';
}else{
//De eerste keer
if(isset($_POST['Yahtzeemoney']) AND is_numeric($_POST['Yahtzeemoney']) AND $_POST['Yahtzeemoney'] > 100 AND $_POST['Yahtzeemoney'] <= 3000000){
}else{
header('Location: Yahtzee.php');
exit;
}
$_SESSION['Yahtzee']['status'] = 1;
$_SESSION['Yahtzee']['money'] = $_POST['Yahtzeemoney'];
//Rol de dobbelstenen
RollDice(1);
RollDice(2);
RollDice(3);
RollDice(4);
RollDice(5);
//Print de dobbelstenen
PrintDices();
}
}else{
?>
<table>
<form action="?a=yatzee" method="post">
<input type="Hidden" name="submit" value="yes">
<tr align=center><td>Money <input type="text" name="Yahtzeemoney"></td></tr>
<tr align=center><td>Max bet 3,000,000</td></tr>
<tr align=center><td><input style="color:#000000" type="submit" name="Yahtzee" value="Start a new game!"></form></td></tr>
<tr height="24"><td></td></tr>
<tr><td>You win if you get any of the following:</td></tr>
<tr><td>Yahtzee: 3X</td></tr>
<tr><td>Large Straight: 1.5X</td></tr>
<tr><td>Four of a Kind: 1.3X</td></tr>
<tr><td>Full House: 1.2X</td></tr>
<tr><td>Three of a Kind: 1.0X</td></tr>
<tr><td>Small Straight does not exist in this game</td></tr>
</table>
Toevoeging op 09/04/2011 21:19:01:
Dat laatste is HTML obviously.
Gewijzigd op 09/04/2011 21:18:13 door Eckies eki
Er zijn nog geen reacties op dit bericht.