HTML 5: <!DOCTYPE html> <html> <head> <title>Slot Machine Game</title> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <div class="slot-machine-container"> <div class="slot-machine-wheels-container"> <div class="slot-machine-wheel"> <div class="slot-machine-wheel-row"> <div class="slot-machine-symbol"> <img src="images/cherry.png" alt="cherry"> </div> <div class="slot-machine-symbol"> <img src="images/lemon.png" alt="lemon"> </div> <div class="slot-machine-symbol"> <img src="images/plum.png" alt="plum"> </div> </div> <div class="slot-machine-wheel-row"> <div class="slot-machine-symbol"> <img src="images/watermelon.png" alt="watermelon"> </div> <div class="slot-machine-symbol"> <img src="images/orange.png" alt="orange"> </div> <div class="slot-machine-symbol"> <img src="images/grapes.png" alt="grapes"> </div> </div> </div> <div class="slot-machine-wheel"> <div class="slot-machine-wheel-row"> <div class="slot-machine-symbol"> <img src="images/bell.png" alt="bell"> </div> <div class="slot-machine-symbol"> <img src="images/bar.png" alt="bar"> </div> <div class="slot-machine-symbol"> <img src="images/seven.png" alt="seven"> </div> </div> <div class="slot-machine-wheel-row"> <div class="slot-machine-symbol"> <img src="images/doublebar.png" alt="doublebar"> </div> <div class="slot-machine-symbol"> <img src="images/triplebar.png" alt="triplebar"> </div> <div class="slot-machine-symbol"> <img src="images/blank.png" alt="blank"> </div> </div> </div> <div class="slot-machine-wheel"> <div class="slot-machine-wheel-row"> <div class="slot-machine-symbol"> <img src="images/cherry.png" alt="cherry"> </div> <div class="slot-machine-symbol"> <img src="images/lemon.png" alt="lemon"> </div> <div class="slot-machine-symbol"> <img src="images/plum.png" alt="plum"> </div> </div> <div class="slot-machine-wheel-row"> <div class="slot-machine-symbol"> <img src="images/watermelon.png" alt="watermelon"> </div> <div class="slot-machine-symbol"> <img src="images/orange.png" alt="orange"> </div> <div class="slot-machine-symbol"> <img src="images/grapes.png" alt="grapes"> </div> </div> </div> <div class="slot-machine-wheel"> <div class="slot-machine-wheel-row"> <div class="slot-machine-symbol"> <img src="images/bell.png" alt="bell"> </div> <div class="slot-machine-symbol"> <img src="images/bar.png" alt="bar"> </div> <div class="slot-machine-symbol"> <img src="images/seven.png" alt="seven"> </div> </div> <div class="slot-machine-wheel-row"> <div class="slot-machine-symbol"> <img src="images/doublebar.png" alt="doublebar"> </div> <div class="slot-machine-symbol"> <img src="images/triplebar.png" alt="triplebar"> </div> <div class="slot-machine-symbol"> <img src="images/blank.png" alt="blank"> </div> </div> </div> <div class="slot-machine-wheel"> <div class="slot-machine-wheel-row"> <div class="slot-machine-symbol"> <img src="images/cherry.png" alt="cherry"> </div> <div class="slot-machine-symbol"> <img src="images/lemon.png" alt="lemon"> </div> <div class="slot-machine-symbol"> <img src="images/plum.png" alt="plum"> </div> </div> <div class="slot-machine-wheel-row"> <div class="slot-machine-symbol"> <img src="images/watermelon.png" alt="watermelon"> </div> <div class="slot-machine-symbol"> <img src="images/orange.png" alt="orange"> </div> <div class="slot-machine-symbol"> <img src="images/grapes.png" alt="grapes"> </div> </div> </div> </div> <div class="slot-machine-buttons-container"> <button type="button" class="slot-machine-button" id="spin-button">Spin</button> <button type="button" class="slot-machine-button" id="reset-button">Reset</button> </div> </div> <script src="script.js"></script> </body> </html> CSS: /* Slot Machine Game */ .slot-machine-container { width: 600px; height: 400px; margin: auto; background-color: #ddd; border-radius: 10px; position: relative; } .slot-machine-wheels-container { position: absolute; top: 0; left: 0; right: 0; bottom: 0; overflow: hidden; } .slot-machine-wheel { width: 33.33%; height: 100%; float: left; position: relative; overflow: hidden; } .slot-machine-wheel-row { position: absolute; top: 0; left: 0; right: 0; bottom: 0; display: flex; flex-wrap: nowrap; transition: transform 1.5s; } .slot-machine-symbol { width: 33.33%; height: 100%; background-color: #fff; border: 1px solid #ddd; border-radius: 10px; margin: 1px; } .slot-machine-buttons-container { position: absolute; bottom: 0; left: 0; right: 0; text-align: center; padding: 10px 0; background-color: #ddd; } .slot-machine-button { width: 100px; height: 30px; background-color: #ccc; border: 0; border-radius: 5px; cursor: pointer; margin: 0 5px; } .slot-machine-button:hover { background-color: #999; } JavaScript: // Slot Machine Game // Get slot machine elements const slotMachineContainer = document.querySelector('.slot-machine-container'); const slotMachineWheelsContainer = document.querySelector('.slot-machine-wheels-container'); const slotMachineWheels = document.querySelectorAll('.slot-machine-wheel'); const slotMachineSymbols = document.querySelectorAll('.slot-machine-symbol'); const spinButton = document.querySelector('#spin-button'); const resetButton = document.querySelector('#reset-button'); // Set up initial variables let spinning = false; let wheelPositions = [0, 0, 0, 0, 0]; let wheelSpeeds = [0, 0, 0, 0, 0]; let currentPositions = [0, 0, 0, 0, 0]; // Set up event listeners spinButton.addEventListener('click', spin); resetButton.addEventListener('click', reset); // Spin function function spin() { // Check if slot machine is already spinning if (spinning) return; // Set spinning flag to true spinning = true; // Set wheel speeds wheelSpeeds = wheelSpeeds.map(() => { return Math.random() * 10 + 10; }); // Start animation loop requestAnimationFrame(animationLoop); } // Reset function function reset() { // Check if slot machine is spinning if (spinning) return; // Reset wheel positions wheelPositions = wheelPositions.map(() => 0); currentPositions = currentPositions.map(() => 0); // Update wheel positions updateWheelPositions(); } // Animation loop function animationLoop() { // Update wheel positions updateWheelPositions(); // Check if wheels have stopped spinning let finished = wheelSpeeds.every(speed => speed < 0.1); if (finished) { spinning = false; return; } // Animate requestAnimationFrame(animationLoop); } // Update wheel positions function updateWheelPositions() { // Update current positions currentPositions = currentPositions.map((position, index) => { let newPosition = position + wheelSpeeds[index]; if (newPosition >= slotMachineSymbols.length) { wheelPositions[index]++; return newPosition - slotMachineSymbols.length; } return newPosition; }); // Update wheel speeds wheelSpeeds = wheelSpeeds.map(speed => speed * 0.95); // Update wheel positions slotMachineWheels.forEach((wheel, wheelIndex) => { let position = wheelPositions[wheelIndex]; wheel.style.transform = `translateY(-${position * slotMachineSymbols[0].offsetHeight}px)`; slotMachineSymbols.forEach((symbol, symbolIndex) => { let currentPosition = currentPositions[wheelIndex]; if (symbolIndex === currentPosition) { symbol.style.opacity = 1; } else { symbol.style.opacity = 0; } }); }); } Flash: // Slot Machine Game // Create the slot machine var slotMachine:SlotMachine = new SlotMachine(); slotMachine.x = stage.stageWidth / 2; slotMachine.y = stage.stageHeight / 2; addChild(slotMachine); // Create the spin button var spinButton:Sprite = new Sprite(); spinButton.graphics.beginFill(0xcccccc, 1); spinButton.graphics.drawRoundRect(0, 0, 100, 30, 5); spinButton.graphics.endFill(); spinButton.x = slotMachine.x - spinButton.width / 2; spinButton.y = slotMachine.y + slotMachine.height / 2 + spinButton.height; addChild(spinButton); // Create the reset button var resetButton:Sprite = new Sprite(); resetButton.graphics.beginFill(0xcccccc, 1); resetButton.graphics.drawRoundRect(0, 0, 100, 30, 5); resetButton.graphics.endFill(); resetButton.x = slotMachine.x + slotMachine.width / 2 - resetButton.width / 2; resetButton.y = slotMachine.y + slotMachine.height / 2 + resetButton.height; addChild(resetButton); // Set up initial variables var spinning:Boolean = false; var wheelPositions:Array = [0, 0, 0, 0, 0]; var wheelSpeeds:Array = [0, 0, 0, 0, 0]; var currentPositions:Array = [0, 0, 0, 0, 0]; // Add event listeners spinButton.addEventListener(MouseEvent.CLICK, spin); resetButton.addEventListener(MouseEvent.CLICK, reset); // Spin function function spin(e:MouseEvent):void { // Check if slot machine is already spinning if (spinning) return; // Set spinning flag to true spinning = true; // Set wheel speeds wheelSpeeds = wheelSpeeds.map(function():Number { return Math.random() * 10 + 10; }); // Start animation loop addEventListener(Event.ENTER_FRAME, animationLoop); } // Reset function function reset(e:MouseEvent):void { // Check if slot machine is spinning if (spinning) return; // Reset wheel positions wheelPositions = wheelPositions.map(function():Number { return 0; }); currentPositions = currentPositions.map(function():Number { return 0; }); // Update wheel positions updateWheelPositions(); } // Animation loop function animationLoop(e:Event):void { // Update wheel positions updateWheelPositions(); // Check if wheels have stopped spinning var finished:Boolean = wheelSpeeds.every(function(speed:Number):Boolean { return speed < 0.1; }); if (finished) { spinning = false; removeEventListener(Event.ENTER_FRAME, animationLoop); return; } } // Update wheel positions function updateWheelPositions():void { // Update current positions currentPositions = currentPositions.map(function(position:Number, index:int):Number {
Write, Run & Share HTML code online using OneCompiler's HTML online Code editor for free. It's one of the robust, feature-rich online Code editor for HTML language, running on the latest version HTML5. Getting started with the OneCompiler's HTML compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as HTML
. You can also specify the stylesheet information in styles.css
tab and scripts information in scripts.js
tab and start coding.
HTML(Hyper Text Markup language) is the standard markup language for Web pages, was created by Berners-Lee in the year 1991. Almost every web page over internet might be using HTML.
<!DOCTYPE html>
<html>
and ends with </html>
<h1>
to <h6>
where <h1>
is the highest important heading and <h6>
is the least important sub-heading.<p>..</p>
tag.<a>
tag.
<a href="https://onecompiler.com/html">HTML online compiler</a>
<img>
tag, where src
attribute consists of image name.<button>..</button>
tag<ul>
for unordered/bullet list and <ol>
for ordered/number list, and the list items are defined in <li>
.<a href="https://onecompiler.com/html">HTML online compiler</a>
CSS(cascading style sheets) describes how HTML elements will look on the web page like color, font-style, font-size, background color etc.
Below is a sample style sheet which displays heading in green and in Candara font with padding space of 25px.
body{
padding: 25px;
}
.title {
color: #228B22;
font-family: Candara;
}
<table>
tag.<tr>
tag<th>
tag<td>
tag<caption>
tag<script>
is the tag used to write scripts in HTML<script src="script.js"></script>