3 / 3 / 1
Регистрация: 12.10.2009
Сообщений: 79
1

Poker Dice Энди Харрис

01.05.2012, 21:13. Показов 1652. Ответов 4
Метки нет (Все метки)

Студворк — интернет-сервис помощи студентам
люди помогите пожалуйста с игрой "Покер с костями" из учебник Харриса
по сути почти все норм работает только проблема в том что условие с чекбоксами не выполняется вот собственно код

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>
1
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
01.05.2012, 21:13
Ответы с готовыми решениями:

ДЗ с учебника по PHP Энди Харрис
Задание: &quot;Создайте игру Морской бой, для двух игроков за одним компьютером. Игра будет отображать...

Проблема с глобальными переменными{Энди Харрис:-(, он такой}
В общем в книге 2005 года нашёл код вот такой вот(возможно вам знакомый): &lt;html&gt; &lt;head&gt;...

Энди Харрис - PHP/MySQL для начинающих. Актуальна?
Всем доброго времени суток. Хочу подтянуть базовые знания PHP, посмотрел список книг, которые...

Atmega8 (Dice)
Доброе утро. Надо сделать игральные кости от 0-6. 1 кнопка, при нажатии выводит случайное число. 2...

4
2386 / 2250 / 584
Регистрация: 27.05.2011
Сообщений: 7,709
02.05.2012, 13:49 2
Цитата Сообщение от Huk Посмотреть сообщение
нашел решение
Notice: Undefined index: secondroll in /var/www/absolux/test/run.php on line 12
нуну
0
3 / 3 / 1
Регистрация: 12.10.2009
Сообщений: 79
03.05.2012, 18:06  [ТС] 3
Цитата Сообщение от crautcher Посмотреть сообщение
Notice: Undefined index: secondroll in /var/www/absolux/test/run.php on line 12
нуну
ээээ и что же у тебя не запускается? у меня все отлично работает!!!!!!
0
2386 / 2250 / 584
Регистрация: 27.05.2011
Сообщений: 7,709
03.05.2012, 18:18 4
Цитата Сообщение от Huk Посмотреть сообщение
ээээ и что же у тебя не запускается? у меня все отлично работает!!!!!!
вывод ошибок включи , ты в слепую работаешь
0
3 / 3 / 1
Регистрация: 12.10.2009
Сообщений: 79
03.05.2012, 18:44  [ТС] 5
Цитата Сообщение от crautcher Посмотреть сообщение
вывод ошибок включи , ты в слепую работаешь
Гыыы спасибо буду знать там все баги лечаться @ =)))


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
<?php
$secondroll = $_POST['secondroll'];
ini_set('display_errors', 1);
  error_reporting(E_ALL);
if(empty($_POST["cash"])) $cash = 100;
else $cash = $_POST["cash"];
rolldie();
if($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;
}
?>
0
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
03.05.2012, 18:44
Помогаю со студенческими работами здесь

Класc Dice (игральные кости).
Доброго времени суток! Ребят, подскажите Вот задание моё для лабы: &quot;Создать обьявление класса и...

игра Dice (бросаются кубики+высчитывается их сумма)
Здравствуйте, нужна помощь. Задание - игра Dice (есть 2 кубика, рандомно выпадающие значения кубика...

Poker
Даны 5 целых чисел. Среди них: если одинаковы 5, то вывести &quot;Impossible&quot;, иначе если одинаковы 4,...

Poker
Даны 5 целых чисел. Среди них: если одинаковы 5, то вывести &quot;Impossible&quot;, иначе если одинаковы...

Отсортировать poker hand
Добрый день, пишу небольшую программу для покера, конкретно для омахи(одна из разновидностей...

Создание онлайн приложения Poker
На каком языке программирования лучше и проще написать онлайн покер для социальной сети?


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
5
Ответ Создать тему
Опции темы

КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2023, CyberForum.ru