Explain solidity>if else

Game Over Logic

After each move, we need to check if the game is over. The game ends when someone wins or it's a draw.

If/Else Statements:

Let you execute different code based on conditions.

Syntax:

if (condition) { ... } else if (anotherCondition) { ... } else { ... }

Example:

if (score > 100) { winner = true; } else { winner = false; }



For Our Game:

First, add a bool public gameOver; state variable to track if the game has ended.

Then update makeMove to check game state AFTER placing the piece:

• If checkWin() returns true → set gameOver = true;

• Else if checkDraw() returns true → set gameOver = true;

• Else → toggle turn with xTurn = !xTurn;



This ensures the turn only switches if the game continues.

Add game over logic with if/else
0%
Requirements:
Declares bool public gameOver
Has if statement checking checkWin()
Sets gameOver = true when win
Has else if checking checkDraw()
Sets gameOver = true when draw
Has else clause
Toggles turn in else clause