Skip to content

Commit

Permalink
Merge pull request #21 from obscuronet/pedro/guessing_game_v2
Browse files Browse the repository at this point in the history
Guessing Game v2
  • Loading branch information
otherview authored Oct 26, 2023
2 parents 6c3a72d + bd19a2b commit 5e21585
Show file tree
Hide file tree
Showing 32 changed files with 12,227 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/deploy-guessing-game-v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Deploy Number Guessing Game v2

on:
workflow_dispatch:
inputs:
address:
description: 'Contract Address'
required: true

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: '18'

- name: Install dependencies
run: npm install
working-directory: ./guessing-game-v2

- name: Write Address to JSON
run: |
echo '{"address": "${{ github.event.inputs.address }}"}' > ./guessing-game-v2/src/assets/contract/address.json
- name: Build application
run: npm run build
working-directory: ./guessing-game-v2

- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./guessing-game-v2/dist
destination_dir: ./guessing-game-v2
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
**/number-guessing-game/deployments
**/number-guessing-game/typechain-types

.idea

14 changes: 14 additions & 0 deletions guessing-game-v2/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* eslint-env node */
require('@rushstack/eslint-patch/modern-module-resolution')

module.exports = {
root: true,
'extends': [
'plugin:vue/vue3-essential',
'eslint:recommended',
'@vue/eslint-config-prettier/skip-formatting'
],
parserOptions: {
ecmaVersion: 'latest'
}
}
40 changes: 40 additions & 0 deletions guessing-game-v2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
.DS_Store
dist
dist-ssr
coverage
*.local

/cypress/videos/
/cypress/screenshots/

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

node_modules
.env
coverage
coverage.json
typechain
typechain-types

# Hardhat files
cache
artifacts

8 changes: 8 additions & 0 deletions guessing-game-v2/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "https://json.schemastore.org/prettierrc",
"semi": false,
"tabWidth": 2,
"singleQuote": true,
"printWidth": 100,
"trailingComma": "none"
}
35 changes: 35 additions & 0 deletions guessing-game-v2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# guessing-game-v2

This template should help get you started developing with Vue 3 in Vite.

## Recommended IDE Setup

[VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur) + [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin).

## Customize configuration

See [Vite Configuration Reference](https://vitejs.dev/config/).

## Project Setup

```sh
npm install
```

### Compile and Hot-Reload for Development

```sh
npm run dev
```

### Compile and Minify for Production

```sh
npm run build
```

### Lint with [ESLint](https://eslint.org/)

```sh
npm run lint
```
46 changes: 46 additions & 0 deletions guessing-game-v2/contracts/GuessingGame.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract GuessingGame {

uint256 private secretNumber;
address private owner;
uint256 public totalGuesses;
uint256 public constant GUESS_FEE = 443e15; // 0.443 ETH

event Guessed(address indexed user, uint256 guessedNumber, bool success);

modifier onlyOwner() {
require(msg.sender == owner, "Only the owner can call this function");
_;
}

constructor(uint256 _secretNumber) {
require(_secretNumber > 0 && _secretNumber <= 1000, "Secret number should be between 1 and 1000");
secretNumber = _secretNumber;
owner = msg.sender;
}

function guess(uint256 _number) external payable {
require(_number > 0 && _number <= 1000, "Secret number should be between 1 and 1000");
require(msg.value == GUESS_FEE, "You need to send 0.443 ETH to make a guess");
totalGuesses += 1;

if (_number == secretNumber) {
// If the guess is correct, transfer all the contract balance to the user
payable(msg.sender).transfer(address(this).balance);
emit Guessed(msg.sender, _number, true);
} else {
emit Guessed(msg.sender, _number, false);
}
}

function setSecretNumber(uint256 _newSecret) external onlyOwner {
require(_newSecret > 0 && _newSecret <= 1000, "Secret number should be between 1 and 1000");
secretNumber = _newSecret;
}

function getContractBalance() external view returns (uint256) {
return address(this).balance;
}
}
8 changes: 8 additions & 0 deletions guessing-game-v2/hardhat.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
solidity: "0.8.19",
paths: {
sources: "./contracts",
artifacts: "./src/assets/contract/artifacts"
},
};
13 changes: 13 additions & 0 deletions guessing-game-v2/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="icon" href="/src/assets/icons/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Obscuro's Guessing Game</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>
Loading

0 comments on commit 5e21585

Please sign in to comment.