Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > Web Development
You last visited: Today at 20:47

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[Hilfe]"Slot Machine" Spielentwicklung

Discussion on [Hilfe]"Slot Machine" Spielentwicklung within the Web Development forum part of the Coders Den category.

Reply
 
Old   #1
 
TramaLP's Avatar
 
elite*gold: 461
Join Date: Jul 2014
Posts: 917
Received Thanks: 24
[Hilfe]"Slot Machine" Spielentwicklung

Hallo,

ich benötige ein wenig Hilfe beim programmieren einer Slot Machine.

Derzeitiger Stand:
bm_slots.php
PHP Code:
<?php
require_once "header.php";
require_once 
"maincore.php";

$smarty->assign('username',$userdet['username']);
$smarty->assign('slots_bet',$userdet['slots_bet']);

$randomnumber rand(1,9);
$smarty->assign('randomnumber',$randomnumber);
$randomnumber2 rand(1,9);
$smarty->assign('randomnumber2',$randomnumber2);
$randomnumber3 rand(1,9);
$smarty->assign('randomnumber3',$randomnumber3);

$invest $userdet['slots_bet'];
$userid $userdet['user_id'];

if (
$_POST['betvalue'] > 0){
    
$db->query("update tbl_user set slots_bet='$invest' where user_id='$userid'");
}

$mal1 10;
$mal2 15;
$mal3 25;
$mal4 35;
$mal5 40;
$mal6 45;
$mal7 50;
$mal8 75;
$mal9 100;

if (
$randomnumber == 1){
    if (
$randomnumber2 == 1){
        if (
$randomnumber3 == 1){
            
$lose 1;
            
$wincalc $invest*$mal1;
            
$win $wincalc;

            if (
$_POST['play'] == $_POST['play']){
                if (
$userdet['credit'] < $userdet['slots_bet']){
                    
$smarty->assign('cashcheck','Sorry, you got not enaught BTC to play.');
                } else {
                    if (
$lose == 1){
                        
$smarty->assign('winorlosetest','Dude, you win!');
                    } else {
                        
$smarty->assign('winorlosetest','Oh no, you lose!');        
                    }
                }
            }

        }
    }
}
if (
$randomnumber == 2){
    if (
$randomnumber2 == 2){
        if (
$randomnumber3 == 2){
            
$lose 1;
            
$wincalc $invest $mal1;
            
$win $wincalc;
if (
$_POST['play'] == $_POST['play']){
    if (
$userdet['credit'] < $userdet['slots_bet']){
        
$smarty->assign('cashcheck','Sorry, you got not enaught BTC to play.');
    } else {
        if (
$lose == 1){
            
$smarty->assign('winorlosetest','Dude, you win!');
        } else {
            
$smarty->assign('winorlosetest','Oh no, you lose!');        
        }
    }
}
        }
    }
}
if (
$randomnumber == 3){
    if (
$randomnumber2 == 3){
        if (
$randomnumber3 == 3){
            
$lose 1;
            
$wincalc $invest $mal2;
            
$win $wincalc;
if (
$_POST['play'] == $_POST['play']){
    if (
$userdet['credit'] < $userdet['slots_bet']){
        
$smarty->assign('cashcheck','Sorry, you got not enaught BTC to play.');
    } else {
        if (
$lose == 1){
            
$smarty->assign('winorlosetest','Dude, you win!');
        } else {
            
$smarty->assign('winorlosetest','Oh no, you lose!');        
        }
    }
}
        }
    }
}
if (
$randomnumber == 4){
    if (
$randomnumber2 == 4){
        if (
$randomnumber3 == 4){
            
$lose 1;
            
$wincalc $invest $mal4;
            
$win $wincalc;
if (
$_POST['play'] == $_POST['play']){
    if (
$userdet['credit'] < $userdet['slots_bet']){
        
$smarty->assign('cashcheck','Sorry, you got not enaught BTC to play.');
    } else {
        if (
$lose == 1){
            
$smarty->assign('winorlosetest','Dude, you win!');
        } else {
            
$smarty->assign('winorlosetest','Oh no, you lose!');        
        }
    }
}
        }
    }
}
if (
$randomnumber == 5){
    if (
$randomnumber2 == 5){
        if (
$randomnumber3 == 5){
            
$lose 1;
            
$wincalc $invest $mal5;
            
$win $wincalc;
if (
$_POST['play'] == $_POST['play']){
    if (
$userdet['credit'] < $userdet['slots_bet']){
        
$smarty->assign('cashcheck','Sorry, you got not enaught BTC to play.');
    } else {
        if (
$lose == 1){
            
$smarty->assign('winorlosetest','Dude, you win!');
        } else {
            
$smarty->assign('winorlosetest','Oh no, you lose!');        
        }
    }
}
        }
    }
}
if (
$randomnumber == 6){
    if (
$randomnumber2 == 6){
        if (
$randomnumber3 == 6){
            
$lose 1;
            
$wincalc $invest $mal6;
            
$win $wincalc;
if (
$_POST['play'] == $_POST['play']){
    if (
$userdet['credit'] < $userdet['slots_bet']){
        
$smarty->assign('cashcheck','Sorry, you got not enaught BTC to play.');
    } else {
        if (
$lose == 1){
            
$smarty->assign('winorlosetest','Dude, you win!');
        } else {
            
$smarty->assign('winorlosetest','Oh no, you lose!');        
        }
    }
}
        }
    }
}
if (
$randomnumber == 7){
    if (
$randomnumber2 == 7){
        if (
$randomnumber3 == 7){
            
$lose 1;
            
$wincalc $invest $mal7;
            
$win $wincalc;
if (
$_POST['play'] == $_POST['play']){
    if (
$userdet['credit'] < $userdet['slots_bet']){
        
$smarty->assign('cashcheck','Sorry, you got not enaught BTC to play.');
    } else {
        if (
$lose == 1){
            
$smarty->assign('winorlosetest','Dude, you win!');
        } else {
            
$smarty->assign('winorlosetest','Oh no, you lose!');        
        }
    }
}
        }
    }
}
if (
$randomnumber == 8){
    if (
$randomnumber2 == 8){
        if (
$randomnumber3 == 8){
            
$lose 1;
            
$wincalc $invest $mal8;
            
$win $wincalc;
if (
$_POST['play'] == $_POST['play']){
    if (
$userdet['credit'] < $userdet['slots_bet']){
        
$smarty->assign('cashcheck','Sorry, you got not enaught BTC to play.');
    } else {
        if (
$lose == 1){
            
$smarty->assign('winorlosetest','Dude, you win!');
        } else {
            
$smarty->assign('winorlosetest','Oh no, you lose!');        
        }
    }
}
        }
    }
}
if (
$randomnumber == 9){
    if (
$randomnumber2 == 9){
        if (
$randomnumber3 == 9){
            
$lose 1;
            
$win $invest*$mal9;
if (
$_POST['play'] == $_POST['play']){
    if (
$userdet['credit'] < $userdet['slots_bet']){
        
$smarty->assign('cashcheck','Sorry, you got not enaught BTC to play.');
    } else {
        if (
$lose == 1){
            
$smarty->assign('winorlosetest','Dude, you win!');
        } else {
            
$smarty->assign('winorlosetest','Oh no, you lose!');        
        }
    }
}
        }
    }
}

if (
$lose == 1){
$smarty->assign('winorlose','You win $win BTC!');
}
else {
$smarty->assign('winorlose','You lose, try again!');
}







require_once 
"includes/solvemedialib.php";
require_once 
"includes/dbconnector.class.php";
$db=new DbConnector;
if(isset(
$_POST['claim'])){
    
$solvemedia_response solvemedia_check_answer($verkey,$_SERVER["REMOTE_ADDR"],$_POST['adcopy_challenge'],$_POST['adcopy_response'],$hashkey);
    if(
$solvemedia_response->is_valid ){
    
        
$db2->query("select * from tbl_prize order by chance desc ");
        while(
$res2=$db2->fetchArray()){
            
$prize.=$res2['prize'].'*'.$res2['chance'].',';    
        }
    
        
        if(!isset(
$_SESSION['prize']))
            
$_SESSION['prize']=chance_creator($prize);
    
        
$db->queryres("select * from tbl_config where header='timer'");
        
$timer=NOW+($db->res['value']*60);
        
$db->query("update tbl_user set credit=credit+'".$_SESSION['prize']."',reset='$timer',ip='$ip' where user_id='$uid'");
        
$rid=$userdet['parent_id'];
    
        if(
$rid){
            
$db->queryres("select * from tbl_config where header='referral_percent'");
            
$profit=($_SESSION['prize']*$db->res['value'])/100;
            
$db->query("update tbl_user set credit=credit+'$profit' where user_id='$rid'");
        }
        
        
$_SESSION['user']['win']=$_SESSION['prize'];
        unset(
$_SESSION['prize']);
        
header('Location:index.php');

    }else{
        unset(
$_SESSION['succ']);
        unset(
$_SESSION['error']);
        
$_SESSION['error']['capt']=true;
        
header('Location:index.php?er=captcha');
    }
}else{

if(isset(
$uid)){


if(isset(
$_SESSION['user']['win'])){
    
$db->queryres("select * from tbl_config where header='currency'");
    
$smarty->assign('prize',$_SESSION['user']['win']);
    
$smarty->assign('curency',$db->res['value']);
    
}

if(isset(
$_SESSION['error']['capt'])){
    
$smarty->assign('capt',true);
    unset(
$_SESSION['error']);
}

$db->queryres("select reset from tbl_user where user_id='$uid' or ip='$ip' order by reset desc");
    if(
$db->res['reset']-time() > 0){
        
$smarty->assign('timer',true);
        
$smarty->assign('timer_amount',$db->res['reset']-time());
    }




    
$with=array();
    
$db->query("select * from tbl_donate where status=2 order by rand() limit 20");
    while(
$res=$db->fetchArray()){
        
$ar=array('link'=>$res['link']);
        
array_push($with,$ar);
    }
    
$smarty->assign('with',$with);

$smarty->assign('captcha',solvemedia_get_html($privkey));


}else{
    
    
$smarty->assign('notlogged',true);
    
    
}








$smarty->display('template/bm_slots.tpl');

}

?>
Template Datei:
PHP Code:
{include file='template/header.tpl'}


<
div id="blue">
    <
div class="container">
        <
div class="row"><h3>Bitcoin Millionaire Slots</h3></div><!-- /row -->     
    </
div> <!-- /container -->    
</
div>    

<
div class="navbar navbar-default">
    <
div class="row">
        <
div class="col-md-2 text-center" style="width:135px;">    
            
        </
div>
        <
Div class="col-md-9">
            <
Div class="row text-center">
                
            </
Div>
            {if !
$notlogged}
            <
center>
            
This is only to demonstrate the gameThe full version of this will be online soon!<br>Information: If you visit this game in a new Sessionit will automatically show youthat you lostbut no Credits are gone.<br>_________________________________________________________________________<br><br>
            <
table >
                <
tr>
                    <
td width="40%">
                        <
center>
                            <
div class="alert alert-info"><h3>You roll:</h3><br><img src='img/slots_{$randomnumber}.png' ><img src='img/slots_{$randomnumber2}.png' ><img src='img/slots_{$randomnumber3}.png' ><br></div>
                        </
center>
                    </
td>
                    <
td width="20%">
                    </
td>
                    <
td width="40%">
                        <
center>
                            <
div class="alert alert-info"><b>{$winorlose}</b></div>
                            <
b>Bet:</b> {$slots_bet}<br><br>
                            <
form action="bm_slots.php" method="post">
                                <
input name="betvalue" type="text" class="btn btn-success" size="10" placeholder="0.00000000">
                                <
button type="submit" name="bet" class="btn btn-success">Set new bet</button>
                            </
form><br><br>
                            <
form>
                                <
button type="submit" value="play" name="play" class="btn btn-success">Roll!</button>
                            </
form>
                            
                            <
br><br><br>{$cashcheck}<br>{$winorlosetest}
                        </
center>
                    </
td>
                </
tr>
            </
table>
            <
table >
                <
tr>
                    <
td>
                        <
center>
                            <
b>Wintable:</b><br>
                            <
img src="img/slots_1.png" width="25px" height="25px"><img src="img/slots_1.png" width="25px" height="25px"><img src="img/slots_1.png" width="25px" height="25px"> = x10    <img src="img/slots_5.png" width="25px" height="25px"><img src="img/slots_5.png" width="25px" height="25px"><img src="img/slots_5.png" width="25px" height="25px"> = x40<br>
                            <
img src="img/slots_2.png" width="25px" height="25px"><img src="img/slots_2.png" width="25px" height="25px"><img src="img/slots_2.png" width="25px" height="25px"> = x15    <img src="img/slots_6.png" width="25px" height="25px"><img src="img/slots_6.png" width="25px" height="25px"><img src="img/slots_6.png" width="25px" height="25px"> = x45<br>
                            <
img src="img/slots_3.png" width="25px" height="25px"><img src="img/slots_3.png" width="25px" height="25px"><img src="img/slots_3.png" width="25px" height="25px"> = x25    <img src="img/slots_7.png" width="25px" height="25px"><img src="img/slots_7.png" width="25px" height="25px"><img src="img/slots_7.png" width="25px" height="25px"> = x50<br>
                            <
img src="img/slots_4.png" width="25px" height="25px"><img src="img/slots_4.png" width="25px" height="25px"><img src="img/slots_4.png" width="25px" height="25px"> = x35    <img src="img/slots_8.png" width="25px" height="25px"><img src="img/slots_8.png" width="25px" height="25px"><img src="img/slots_8.png" width="25px" height="25px"> = x75<br>
                            <
img src="img/slots_9.png" width="35px" height="35px"><img src="img/slots_9.png" width="35px" height="35px"><img src="img/slots_9.png" width="35px" height="35px"><b> = x100</b><br>
                        </
center>
                    </
td>
                </
tr>
            </
table>
            </
center>
            {else}<
br><div class="alert alert-info">You are not logged inEarn free Bitcoin by <a href="register.php">opening account</a></div>{/if}
                </
Div>
                <
div class="col-md-2 text-center" style="width:135px;">    </div>
        </
div>
<
div class="clearfix"></div></div>
{include 
file='template/footer.tpl'
Habt ihr vielleicht Tipps, wie ich das ganze Übersichtlicher gestalten kann?
Oder in einem kleineren Format?

Ich lerne das programmieren erst seit kurzer Zeit und auch nur aus Spaß weil mich das ganze interessiert.

Über jede Hilfe würde ich mich freuen.

Gruß,
TramaLP
TramaLP is offline  
Old 04/22/2016, 23:00   #2


 
False's Avatar
 
elite*gold: 0
The Black Market: 243/0/0
Join Date: Apr 2011
Posts: 11,115
Received Thanks: 2,436
Ich persönlich mag Smarty nicht, selber benutze ich Twig als Template Engine.

- Wieso hast du 2 Tabellen mit je einer Row ? (wieso so gelöst o.O ?)
- Bei den Images hast du überall die selbe Größe etc. wieso nutzt du da nicht eine Class die überall dran kommt ?
- Wieso hast du dort eine Form wenn die nichts macht ?
- Deine Variablen namen sind nicht grade gut gewählt (randomnumber(1/2) etc...)- Wieso nimmst du bei der $lose Variable die 1 statt true/false ?
- Was soll der Check
PHP Code:
$_POST['play'] == $_POST['play'
wenn du zwei mal das gleiche mit einander vergleist muss es logischer weiße gleich sein.
- Du hast den Check
PHP Code:
if ($lose == 1
drin, obwohl an der Stelle es nur 1 sein kann.
- Solche Checks :
PHP Code:
if ($userdet['credit'] < $userdet['slots_bet']){
                    
$smarty->assign('cashcheck','Sorry, you got not enaught BTC to play.');
                } 
am besten immer am Anfang machen, bevor du etwas berechnest o.ä.. Das ganze spart einfach Berechnungszeit die unnötig ist weil es nachher eh nicht gebraucht wird (bei so ein Projekt wahrscheinlich eh egal, dennoch direkt angewöhnen ordentlichen Code zu schreiben.- Wenn du dennoch mal fälle hast wo du mehrere Ifs nacheinander hast und immer die gleiche Variable nutzt dann benutzt elseif(s).
Wenn in deinem Beispiel z.b. die Variable 'randomnumber ' eine 1 ist dann KÖNNEN die anderen 8 Abfragen nicht mehr treffen, daher elseif nutzen(zeit Ersparung).
- Weitere kleine Sachen die man optimieren könnte :
- Beim oberen teil könnte man den ganzen Doppelten Code, z.b. so lösen :
- Generell würde ich aber eh mit Klasen arbeiten und optimal natürlich mit Ajax so das die Seite nicht neu geladen werden muss.




Sind jetzt nur paar Sachen zu den oberen Teil, viel Glück mit dem Spiel
False is offline  

Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.