Guessnum is a decentralized application (dApp) for a number guessing game, developed as a part of the FT5004 course at the National University of Singapore (NUS). The project utilizes Next.js and Solidity, with a frontend styled using TailwindCSS and Shadcn. Web3 functionalities are implemented using RainbowKit, wagmi, and viem. It runs on Klaytn Baobab Testnet only.
The dApp demonstrates the use of blockchain in gaming, specifically for a number guessing game mechanics. It is designed for educational purposes to showcase the application of blockchain technology.
Ensure Node.js and npm are installed.
-
Clone the repository and navigate into the directory:
git clone https://github.com/CUHKfreshman/guessnum.git cd guessnum
-
Install dependencies:
npm install
Launch the development server:
npm run dev
Access the dApp via http://localhost:3000
.
joinGame()
allows users to join an existing game.startGame()
initiates the game after required checks and generates a winning number.createGame(uint roomNumber, address player1, address player2, uint winningNumber1, uint winningNumber2)
sets up a new game instance.checkGameStatus()
provides information on the current round, turn, game end status,and numbers attempted.guessNumber(uint guess)
allows players to submit their guesses.resetGame(uint gameNumber)
resets a specific game.calculateWinnings(uint256 gameNumber)
determines the fees and prizes based on player's guess in each stage of a game.quitGame()
allows players to exit the game.settleGame()
transfers tokens from the contract to the respective players and host.findAvailableRoom()
search for an available room, or create a new room if no room is available.isGameTimeout(uint256 gameID)
to ensure games do not exceed the set time limit of 10 minutes per game (2 rounds).remainingTime(uint256 gameID)
to check the time left in the current game.
This project is intended solely for educational use within FT5004 at National University of Singapore.