Jump to content

SUBIECTE NOI
« 1 / 5 »
RSS
La multi ani @Passenger001!

La multi ani @barbosa1bis!

La multi ani @MikeSpike!

Cum curat gletul de pe perete
 Soluție incalzire apartament...

Culori fire la boxele de jogger

Autorizatie Birou Acte Auto

Parbriz defect
 Ajutor cercetare lucrare de diser...

M-am culcat cu un tip și apo...

Facultate din Bucuresti posibil o...

Eroare steering
 Recomandare service pentru repara...

Premier Energy se listeaza la bursa

Unde recomandati un CT cu Casa de...

Adaptare masina pentru o persoana...
 

Cookie/sesiune/php

- - - - -
  • Please log in to reply
2 replies to this topic

#1
phpguru

phpguru

    Junior Member

  • Grup: Members
  • Posts: 127
  • Înscris: 12.07.2012
1. Dati copy/paste si puneti codul intr-o pagina.
2. Prima problema este acolo unde setcookie l-am dezactivat cu // deoarece atunci cand primeam un rezultat, gen: 1. Egalitate, imi apare pagina blank nu mi se salveaza cookie corect ca celelalte.
3. A 2 a problema este cartea A, desi random returneaza 1 sau 11, jos in paranteze afiseaza mereu (11). Celelalte carti afiseaza corect valoarea lor.
4. A 3 a problema este ca nu stiu sa adaug un buton nou Dubleaza miza, tot cu sesiune, in care sa dublez suma (pe care o stabilesc eu din cookie). Mai exact butonul de dublat sa fie egal cu butonul Retrage, cu diferenta ca dubleaza miza curenta.

<?php
echo "<!DOCTYPE html>\n" ;
echo "<html lang=\"ro-RO\">\n" ;
echo "<head>\n" ;
$ogtitle = "Blackjack 21 | Joc de cazino popular in lume" ;
echo "<title>" . $ogtitle . "</title>\n" ;
echo "<meta charset=\"UTF-8\">\n" ;
echo "<link rel=\"icon\" type=\"image/png\" href=\"https://img.icons8.com/arcade/36/1FB141/hangman.png\">\n" ;
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"/static/css/default.css\">\n" ;
echo "</head>\n" ;
echo "<body>\n" ;
$wname = "Blackjack21" ; // Nume
$wvalue = "666" ; // Valoare
$wtime = time() + ( 60 * 60 ) ; // 1h
$wlock = date( "H:i, d.m.Y", $wtime ) ; // Timp asteptare
if ( ! isset( $_COOKIE[$wname] ) ) {
setcookie( $wname, $wvalue, $wtime ) ;
echo "<div style=\"text-align: left;\">\n" ;
echo "- " . $ogtitle . ".\n" ;
echo "<br/>\n" ;
echo "- Varsta recomandata: minim 18 ani.\n" ;
echo "<br/>\n" ;
echo "- Jucatori participanti: maxim 5.\n" ;
echo "<br/>\n" ;
echo "- Wlogi alocati: " . $wvalue . ".\n" ;
echo "<br/>\n" ;
echo "- Acesta este un simulator de joc online.\n" ;
echo "<br/>\n" ;
echo "- <a href=\"#\"onclick=\"javascript:window.location.reload();\">Incepe jocul</a>\n" ;
echo "</div>\n" ;
} else {
if ( $_COOKIE[$wname] < 3 ) {
echo "<div style=\"text-align: left;\">\n" ;
echo "- Nu mai ai wlogi, revino dupa " . $wlock . "\n" ;
echo "<br/>\n" ;
echo "- Jocul nu a fost creat sa castigi ceva, ci doar sa te distrezi.\n" ;
echo "<br/>\n" ;
echo "- <a href=\"cazino.php\" title=\"*\">Cazino 777</a>\n" ;
echo "<br/>\n" ;
echo "- <a href=\"piatra-hartie-foarfeca.php\" title=\"*\">Piatra, Hartie, Foarfeca</a>\n" ;
echo "</div>\n" ;
} else {
session_start() ;
$cards = array(
"2" => 2,
"3" => 3,
"4" => 4,
"5" => 5,
"6" => 6,
"7" => 7,
"8" => 8,
"9" => 9,
"10" => 10,
"J" => 10,
"Q" => 10,
"K" => 10,
"A" => 11 ) ;
$types = array(
"C",
"D",
"H",
"S" ) ;
$winner = false ;
function notification( $msg ) {
echo $msg . "\n" ;
}
function pullCard() {
global $cards ;
global $types ;
$tmp["card"] = array_rand( $cards ) ;
$tmp["type"] = $types[array_rand( $types )] ;
while ( in_array( $tmp["card"] . $tmp["type"], $_SESSION["used_cards"] ) ) {
$tmp["card"] = array_rand( $cards ) ;
$tmp["type"] = $types[array_rand( $types )] ;
}
$_SESSION["used_cards"][] = $tmp["card"] . $tmp["type"] ;
return $tmp ;
}
function calcCards( $hand ) {
global $cards ;
$count = 0 ;
$aces = 0 ;
foreach ( $hand as $card ) {
if ( $card["card"] != "1" ) {
$count += $cards[$card["card"]] ;
} else {
$aces++ ;
}
}
for ( $x = 0; $x < $aces; $x++ ) {
if ( $count + 11 > 21 ) {
$count += 1 ;
} else {
$count += 11 ;
}
}
return $count ;
}
echo "<div style=\"text-align: center;\">\n" ;
function checkWinner( $player, $computer ) {
global $winner ;
if ( $winner != true ) {
if ( calcCards( $player ) == 21 && calcCards( $computer ) == 21 ) {
//$Total = $_COOKIE[$wname] + 0 ;
//setcookie( $wname, $Total, $wtime ) ;
echo notification( "<mark>1. Egalitate</mark>" ) ;
$winner = true ;
} else
if ( calcCards( $player ) > 21 || calcCards( $computer ) == 21 ) {
//$Wlogs = mt_rand( 1, 5 ) ;
//$Total = $_COOKIE[$wname] - $Wlogs ;
//setcookie( $wname, $Total, $wtime ) ;
echo notification( "<mark>1. Ne pare rau, ai pierdut. " . $Wlogs . " wlogi</mark>" ) ;
$winner = true ;
} else
if ( calcCards( $computer ) > 21 || calcCards( $player ) == 21 ) {
//$Wlogs = mt_rand( 1, 5 ) ;
//$Total = $_COOKIE[$wname] + $Wlogs ;
//setcookie( $wname, $Total, $wtime ) ;
echo notification( "<mark>1. Bravo, ai castigat " . $Wlogs . " wlogi</mark>" ) ;
$winner = true ;
} else {
return false ;
}
}
}
if ( $_POST["reset"] ) {
session_destroy() ;
session_start() ;
}
if ( ! $_SESSION["hand_player"] ) {
$_SESSION["used_cards"] = array() ;
$hand_player = array() ;
$hand_computer = array() ;
array_push( $hand_player, pullCard() ) ;
array_push( $hand_player, pullCard() ) ;
array_push( $hand_computer, pullCard() ) ;
array_push( $hand_computer, pullCard() ) ;
$_SESSION["hand_player"] = $hand_player ;
$_SESSION["hand_computer"] = $hand_computer ;
}
if ( $_POST["hit"] && $winner != true ) {
array_push( $_SESSION["hand_player"], pullCard() ) ;
} else
if ( $_POST["stand"] && $winner != true ) {
while ( calcCards( $_SESSION["hand_player"] ) > calcCards( $_SESSION["hand_computer"] ) ) {
array_push( $_SESSION["hand_computer"], pullCard() ) ;
if ( calcCards( $_SESSION["hand_computer"] ) == 21 && calcCards( $_SESSION["hand_player"] ) == 21 ) {
$Total = $_COOKIE[$wname] + 0 ;
setcookie( $wname, $Total, $wtime ) ;
echo notification( "<mark>2. Egalitate</mark>" ) ;
$winner = true ;
continue ;
} else
if ( calcCards( $_SESSION["hand_computer"] ) > 21 ) {
$Wlogs = mt_rand( 1, 5 ) ;
$Total = $_COOKIE[$wname] + $Wlogs ;
setcookie( $wname, $Total, $wtime ) ;
echo notification( "<mark>2. Bravo, ai castigat " . $Wlogs . " wlogi</mark>" ) ;
$winner = true ;
continue ;
} else
if ( ( calcCards( $_SESSION["hand_player"] ) < calcCards( $_SESSION["hand_computer"] ) || calcCards( $_SESSION["hand_computer"] ) == 21 ) ) {
$Wlogs = mt_rand( 1, 5 ) ;
$Total = $_COOKIE[$wname] - $Wlogs ;
setcookie( $wname, $Total, $wtime ) ;
echo notification( "<mark>2. Ne pare rau, ai pierdut " . $Wlogs . " wlogi</mark>" ) ;
$winner = true ;
continue ;
}
}
if ( calcCards( $_SESSION["hand_player"] ) == calcCards( $_SESSION["hand_computer"] ) ) {
$Total = $_COOKIE[$wname] + 0 ;
setcookie( $wname, $Total, $wtime ) ;
echo notification( "<mark>3. Egalitate</mark>" ) ;
$winner = true ;
}
if ( ( calcCards( $_SESSION["hand_computer"] ) > calcCards( $_SESSION["hand_player"] ) ) && $winner != true ) {
$Wlogs = mt_rand( 1, 5 ) ;
$Total = $_COOKIE[$wname] - $Wlogs ;
setcookie( $wname, $Total, $wtime ) ;
echo notification( "<mark>3. Ne pare rau, ai pierdut " . $Wlogs . " wlogi</mark>" ) ;
$winner = true ;
}
}
checkWinner( $_SESSION["hand_player"], $_SESSION["hand_computer"] ) ;
echo "<div class=\"cards-table\">\n" ;
$comp = 0 ;
foreach ( $_SESSION["hand_computer"] as $card ) {
if ( $comp != 0 || $winner == true ) {
echo "<div class=\"cards\">\n" ;
echo "<img src=\"test5/cards/" . $card["card"] . $card["type"] . ".png\">\n" ;
echo "<br/>\n" ;
echo "(" . $cards[$card["card"]] . ")\n" ;
echo "</div>\n" ;
} else {
$rand = ["21CB", "21CR"] ;
$what = $rand[mt_rand( 0, count( $rand ) - 1 )] ;
echo "<div class=\"cards\">\n" ;
echo "<img src=\"test5/cards/21CB.png\">\n" ;
echo "<br/>\n" ;
echo "(?)\n" ;
echo "</div>\n" ;
}
$comp++ ;
}
echo "</div>\n" ;
if ( $winner == true ) {
echo "Calculator: " . calcCards( $_SESSION["hand_computer"] ) . "\n" ; //echo count( $_SESSION["hand_computer"] );
echo "<br/>\n" ;
}
echo "<br/>\n" ;
echo "<div class=\"cards-table\">\n" ;
foreach ( $_SESSION["hand_player"] as $card ) {
echo "<div class=\"cards\">\n" ;
echo "<img src=\"test5/cards/" . $card["card"] . $card["type"] . ".png\">\n" ;
echo "<br/>\n" ;
echo "(" . $cards[$card["card"]] . ")\n" ;
echo "</div>\n" ;
}
echo "</div>\n" ;
echo "Jucator: " . calcCards( $_SESSION["hand_player"] ) . "\n" ; //echo count( $_SESSION["hand_player"] );
echo "<br/>\n" ;
echo "<br/>\n" ;
echo "<form action=\"" . htmlentities( $_SERVER["PHP_SELF"] ) . "\" method=\"POST\">\n" ;
if ( $winner == true ) {
echo "<button type=\"submit\" name=\"reset\" value=\"reset\" style=\"background: green; color: white; font-weight: bold; height: 30px;\">Joc nou</button>\n" ;
} else {
echo "<button type=\"submit\" name=\"hit\" value=\"hit\" style=\"background: red; color: white; font-weight: bold; height: 30px;\">Mizez</button>\n" ;
echo "<button type=\"submit\" name=\"stand\" value=\"stand\" style=\"background: blue; color: white; font-weight: bold; height: 30px;\">Retrag</button>\n" ;
}
echo "</form>\n" ;
echo "(Wlogi: " . $_COOKIE[$wname] . ")\n" ;
echo "</div>\n" ;
}
}
echo "</body>\n";
echo "</html>\n";
if ( $winner == true ) {
session_destroy() ;
session_start() ;
}
?>



#2
radu103

radu103

    Guru Member

  • Grup: Senior Members
  • Posts: 12,513
  • Înscris: 15.11.2003
E mai util sa dai share la code + runtime atunci cand vrei ajutor https://onlinephp.io/
Codul de mai sus arata oribil, ma zgarie pe ochi asa ca nu ma uit atent, sintetizeaza perfect : asa nu se face

Edited by radu103, 17 November 2023 - 01:10.


#3
robert23mg

robert23mg

    Member

  • Grup: Members
  • Posts: 555
  • Înscris: 18.06.2017
3. A 2 a problema este cartea A, desi random returneaza 1 sau 11, jos in paranteze afiseaza mereu (11). Celelalte carti afiseaza corect valoarea lor.

Incearca sa incapsulezi cartile macar in niste obiecte de forma, daca nu vrei in clasa diferita
[ label => 'K', value => 10 ], asa o sa fi mereu sigur de valoarea unui label

Anunturi

Chirurgia spinală minim invazivă Chirurgia spinală minim invazivă

Chirurgia spinală minim invazivă oferă pacienților oportunitatea unui tratament eficient, permițându-le o recuperare ultra rapidă și nu în ultimul rând minimizând leziunile induse chirurgical.

Echipa noastră utilizează un spectru larg de tehnici minim invazive, din care enumerăm câteva: endoscopia cu variantele ei (transnazală, transtoracică, transmusculară, etc), microscopul operator, abordurile trans tubulare și nu în ultimul rând infiltrațiile la toate nivelurile coloanei vertebrale.

www.neurohope.ro

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users

Forumul Softpedia foloseste "cookies" pentru a imbunatati experienta utilizatorilor Accept
Pentru detalii si optiuni legate de cookies si datele personale, consultati Politica de utilizare cookies si Politica de confidentialitate