3
Good afternoon, I’m making a scratch card in Actionscript and PHP. I have 9 boxes and when I click the buy button it goes to a PHP file and generates in a cycle is a Rand of random numbers to be shown, when clicked on the boxes, what I intend to do now and when it comes out 3 equal numbers automatically tell me who won and appear a message and count the value of the prize and send to the database where you have the player credits .
PHP code
<?php
$host = "localhost";
$bd = "raspadinha";
$user = "root";
$pass = "";
try {
$conexao = new PDO('mysql:host='.$host.';dbname='.$bd.';charset=utf8', ''.$user.'', ''.$pass.'');
$conexao->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo 'Error : <br>' . $e->getMessage();
}
$query = $_POST['query'];
$sql_saldo_loaded = $conexao->prepare("SELECT * FROM raspadinha");
$sql_saldo_loaded->execute();
$row_saldo_loaded = $sql_saldo_loaded->fetch(PDO::FETCH_ASSOC);
$saldo_loaded = $row_saldo_loaded['saldo'];
if($query == "saldo_loaded"){
echo "saldo=$saldo_loaded";
}
if($query == "valores"){
$alert = "N�o tem mais Creditos para jogar";
$sql_saldo_verificar = $conexao->prepare("SELECT * FROM raspadinha");
$sql_saldo_verificar->execute();
$row_saldo_verificar = $sql_saldo_verificar->fetch(PDO::FETCH_ASSOC);
if($row_saldo_verificar['saldo'] == "0" ){
echo "msg=$alert";
}else{
for ($i = 0; $i<9; $i++){
$a = mt_rand(1,9);
echo "valor" . ($i + 1) . "=$a&";
}
for ($i_premio = 0; $i_premio<9; $i_premio++){
$premio = mt_rand(1,50);
echo "premio" . ($i_premio + 1) . "=$premio&";
}
$sql = $conexao->prepare("UPDATE raspadinha SET saldo = saldo - preco");
$sql->execute();
$sql_saldo = $conexao->prepare("SELECT * FROM raspadinha");
$sql_saldo->execute();
$row_saldo_ver = $sql_saldo->fetch(PDO::FETCH_ASSOC);
$saldo_descontado = $row_saldo_ver['saldo'];
echo "saldo=$saldo_descontado";
}
}
if($query == "saldo"){
echo "saldo=$saldo_descontado";
}
//echo "valor=$rand";
?>
Flash code
var vars_send:LoadVars = new LoadVars();
var valores_rcv:LoadVars = new LoadVars();
var saldo_rcv:LoadVars = new LoadVars();
var saldo_loaded:LoadVars = new LoadVars();
vars_send.query = "saldo_loaded";
vars_send.sendAndLoad("http://localhost/api.php",saldo_loaded,"POST");
saldo_loaded.onLoad = function(success:Boolean) {
if (success) {
saldo.txt_saldo.text = saldo_loaded.saldo;
} else {
trace("Erro do conexao");
}
};
valores_rcv.onLoad = function(success:Boolean) {
if (success) {
trace(valores_rcv);
for (var i:Number = 0; i < 9; i++) {
_level0["quadrado" + (i + 1)].txt._visible = false;
_level0["quadrado" + (i + 1)].txt_premio._visible = false;
cor = new Color(_level0["quadrado" + (i + 1)].bg);
cor.setRGB(0xa2a1a1);
//
_level0["quadrado" + (i + 1)].txt.text = valores_rcv["valor" + (i+1)];
_level0["quadrado" + (i + 1)].txt_premio.text = valores_rcv["premio" + (i+1)];
}
if(valores_rcv.saldo >= 0){
saldo.txt_saldo.text = valores_rcv.saldo;
}
} else {
trace("Erro do conexao");
}
};
saldo_rcv.onLoad = function(success:Boolean) {
if (success) {
trace(saldo_rcv);
saldo.txt_saldo.text = saldo_rcv.saldo;
} else {
trace("Erro do conexao");
}
};
for (var i:Number = 0; i < 9; i++) {
_level0["quadrado" + (i + 1)].onRelease = function() {
cor = new Color(this.bg);
cor.setRGB(0xFFFF00);
this.txt._visible = true;
this.txt_premio._visible = true;
};
}
/*function randRange(min:Number, max:Number):Number {
var randomNum:Number = Math.floor(Math.random() * (max - min + 1)) + min;
return randomNum;
}*/
iniciar.onRelease = function() {
vars_send.query = "valores";
if(valores_rcv.saldo == "1"){
this.enabled = false;
}
vars_send.sendAndLoad("http://localhost/api.php",valores_rcv,"POST");
};
Let me ask you, why doesn’t it generate 3 Rand from 0 to 9 each, it’s easier to compare later
– Lucas Mota
It might be if you think it’s best to make a response if you please the altered code and to fuck with me I intend to do please and that I’m not able to do
– César Sousa