DEV Community

Cover image for Rock Paper Scissors Game - Flutter
Muha-mmed
Muha-mmed

Posted on

Rock Paper Scissors Game - Flutter

In this article, I'll show you how I built a simple Rock Paper Scissors game using Flutter. The app allows you to play the classic game against the computer. You can check out the full code on GitHub here.

How the Game Works

The game has a simple structure:

  1. The player selects either Rock, Paper, or Scissors.
  2. The computer makes a random choice.
  3. A comparison is made to determine the winner:
    • Rock beats Scissors
    • Scissors beats Paper
    • Paper beats Rock

The game shows the results and updates the score.

Code Walkthrough

Here's the function that generates the computer's choice:

String getComputerChoice() {
    List<String> choices = ['Rock', 'Paper', 'Scissors'];
    return choices[Random().nextInt(3)];
}

Enter fullscreen mode Exit fullscreen mode

Image description
Image description
Image description

Top comments (0)