Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Difficulty options #28

Merged
merged 2 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,9 @@ export default function Game() {
<ClipboardAnimation peerId={peerId} />
{peerConnection &&
(isItMyTurn(playerSymbol) ? (
<p>{`Your (${playerSymbol}) turn`}</p>
<p style={{textAlign: "center"}}>{`Your (${playerSymbol}) turn`}</p>
) : (
<p>{`Opponent's (${opponentSymbol}) turn`}</p>
<p style={{textAlign: "center"}}>{`Opponent's (${opponentSymbol}) turn`}</p>
))}
{!peerConnection && (
<p
Expand Down
19 changes: 15 additions & 4 deletions src/startpage/startpage.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default function StartScreen({ onStart }) {
const [onlineModeSelected, setOnlineModeSelected] = useState(false);
const [joinModeSelected, setJoinModeSelected] = useState(false);
const [joinId, setJoinId] = useState("");
const [selectedDifficulty, setSelectedDifficulty] = useState(6);

function createMultiplayerGame() {
const props = new GameStartProperties(false, null, null, null);
Expand All @@ -30,7 +31,7 @@ export default function StartScreen({ onStart }) {
return randomPlayer === 0 ? "X" : "O";
}

function createAiGame(playerSymbol = randomSymbol(), difficulty = 6) {
function createAiGame(playerSymbol, difficulty) {
const props = new GameStartProperties(
true,
playerSymbol,
Expand Down Expand Up @@ -58,9 +59,19 @@ export default function StartScreen({ onStart }) {
{aiModeSelected && (
<>
<div className={styles.horizontalButtonsContainer}>
<button onClick={() => createAiGame("X")}>Play first (X)</button>
<button onClick={() => createAiGame("O")}>Play second (O)</button>
<button onClick={() => createAiGame()}>Random</button>
<button onClick={() => createAiGame("X", selectedDifficulty)}>Play first (X)</button>
<button onClick={() => createAiGame("O", selectedDifficulty)}>Play second (O)</button>
<button onClick={() => createAiGame(randomSymbol(), selectedDifficulty)}>Random</button>
</div>
<div>
<select
value={selectedDifficulty}
onChange={(e) => setSelectedDifficulty(parseInt(e.target.value))}
>
<option value={6}>Easy</option>
<option value={7}>Medium</option>
<option value={8}>Hard</option>
</select>
</div>
<button onClick={() => setAiModeSelected(false)}>Back</button>
</>
Expand Down
19 changes: 18 additions & 1 deletion src/startpage/startpage.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,28 @@ img {
.horizontalButtonsContainer {
display: flex;
justify-content: space-between;
margin-bottom: 20px;
margin-bottom: 10px;
}

.horizontalButtonsContainer button {
font-size: 1rem;
margin-left: 5px;
margin-right: 5px;
}

.startScreen select {
text-align: center;
padding: 10px 20px;
font-size: 1.2rem;
background-color: #f8b400;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s ease;
margin-bottom: 20px;
}

.startScreen select:hover {
background-color: #ffd04f;
}
4 changes: 2 additions & 2 deletions src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ h1 {
background: url(../media/home.png) no-repeat;
cursor: pointer;
border: none;
width: 40px;
height: 40px;
width: 43px;
height: 43px;
background-size: contain;
position: absolute;
top: 40px;
Expand Down
Loading