DEV Community

Cover image for PIG GAME πŸ—
Sanjay Kumar Sah
Sanjay Kumar Sah

Posted on

PIG GAME πŸ—

This is a submission for the Web Game Challenge, Build a Game: Alien Edition

What I Built

I built an exciting web game called PIG GAME! It's a simple dice game first described in print by John Scarne in 1945. The game is easy to pick up but requires some strategy and luck to win. I implemented it as a fun exercise to practice HTML, CSS, and JavaScript.

Tech Stack πŸ› οΈ

  • HTML5: Structuring the basic elements of the game.
  • CSS3: Styling the game interface for an engaging user experience.
  • JavaScript (ES6): Handling the game logic, dice rolls, and user interactions.

The project was a great opportunity to refine my DOM manipulation skills and event handling in JavaScript.

RULESπŸ“ƒTO PLAY GAME

Each turn, a player repeatedly rolls a die until either a 1 is rolled or the player decides to β€œhold”:

  • If the player rolls a 1, they score nothing and it becomes the next player's turn.
  • If the player rolls any other number, it is added to their turn total and the player's turn continues.
  • If a player chooses to β€œhold”, their turn total is added to their score, becoming the next player's turn.
  • Variation we used, if you roll snake eyes (both 1's), your total score from past rounds is reset to 0.

The first player to score 100 or more points wins.

Features ✨

  • Dynamic Score Updates: The score and dice rolls update live as the player plays.
  • Winning Screen: A celebratory message displays when a player wins the game.
  • Snake Eyes Reset Rule: Rolling double ones adds an element of risk, making the game more challenging.

Demo

You can play the Pig game here!

Journey

I built this game using HTML, CSS, and JavaScript as part of a project to enhance my front-end development skills. One of the main challenges was figuring out the logic for handling different game states, such as when the player should roll when they should hold, and how to implement the snake eyes rule.

Additionally, I spent time optimizing the user interface to be responsive and intuitive, ensuring players could enjoy the game on different devices.

This project helped me to improve my understanding of event-driven programming in JavaScript and how to manage state changes in a small game application.

Top comments (0)