люди помогите пожалуйста с игрой "Покер с костями" из учебник Харриса
по сути почти все норм работает только проблема в том что условие с чекбоксами не выполняется вот собственно код
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
| <?php
$keepit[$i] = $_POST['keepit[$i]'];
$secondroll = $_POST['secondroll'];
$cash = $_POST['cash'];
if(empty($cash)){
$cash = 100;
}
rolldie();
if(secondroll==true){
print"<h2>Следующий бросок</h2>\n";
$secondroll=FALSE;
evaluate();
}else{
print"<h2>Первый бросок</h2>\n";
$secondroll=TRUE;
}
printstuff();
function rolldie(){
global $die, $secondroll, $keepit;
print"<table border='1'><td><tr>";
for($i=0;$i<5;$i++){
if($keepit[$i]==""){
$die[$i] = rand(1,6);
}else{
$die[$i] = $keepit[$i];}
$thefile="images/d$die[$i].png";
print<<<HERE
<td>
<img src = $thefile ><br>
HERE;
if($secondroll==FALSE){
print<<<HERE
<input type="checkbox" name="keepit[$i]" value="$die[$i]">
</td>
HERE;
}}
print<<<HERE
</tr></td>
<tr>
<td colspan="5">
<center>
<input type="submit">
</center>
</td></tr>
</table>
HERE;
}
function evaluate(){
global $die, $cash;
$playoff=0;
$cash-=2;
$numvals=array(0,0,0,0,0,0,0);
for($i=0;$i<5;$i++){
$numvals[$die[$i]]++;
}
for($i=1;$i<=6;$i++){
print"$i:$numvals[$i]<br>";
}
$numpairs=0;
$numthrees=0;
$numfours=0;
$numfives=0;
for($i=1;$i<=6;$i++){
switch($numvals[$i]){
case 2: $numpairs++; break;
case 3: $numthrees++; break;
case 4: $numfours++; break;
case 5: $numfives++; break;
}
}
if($numpairs == 2) {
print "You have two pairs!\n";
$payoff = 1;
}// end if
if($numthrees == 1) {
if($numpairs == 1) {
print "You have a full house! \n";
$payoff = 5;
} else {
print "You have three of a kind! \n";
$payoff = 2;
}// end if for double
}// end if for thriple
if($numfours == 1) {
print "You have four of a kind\n";
$payoff = 5;
}// end if
if($numfives == 1) {
print "You got a five of a kind !\n";
}// end if
if ( ($numvals[1] == 1)
&&($numvals[2] == 1)
&&($numvals[3] == 1)
&&($numvals[4] == 1)
&&($numvals[5] == 1)){
print "You have a straight!\n";
$payoff = 10;
}// end if
if ( ($numvals[2]==1)
&&($numvals[3]==1)
&&($numvals[4]==1)
&&($numvals[5]==1)
&&($numvals[6]==1)) {
print "You have a straight\n";
$payoff = 10;
}// end if
print "You bet 2\n";
print "Payoff is $payoff\n";
$cash += $payoff;
}
function printstuff(){
global $cash, $secondroll;
print"<br>Деньги $cash<br>";
print<<<HERE
<input type="hidden" name="secondroll" value="$secondroll">
<input type="hidden" name="cash" value="$cash">
HERE;
}
?> |
|
Добавлено через 6 часов 45 минут
нашел решение тему можно закрыть кому интересно вот прога
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
| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Документ без названия</title>
<link href="css/style.css" type="text/css" rel="stylesheet">
</head>
<body style="background-color:green;">
<h1 style="text-align:center;font-family:Comic Sans Ms; ">Игра "Покер в кости"</h1>
<form method="POST">
<?php
$secondroll = $_POST['secondroll'];
if(empty($_POST["cash"])) $cash = 100;
else $cash = $_POST["cash"];
rolldie();
if($_POST["secondroll"] == "1") {
print "<h2>Second roll</h1>\n";
$secondroll = "0";
evaluate();
} else {
print "<h2>First Roll</h2>\n";
$secondroll = "1";
}
printstuff();
function rolldie(){
global $die, $secondroll, $keepit;
print"<table border='1'>";
for($i=0;$i<5;$i++){
if(!isset($_POST["keepit"][$i])){
$die[$i] = rand(1,6);
} else {
$die[$i] = $_POST["keepit"][$i];
}// завершення if
$thefile="images/d$die[$i].png";
print<<<HERE
<td>
<img src = $thefile ><br>
HERE;
if($secondroll == "1") {
print "<input type='checkbox' name='keepit[".$i."]' value='".$die[$i]."'>
</td>";
}}
print<<<HERE
</tr></td>
<tr>
<td colspan="5">
<center>
<input type="submit">
</center>
</td></tr>
</table>
HERE;
}
function evaluate(){
global $die, $cash;
$payoff=0;
$cash-=2;
$numvals=array(6);
for($theval=1;$theval<=6;$theval++){
for($dienum=0;$dienum<5;$dienum++){
if($die[$dienum]==$theval){
$numvals[$theval]++;}}}
for($i=1;$i<=6;$i++){
print"$i:$numvals[$i]<br>";}
$numPairs = 0;
$numThrees = 0;
$numFours = 0;
$numFives = 0;
for($i = 1; $i <= 6; $i++){
switch($numvals[$i]){
case 2:
$numPairs++;
break;
case 3:
$numThrees++;
break;
case 4:
$numFours++;
break;
case 5:
$numFives++;
break;}}
if($numPairs == 2) {
print "You have two pairs!\n";
$payoff = 1;
}// end if
if($numThrees == 1) {
if($numPairs == 1) {
print "You have a full house! \n";
$payoff = 5;
} else {
print "You have three of a kind! \n";
$payoff = 2;
}// end if for double
}// end if for thriple
if($numFours == 1) {
print "You have four of a kind\n";
$payoff = 5;
}// end if
if($numFives == 1) {
print "You got a five of a kind !\n";
}// end if
if ( ($numVals[1] == 1)
&&($numVals[2] == 1)
&&($numVals[3] == 1)
&&($numVals[4] == 1)
&&($numVals[5] == 1)){
print "You have a straight!\n";
$payoff = 10;
}// end if
if ( ($numVals[2]==1)
&&($numVals[3]==1)
&&($numVals[4]==1)
&&($numVals[5]==1)
&&($numVals[6]==1)) {
print "You have a straight\n";
$payoff = 10;
}// end if
print "You bet 2\n";
print "Payoff is $payoff\n";
$cash += $payoff;
}
function printstuff(){
global $cash, $secondroll;
print"<br>Деньги $cash<br>";
print<<<HERE
<input type="hidden" name="secondroll" value="$secondroll">
<input type="hidden" name="cash" value="$cash">
HERE;
}
?>
</form>
</body>
</html> |
|