Jump to content

Recommended Posts

Posted

So I made a simple slot machine game. But I was wondering normally when you press spin you get the moving wheel what would be the best approach for that? I was thinking maybe a random gif.

<?php

$num1 = rand(1, 5);$num2 = rand(1, 5);$num3 = rand(1, 5);
$num4 = rand(1, 5);$num5 = rand(1, 5);$num6 = rand(1, 5);
$num7 = rand(1, 5);$num8 = rand(1, 5);$num9 = rand(1, 5);

$result1 = $num1.' | '.$num2.' | '.$num3;
$result2 = $num4.' | '.$num5.' | '.$num6;
$result3 = $num7.' | '.$num8.' | '.$num9;


// Read points from file
$filename = 'points.txt';
$handle = fopen($filename, 'r');
$current = fread($handle, filesize($filename));
fclose($handle);

if 
(
($num1 == $num2 && $num2 == $num3)||($num1 == $num5 && $num5 == $num9)||
($num4 == $num5 && $num5 == $num6)||($num3 == $num5 && $num5 == $num7)||
($num7 == $num8 && $num8 == $num9)
) {
$status = '<big>You are a winner!</big>';

$add_points = $current + 10;

// Add points to file
$handle = fopen($filename, 'w');
$current_points = fwrite($handle, $add_points);
fclose($handle);

} else {
$status = 'please try again!';
$handle = fopen($filename, 'w');

$add_points = $current - 2;
$current_points = fwrite($handle, $add_points);
fclose($handle);
}

?>
<html>
<head>
<title>Slot Machine Game!</title>
</head>
<body>

<center><big><?php echo $result1; ?></big></center>
<center><big><?php echo $result2; ?></big></center>
<center><big><?php echo $result3; ?></big></center>

<center><big><?php echo $status; ?></big></center>

<center><big><?php echo 'You have <strong>'.$current.'</strong> points!'; ?></big></center>
<center><a href='index.php'>spin</a></big></center>
</body>
</html>
Posted

CSS allows positioning element in x and y coords.

Element can be found by JavaScript by ID, and its coordinate set.

If you will set decreasing values, and repeat it (JavaScript timer), there will be animation.

You should also control clipping of elements (one element inside of group of elements) to hide numbers.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.