Add prettier, board renders to something reasonable

This commit is contained in:
fry 2022-03-06 10:45:35 -05:00
parent 74ee26c8d6
commit 75431afaa9
7 changed files with 89 additions and 15 deletions

5
ui/.prettierrc Normal file
View File

@ -0,0 +1,5 @@
{
"tabWidth": 2,
"useTabs": false,
"semi": true
}

View File

@ -1,7 +1,25 @@
import React from 'react'
import React from "react";
import { Cell } from "./types";
import styles from "../styles/board.module.css";
const Board = () => (
<input/>
)
interface BoardProps {
cells: Cell[];
cellWidth: number;
}
export default Board;
const Board = (props: BoardProps) => {
return (
<div
className={styles.gridContainer}
style={{
gridTemplateColumns: `repeat(${props.cellWidth}, 1fr)`,
}}
>
{props.cells.map((cell) => (
<div className={styles.gridCell}>{cell.terrainType}</div>
))}
</div>
);
};
export default Board;

30
ui/components/game.tsx Normal file
View File

@ -0,0 +1,30 @@
import React from "react";
import Board from "./board";
const Game = () => {
return (
<Board
cellWidth={4}
cells={[
{ terrainType: 1 },
{ terrainType: 1 },
{ terrainType: 1 },
{ terrainType: 1 },
{ terrainType: 1 },
{ terrainType: 1 },
{ terrainType: 1 },
{ terrainType: 1 },
{ terrainType: 1 },
{ terrainType: 1 },
{ terrainType: 1 },
{ terrainType: 1 },
{ terrainType: 1 },
{ terrainType: 1 },
{ terrainType: 1 },
{ terrainType: 1 },
]}
/>
);
};
export default Game;

9
ui/components/types.ts Normal file
View File

@ -0,0 +1,9 @@
export interface Piece {
rank: number;
owner: number;
}
export interface Cell {
piece?: Piece;
terrainType: number;
}

View File

@ -1,19 +1,19 @@
import type { NextPage } from 'next'
import Head from 'next/head'
import Image from 'next/image'
import Board from '../components/board'
import styles from '../styles/Home.module.css'
import type { NextPage } from "next";
import Head from "next/head";
import Image from "next/image";
import Game from "../components/game";
import styles from "../styles/BoardPage.module.css";
const Home: NextPage = () => (
<>
<div className={styles.main}>
<Head>
<title>Free Go Game</title>
<link rel="icon" href="/favicon.ico" />
</Head>
<main>
<Board />
<Game />
</main>
</>
)
</div>
);
export default Home
export default Home;

View File

@ -0,0 +1,4 @@
.main {
max-width: 900px;
margin: auto;
}

View File

@ -0,0 +1,8 @@
.gridContainer {
display: grid;
}
.gridCell {
border: 1px solid black;
padding-top: 91%; /* 100% is supposed to be 1:1 aspect ratio but it doesn't look like it */
}