diff --git a/client/src/components/GameConfigForms/CpuMultiForm.js b/client/src/components/GameConfigForms/CpuMultiForm.js new file mode 100644 index 0000000..03892ef --- /dev/null +++ b/client/src/components/GameConfigForms/CpuMultiForm.js @@ -0,0 +1,7 @@ +export default function CpuMultiForm() { + return ( +
+

AI and stuff?

+
+ ) +} \ No newline at end of file diff --git a/client/src/components/GameConfigForms/LocalMultiForm.js b/client/src/components/GameConfigForms/LocalMultiForm.js new file mode 100644 index 0000000..90c2594 --- /dev/null +++ b/client/src/components/GameConfigForms/LocalMultiForm.js @@ -0,0 +1,76 @@ +import { useState, useEffect } from "react"; + +const formVariants = [ + <> { /* Fragment, expects to be concatenated as necessary within a
element */ } + { /* Player one and two base; index 0 */ } + + console.log(e.target.value)}> + + console.log(e.target.value)}> + + , + <> { /* Player three add on */ } + + console.log(e.target.value)}> + + , + <> + + console.log(e.target.value)}> + +]; + + + +export default function LocalMultiForm() { + const [players, setPlayers] = useState(null); + const [formVariant, setFormVariant] = useState(null); + const [playerNames, setPlayerNames] = useState({ + playerOne: null, + playerTwo: null, + playerThree: null, + playerFour: null + }); + + useEffect(() => { + switch (players) { + case "2": + setFormVariant(formVariants[0]); + break; + case "3": + setFormVariant([formVariants[0], formVariants[1]]); + break; + case "4": + setFormVariant([...formVariants]); + break; + default: + console.log("none"); + break; + } + }, [players]); + + return ( + <> + +

Number of players:

+ +
+ + setPlayers(e.target.id)}> +
+
+ + setPlayers(e.target.id)}> +
+
+ + setPlayers(e.target.id)}> +
+
+ +
+ {formVariant} +
+ + ) +} \ No newline at end of file diff --git a/client/src/components/Welcome.js b/client/src/components/Welcome.js index 2b64060..5e5a9f0 100644 --- a/client/src/components/Welcome.js +++ b/client/src/components/Welcome.js @@ -1,4 +1,37 @@ +import { useState, useRef } from "react" +import LocalMultiForm from "./GameConfigForms/LocalMultiForm"; +import CpuMultiForm from "./GameConfigForms/CpuMultiForm"; + export default function Welcome() { + const [localMulti, setLocalMulti] = useState(false); + const [cpuMulti, setCpuMulti] = useState(false); + + const [value, setValue] = useState(''); + + const localMultiRadio = useRef(); + const cpuRadio = useRef(); + + const handleChange = (e) => { + setValue(e.target.id); + + if (e.target.id === 'local-multi') { + setLocalMulti(true); + setCpuMulti(false); + } else { + setLocalMulti(false); + setCpuMulti(true); + } + } + + const handleClear = () => { + localMultiRadio.current.checked = false; + cpuRadio.current.checked = false; + + setLocalMulti(false); + setCpuMulti(false); + setValue(''); + } + return ( <>

Welcome to Splinter

@@ -6,8 +39,20 @@ export default function Welcome() {

Choose from the options below:

- +
+ + handleChange(e)}> +
+
+ + handleChange(e)}> +
+ + {localMulti ? : null} + {cpuMulti ? : null} + + ) } \ No newline at end of file