Skip to content

Commit

Permalink
make the contract
Browse files Browse the repository at this point in the history
  • Loading branch information
kamalbuilds committed Aug 12, 2024
1 parent 6a45bde commit 51f20ac
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# Zk card game
# Zk Multiplayer card game
27 changes: 27 additions & 0 deletions frontend/app/leaderboard/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { useState, useEffect } from 'react';

export default function Leaderboard() {
const [players, setPlayers] = useState([]);

useEffect(() => {
// Fetch player statistics from server
setPlayers([
{ name: 'Alice', wins: 10, losses: 2 },
{ name: 'Bob', wins: 8, losses: 4 },
// ...more players
]);
}, []);

return (
<div>
<h1>Leaderboard</h1>
<ul>
{players.map((player) => (
<li key={player.name}>
{player.name} - Wins: {player.wins}, Losses: {player.losses}
</li>
))}
</ul>
</div>
);
}
Binary file added smartcontract/bun.lockb
Binary file not shown.
11 changes: 6 additions & 5 deletions smartcontract/contracts/ZkShuffleGame.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

import "@zkshuffle/sdk/contracts/ZkShuffle.sol";
import "@zk-shuffle/contracts/contracts/shuffle/IShuffleStateManager.sol";
import "@zk-shuffle/contracts/contracts/shuffle/IBaseGame.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract ZkShuffleGame is Ownable {

enum GameState { WaitingForPlayers, Shuffling, Dealing, InProgress, Finished }

struct Player {
Expand All @@ -14,7 +16,6 @@ contract ZkShuffleGame is Ownable {
}

GameState public gameState;
ZkShuffle public zkShuffle;
Player[] public players;
uint256 public maxPlayers;
uint256 public pot;
Expand All @@ -24,9 +25,9 @@ contract ZkShuffleGame is Ownable {
event PlayerHandDealt(address indexed player, uint256 hand);
event GameEnded(address indexed winner, uint256 pot);

constructor(uint256 _maxPlayers, address _zkShuffleAddress) {
IShuffleStateManager public zkShuffle;
constructor(uint256 _maxPlayers, address owner) Ownable(owner) {
maxPlayers = _maxPlayers;
zkShuffle = ZkShuffle(_zkShuffleAddress);
gameState = GameState.WaitingForPlayers;
}

Expand All @@ -52,7 +53,7 @@ contract ZkShuffleGame is Ownable {
function startGame() internal {
gameState = GameState.Shuffling;
emit GameStarted();
zkShuffle.shuffleDeck();
zkShuffle.shuffle();
}

function dealHands() external onlyOwner {
Expand Down
13 changes: 12 additions & 1 deletion smartcontract/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@
"description": "",
"devDependencies": {
"@nomicfoundation/hardhat-toolbox": "^5.0.0",
"hardhat": "^2.22.6"
"hardhat": "^2.22.6",
"@semaphore-protocol/contracts": "^2.6.1",
"@zk-shuffle/circuits": "1.0.0",
"@zk-shuffle/jssdk": "1.0.0",
"@zk-shuffle/proof": "1.0.0",
"circomlibjs": "^0.1.7",
"node-pandoc": "^0.3.0",
"snarkjs": "^0.7.0"
},
"dependencies": {
"@openzeppelin/contracts": "^5.0.2",
"@zk-shuffle/contracts": "^1.0.1"
}
}

0 comments on commit 51f20ac

Please sign in to comment.