diff --git a/src/components/FinalPoem.css b/src/components/FinalPoem.css index 67dda943..c9c2f7df 100644 --- a/src/components/FinalPoem.css +++ b/src/components/FinalPoem.css @@ -13,7 +13,7 @@ } .FinalPoem__reveal-btn:hover { - background-color: tomato; + background-color: rgb(54, 236, 197); } .FinalPoem__poem { diff --git a/src/components/FinalPoem.js b/src/components/FinalPoem.js index d516184e..61811e49 100644 --- a/src/components/FinalPoem.js +++ b/src/components/FinalPoem.js @@ -1,20 +1,53 @@ import React from 'react'; import './FinalPoem.css'; +import PropTypes from 'prop-types'; const FinalPoem = (props) => { + console.log(props) + + // Each submission in the final poem section on a different line or paragraph. + const showingPoemLines = props.poems.map((poem, i) => { + return ( +

{poem}

+ ) + }); + + // It shows each part depends on playing state. + return (
-
-

Final Poem

+ { + // props.playing || === !props.playing + // It shows final poem if playing is false. + props.playing || ( +
+

Final Poem

+ {/* See all of the submissions of poetry lines in the section named "Final Poem". */} + {showingPoemLines} +
+ ) + } + { + // It shows the button if playing is true. + // Means the game is not over. + props.playing && ( +
+ {/* A button to click to finalize the poem and reveal the entire final poem, + it does not show the previous lines until the poem is finished. */} + +
+ ) + } -
- -
- -
); } +FinalPoem.propTypes = { + poems: PropTypes.array.isRequired, + playing: PropTypes.bool.isRequired, + onGameOverCallback: PropTypes.func.isRequired +}; + export default FinalPoem; diff --git a/src/components/Game.css b/src/components/Game.css index 8ff58e42..b85331d2 100644 --- a/src/components/Game.css +++ b/src/components/Game.css @@ -2,3 +2,11 @@ text-align: center; font-style: italic; } +.btn { + display: flex; + justify-content: space-around; +} + +h2 { + padding: 20px; +} diff --git a/src/components/Game.js b/src/components/Game.js index ad27105b..3589fc15 100644 --- a/src/components/Game.js +++ b/src/components/Game.js @@ -4,7 +4,17 @@ import PlayerSubmissionForm from './PlayerSubmissionForm'; import FinalPoem from './FinalPoem'; import RecentSubmission from './RecentSubmission'; + const Game = () => { + + // data of form submission, so that the Game component keeps track of all of the submissions. + + const [poems, setPoemPieces] = useState([]); + // SetPlaying false when the game is over. + const [playing, setPlaying] = useState(true); + // State to add up 1 to the next player. + const [player, setPlayer] = useState(1) + const exampleFormat = FIELDS.map((field) => { if (field.key) { return field.placeholder; @@ -13,24 +23,63 @@ const Game = () => { } }).join(" "); + // Function to start over the game! Anytime + const resetGame = () => { + setPoemPieces([]); + setPlaying(true); + setPlayer(1); + } + + + // CallBack func to get the info from the form. + const addPoemPiece = (poem) => { + + const newPoemPiece = [...poems]; + console.log(poem) + + newPoemPiece.push(poem) + setPlayer(player + 1) + setPoemPieces(newPoemPiece); + } + + const gameOver = () => { + setPlaying(false); + } + return (

Game

+
+ +

Each player should take turns filling out and submitting the form below. Each turn should be done individually and in secret! Take inspiration from the revealed recent submission. When all players are finished, click the final button on the bottom to reveal the entire poem.

Please follow the following format for your poetry submission:

- { exampleFormat } + {exampleFormat}

+ + - - - - - + +
); } @@ -66,4 +115,5 @@ const FIELDS = [ ".", ]; + export default Game; diff --git a/src/components/PlayerSubmissionForm.css b/src/components/PlayerSubmissionForm.css index 7cded5d9..707d4b9c 100644 --- a/src/components/PlayerSubmissionForm.css +++ b/src/components/PlayerSubmissionForm.css @@ -28,7 +28,7 @@ } .PlayerSubmissionForm__submit-btn:hover { - background-color: tomato; + background-color: rgb(54, 236, 197); } .PlayerSubmissionFormt__input--invalid { @@ -38,3 +38,11 @@ .PlayerSubmissionForm__input--invalid::placeholder { color: black; } + +.empty { + background-color: lightpink; +} + +h3 { + text-align: center; +} \ No newline at end of file diff --git a/src/components/PlayerSubmissionForm.js b/src/components/PlayerSubmissionForm.js index ba19e6ef..a4051ce4 100644 --- a/src/components/PlayerSubmissionForm.js +++ b/src/components/PlayerSubmissionForm.js @@ -1,31 +1,120 @@ import React, { useState } from 'react'; import './PlayerSubmissionForm.css'; +import PropTypes from 'prop-types'; -const PlayerSubmissionForm = () => { - return ( -
-

Player Submission Form for Player #{ }

+const CLEARINPUTS = { + adj1: '', + noun1: '', + adv: '', + verb: '', + adj2: '', + noun2: '' +}; + +const PlayerSubmissionForm = (props) => { + + // State to handle the pieces of poems. + // CLEARINPUTS = use constant to set the input to empty strings. + const [poemPiece, setPoemPiece] = useState(CLEARINPUTS); + console.log(props); + const onChange = (event) => { + const newPoem = { + ...poemPiece + } -
+ console.log(newPoem); + newPoem[event.target.name] = event.target.value; + setPoemPiece(newPoem); + } -
+ const onFormSubmit = (event) => { + event.preventDefault(); + console.log("submitting form") + if (poemPiece.adj1 !== '' && + poemPiece.noun1 !== '' && + poemPiece.adv !== '' && + poemPiece.verb !== '' && + poemPiece.adj2 !== '' && + poemPiece.noun2 !== '') { + // Format the poem once the submit event happens. + // One line compact everything before to send it to game Component. + const formatPoem = [ + "The", + poemPiece.adj1, + poemPiece.noun1, + poemPiece.adv, + poemPiece.verb, + "the", + poemPiece.adj2, + poemPiece.noun2, + "." + ].join(" ") - { - // Put your form inputs here... We've put in one below as an example - } - + console.log(formatPoem) + // send that data back up to app. + props.onFormSubmitCallback(formatPoem) + // reseting form with no text in the input elements after the first player submitted + setPoemPiece(CLEARINPUTS); + } + }; -
+ // Getting the fields from the parent (Game) Props.field object. + const generateFormComponents = props.fields.map((field, i) => { + // Initialize the place holder value to empty string. + const valueHolder = poemPiece[field.key]; + if (field.key) { + return ( + + ); + } else { + return field; + } + }); -
- -
-
+ // {/* Displaying the number of the current player. props.currentPlayer from Game.js */} + return ( +
+ {/* Hide the Player Submission Form after the final poem has been revealed. */} + { + props.playing && + ( +
+

Player Submission Form for Player #{props.currentPlayer}

+
+
+ {/* Invoking the function to generate dynamicly the Input form. */} + {generateFormComponents} +
+
+ +
+
+
+ ) + }
); } +PlayerSubmissionForm.propTypes = { + currentPlayer: PropTypes.number.isRequired, + fields: PropTypes.array.isRequired, + onFormSubmitCallback: PropTypes.func.isRequired, + playing: PropTypes.bool.isRequired, +}; + export default PlayerSubmissionForm; diff --git a/src/components/RecentSubmission.js b/src/components/RecentSubmission.js index 663da34b..efca69e9 100644 --- a/src/components/RecentSubmission.js +++ b/src/components/RecentSubmission.js @@ -1,13 +1,43 @@ import React from 'react'; import './RecentSubmission.css'; +import PropTypes from 'prop-types'; const RecentSubmission = (props) => { + + const showingLastPoemePiece = () => { + const lastPoemIdx = props.poems.length - 1 + return ( +

{props.poems[lastPoemIdx]}

+ ) + }; + + // It returns false if there is not poems within the array. + const shouldDisplay = () => { + if (props.poems.length === 0) { + return false; + } else { + return props.playing; + } + } + return ( -
-

The Most Recent Submission

-

{ }

-
+ // If the result of sholdDisplay is true -> Display the Most Recent. + // React does not render anything if the return of our func is false. + shouldDisplay() && ( +
+ {/* See only the most recent submission of poetry in the section */} +

The Most Recent Submission

+ {showingLastPoemePiece()} +

{}

+
+ ) ); } +RecentSubmission.propTypes = { + poems: PropTypes.array.isRequired, + playing: PropTypes.bool.isRequired, +}; + + export default RecentSubmission;