Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dice Game README

This project is a simple dice game built with HTML, CSS, and JavaScript. The game allows two players to roll dice and the player with the higher roll wins.

Files:

  • index.html: The main HTML file containing the structure and content of the game.
  • style.css: The CSS file responsible for styling the game elements.
  • code.js: The JavaScript file containing the game logic.

index.html

This file contains the HTML structure for the dice game. It includes the following elements:

  1. DOCTYPE declaration: Specifies the document type as HTML5.
  2. HTML tag: Defines the root element of the HTML document.
  3. Head section:
    • Meta tags: Provide information about the document, including character encoding (UTF-8) and viewport settings for responsiveness.
    • Title tag: Sets the title of the HTML document.
    • Link tags: Link the style.css file for styling and Font Awesome for the icon library.
  4. Body section:
    • Heading: Displays the game's title.
    • Section: Contains the player's scores and dice images.
      • Div with class 'first':
        • H2 tag: Displays "Score" for the first player.
        • H2 tag with id 'p1': Displays the score for the first player (initially empty).
        • Image tag with id 'dice1': Displays the dice image for the first player.
      • Div with class 'sec': Similar structure as the first player's div, but for the second player.
    • Div with class 'b':
      • Button with id 'btn': The "Let's Play" button that triggers the game logic.
    • Script tag: Loads the code.js file containing the JavaScript logic.

style.css

This file contains the CSS styles for the game. It includes:

  1. Body styles: Sets the background color, font family, and text alignment.
  2. Heading styles: Styles the game title.
  3. Section styles: Sets the layout and styling for the player's score and dice image sections.
  4. Div styles: Applies styles to the "Score" and "Let's Play" button containers.
  5. Button styles: Styles the "Let's Play" button with a background color, border radius, padding, and hover effect.
  6. Image styles: Sets the height and padding for the dice images.

code.js

This file contains the JavaScript code for the game logic:

  1. Event listener: Attaches an event listener to the "Let's Play" button, triggering the game logic when clicked.
  2. Dice roll function: Generates random numbers between 1 and 6 to represent the dice rolls for both players.
  3. Update image function: Updates the dice images based on the generated random numbers.
  4. Determine winner function: Compares the two dice rolls and displays the winner (or a tie) in the console.

To Run the Game:

  1. Open the index.html file in a web browser.
  2. Click the "Let's Play" button to start the game.

Features:

  • Simple dice game for two players.
  • Random dice roll generation.
  • Visual display of dice images.
  • Determination and display of the winner (or tie).

Further Improvements:

  • Add sound effects for dice rolling.
  • Implement a scorekeeping system for multiple rounds.
  • Add a visual animation for dice rolling.
  • Create a user interface for player names and scores.
  • Integrate the game with a server for multiplayer functionality.

About

A fun dice-rolling web app made using HTML, CSS, and JavaScript. Generates a random number between 1–6 with animation and updates dice images accordingly. Great for games and practice projects.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages