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

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay