Username:
Password:
Remember me:
Register

Back to forum: Web Programming (HTML, JS, CSS, PHP, MySQL)


Search forums via Google


1 Users appreciate this thread.

Simple PHP slots
Started by klubadmin
(2012-11-09 02:46:18)
klubadmin (2012-11-09 02:46:18)
You could call this a tutorial, but it's really more of a handy free example script. Here, I'll show an easy and simple way to make a basic game of slots in PHP. Warning: even though the slots are basic, the php isn't necessarily basic too. I'll add comments throughout to explain sections, but not individual codes.

Here's the code:
Source Code
<?php //pick 3 random numbers 1-9 $first=rand(1,9); $second=rand(1,9); $third=rand(1,9); //display them echo "<h1>" .$first. " | " .$second. " | " .$third. "</h1>"; //if they all match if($first == $second && $second == $third){ //jackpot echo "You won stuff! "; }else{ //if they don't all match, check for just two matching if($first == $second){ //first-second match echo "First two match! You win a bit of stuff."; } if($second == $third){ //second-third match echo "Last two match! You win a bit of stuff."; } if($first == $third){ //first-third match echo "First and last match! You win a bit of stuff."; } //or you failed completely if($first != $second && $second != $third && $first != $third){ //none match echo "You failed. You lose some stuff."; } } echo "<h3>Refresh to try again.</h3>"; >?


Hopefully you find this useful/interesting/helpful and maybe you even learned something new. If you want to add on to the script, simply read through the comments to find where you should place things. I don't require you to give credit if you use this script, though a little pointer to http://klub.t15.org somewhere is always nice.

Disclaimer: This script should be fully functional, though it has not been tested.
socialcu.be
3dsklub.cf

Like what I said? +respect
>Official Trinate Spriter<
(Capt.)Orb (2012-11-12 16:13:40)
looks cool! but how could it work without a html input tag?

BTW <h3> is for headers not for text sizing use
Source Code
<font size='size'>Stuff</font>



This post has been edited one or more times, the last time was:
2012-11-12 16:17:32

Aviation fact: The a380 is the largest commerical aircraft in service!

Go to Splashiverse! Splashiverse
klubadmin (2012-11-12 20:05:54)
Actually, the font tag is depreciated. You should use:
Source Code
<span style='font-size:16px'>Text</span>


And it's just an example. You can use whatever tags you want.
socialcu.be
3dsklub.cf

Like what I said? +respect
>Official Trinate Spriter<
angelrulez7 (2012-11-12 20:45:36)
You messed up at the end. (>?)
a
angelrulez7 (2012-11-12 20:46:06)
[code=Fixed *php]
<?php
//pick 3 random numbers 1-9

$first=rand(1,9);
$second=rand(1,9);
$third=rand(1,9);

//display them

echo "<h1>" .$first. " | " .$second. " | " .$third. "</h1>";

//if they all match

if($first == $second && $second == $third){

//jackpot

echo "You won stuff! ";

}else{

//if they don't all match, check for just two matching

if($first == $second){

//first-second match

echo "First two match! You win a bit of stuff.";

}
if($second == $third){

//second-third match

echo "Last two match! You win a bit of stuff.";

}
if($first == $third){

//first-third match

echo "First and last match! You win a bit of stuff.";

}

//or you failed completely

if($first != $second && $second != $third && $first != $third){

//none match

echo "You failed. You lose some stuff.";

}
}

echo "<h3>Refresh to try again.</h3>";
?>[/code]

Fixed.

This post has been edited one or more times, the last time was:
2013-10-20 20:11:44

a
angelrulez7 (2012-11-12 21:10:20)
[IMG]http://i47.tinypic.com/2uhs1uu.png[/IMG]

I used your script. ._.
a
klubadmin (2012-11-12 22:35:56)
Lol. @the picture

And wow. Should have seen that typo.
socialcu.be
3dsklub.cf

Like what I said? +respect
>Official Trinate Spriter<
klubadmin (2012-11-14 19:41:56)
@dimitris Actually, no you don't.

1) I'm not even sure <?session start , php ?> is a real code, but if it is, it's definitely not required.

2) This is a php snippet, not an entire web page. Also, even if it was, most browsers wouldn't care and would display it correctly anyways (though you always should include proper formatting when possible).
socialcu.be
3dsklub.cf

Like what I said? +respect
>Official Trinate Spriter<
(Capt.)Orb (2012-11-14 20:40:37)
it's SESSION_start();
but as klubadmin said,it's not needed....
Aviation fact: The a380 is the largest commerical aircraft in service!

Go to Splashiverse! Splashiverse
klubadmin (2012-11-19 20:40:50)
1) Fapka.mobi doesn't exist.

2) If you meant wapka.mobi, it's terrible and you shouldn't be using it anyways if you're even slightly serious about being a web dev, so nobody cares.
socialcu.be
3dsklub.cf

Like what I said? +respect
>Official Trinate Spriter<
angelrulez7 (2012-11-23 21:25:31)
Wapka doesn't support php.
a
angelrulez7 (2012-11-24 23:37:57)
Dimitris, it's just you don't know how to work it. -.-
a
 

Log in to submit a comment

This topic's ID: 35878

Back to forum: Web Programming (HTML, JS, CSS, PHP, MySQL)




Total registered users: 8321
New registered users today: 7
Newest registered user: ElegantVulpes

©  Copyright 2026 3DSPlaza. All Rights Reserved