Explain solidity>helper functions

Organizing with Private Functions

When game logic gets complex, private helper functions keep code clean and reusable.

The _endGame Helper:

We need to end the game from two places: when someone wins/draws, and when someone claims forfeit.

Instead of duplicating code, create a helper: function _endGame(address _winner, bool isDraw) private



Naming Convention:

Private internal functions often start with an underscore: _endGame

This makes it clear they're not part of the public interface.



What _endGame Does:

1. Set gameOver = true;
2. Set winner = _winner;
3. Store the pot: uint256 pot = stake;
4. If draw, split pot: both players get their stake back
5. If win, winner gets double: credits[_winner] += pot;
6. Reset game state so a new game can start
7. Emit GameEnded event



Create the _endGame helper function with proper win/draw logic.

Create _endGame helper function
0%
Requirements:
Declares _endGame function
_endGame is private
Has _winner parameter
Has isDraw parameter
Sets gameOver to true
Sets winner to _winner parameter
Stores pot in variable
Uses if/else for isDraw logic
Credits both players on draw
Credits winner on win
Resets stake to 0
Resets gameActive to false
Emits GameEnded event