Skip to content

Commit 58d0217

Browse files
committed
Add Backgammon board visualization with contract integration
1 parent 53fddc7 commit 58d0217

File tree

9 files changed

+308
-239
lines changed

9 files changed

+308
-239
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.30;
3+
4+
contract Backgammon {
5+
uint256[24] public white;
6+
uint256[24] public black;
7+
8+
constructor() {
9+
// black: [0,0,0,0,0,5,0,3,0,0,0,0,5,0,0,0,0,0,0,0,0,0,0,2]
10+
black[5] = 5;
11+
black[7] = 3;
12+
black[12] = 5;
13+
black[23] = 2;
14+
15+
// white: [2,0,0,0,0,0,0,0,0,0,0,5,0,0,0,0,3,0,5,0,0,0,0,0]
16+
white[0] = 2;
17+
white[11] = 5;
18+
white[16] = 3;
19+
white[18] = 5;
20+
}
21+
}

packages/foundry/contracts/YourContract.sol

Lines changed: 0 additions & 79 deletions
This file was deleted.

packages/foundry/script/Deploy.s.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
pragma solidity ^0.8.19;
33

44
import "./DeployHelpers.s.sol";
5-
import { DeployYourContract } from "./DeployYourContract.s.sol";
5+
import {DeployBackgammon} from "./DeployBackgammon.s.sol";
66

77
/**
88
* @notice Main deployment script for all contracts
@@ -15,8 +15,8 @@ contract DeployScript is ScaffoldETHDeploy {
1515
// Deploys all your contracts sequentially
1616
// Add new deployments here when needed
1717

18-
DeployYourContract deployYourContract = new DeployYourContract();
19-
deployYourContract.run();
18+
DeployBackgammon deployBackgammon = new DeployBackgammon();
19+
deployBackgammon.run();
2020

2121
// Deploy another contract
2222
// DeployMyContract myContract = new DeployMyContract();

packages/foundry/script/DeployYourContract.s.sol renamed to packages/foundry/script/DeployBackgammon.s.sol

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
pragma solidity ^0.8.19;
33

44
import "./DeployHelpers.s.sol";
5-
import "../contracts/YourContract.sol";
5+
import "../contracts/Backgammon.sol";
66

77
/**
8-
* @notice Deploy script for YourContract contract
8+
* @notice Deploy script for Backgammon contract
99
* @dev Inherits ScaffoldETHDeploy which:
1010
* - Includes forge-std/Script.sol for deployment
1111
* - Includes ScaffoldEthDeployerRunner modifier
1212
* - Provides `deployer` variable
1313
* Example:
14-
* yarn deploy --file DeployYourContract.s.sol # local anvil chain
15-
* yarn deploy --file DeployYourContract.s.sol --network optimism # live network (requires keystore)
14+
* yarn deploy --file DeployBackgammon.s.sol # local anvil chain
15+
* yarn deploy --file DeployBackgammon.s.sol --network optimism # live network (requires keystore)
1616
*/
17-
contract DeployYourContract is ScaffoldETHDeploy {
17+
contract DeployBackgammon is ScaffoldETHDeploy {
1818
/**
1919
* @dev Deployer setup based on `ETH_KEYSTORE_ACCOUNT` in `.env`:
2020
* - "scaffold-eth-default": Uses Anvil's account #9 (0xa0Ee7A142d267C1f36714E4a8F75612F20a79720), no password prompt
@@ -25,6 +25,7 @@ contract DeployYourContract is ScaffoldETHDeploy {
2525
* - Export contract addresses & ABIs to `nextjs` packages
2626
*/
2727
function run() external ScaffoldEthDeployerRunner {
28-
new YourContract(deployer);
28+
Backgammon backgammon = new Backgammon();
29+
deployments.push(Deployment("Backgammon", address(backgammon)));
2930
}
3031
}

packages/foundry/test/YourContract.t.sol

Lines changed: 0 additions & 17 deletions
This file was deleted.

packages/nextjs/app/page.tsx

Lines changed: 3 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,14 @@
11
"use client";
22

3-
import Link from "next/link";
4-
import { Address } from "@scaffold-ui/components";
53
import type { NextPage } from "next";
6-
import { hardhat } from "viem/chains";
7-
import { useAccount } from "wagmi";
8-
import { BugAntIcon, MagnifyingGlassIcon } from "@heroicons/react/24/outline";
9-
import { useTargetNetwork } from "~~/hooks/scaffold-eth";
4+
import { BackgammonBoard } from "~~/components/BackgammonBoard";
105

116
const Home: NextPage = () => {
12-
const { address: connectedAddress } = useAccount();
13-
const { targetNetwork } = useTargetNetwork();
14-
157
return (
168
<>
179
<div className="flex items-center flex-col grow pt-10">
18-
<div className="px-5">
19-
<h1 className="text-center">
20-
<span className="block text-2xl mb-2">Welcome to</span>
21-
<span className="block text-4xl font-bold">Scaffold-ETH 2</span>
22-
</h1>
23-
<div className="flex justify-center items-center space-x-2 flex-col">
24-
<p className="my-2 font-medium">Connected Address:</p>
25-
<Address
26-
address={connectedAddress}
27-
chain={targetNetwork}
28-
blockExplorerAddressLink={
29-
targetNetwork.id === hardhat.id ? `/blockexplorer/address/${connectedAddress}` : undefined
30-
}
31-
/>
32-
</div>
33-
34-
<p className="text-center text-lg">
35-
Get started by editing{" "}
36-
<code className="italic bg-base-300 text-base font-bold max-w-full break-words break-all inline-block">
37-
packages/nextjs/app/page.tsx
38-
</code>
39-
</p>
40-
<p className="text-center text-lg">
41-
Edit your smart contract{" "}
42-
<code className="italic bg-base-300 text-base font-bold max-w-full break-words break-all inline-block">
43-
YourContract.sol
44-
</code>{" "}
45-
in{" "}
46-
<code className="italic bg-base-300 text-base font-bold max-w-full break-words break-all inline-block">
47-
packages/hardhat/contracts
48-
</code>
49-
</p>
50-
</div>
51-
52-
<div className="grow bg-base-300 w-full mt-16 px-8 py-12">
53-
<div className="flex justify-center items-center gap-12 flex-col md:flex-row">
54-
<div className="flex flex-col bg-base-100 px-10 py-10 text-center items-center max-w-xs rounded-3xl">
55-
<BugAntIcon className="h-8 w-8 fill-secondary" />
56-
<p>
57-
Tinker with your smart contract using the{" "}
58-
<Link href="/debug" passHref className="link">
59-
Debug Contracts
60-
</Link>{" "}
61-
tab.
62-
</p>
63-
</div>
64-
<div className="flex flex-col bg-base-100 px-10 py-10 text-center items-center max-w-xs rounded-3xl">
65-
<MagnifyingGlassIcon className="h-8 w-8 fill-secondary" />
66-
<p>
67-
Explore your local transactions with the{" "}
68-
<Link href="/blockexplorer" passHref className="link">
69-
Block Explorer
70-
</Link>{" "}
71-
tab.
72-
</p>
73-
</div>
74-
</div>
10+
<div className="px-5 w-auto rounded-lg">
11+
<BackgammonBoard />
7512
</div>
7613
</div>
7714
</>

0 commit comments

Comments
 (0)