Created
May 30, 2022 03:39
-
-
Save pxpc2/bf2b54551f4951efc49bb1fa742c296b to your computer and use it in GitHub Desktop.
jokenpo flutter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:math'; | |
import 'package:flutter/material.dart'; | |
class Jogo extends StatefulWidget { | |
const Jogo({Key? key}) : super(key: key); | |
@override | |
State<Jogo> createState() => _JogoState(); | |
} | |
class _JogoState extends State<Jogo> { | |
var imgApp = AssetImage("images/padrao.png"); | |
var msg = "Choose an option"; | |
void selectedOption(String userChoice) { | |
var options = ["pedra", "papel", "tesoura"]; | |
var choice = options[Random().nextInt(3)]; | |
setState(() { | |
imgApp = AssetImage("images/$choice.png"); | |
if (userChoice == "pedra") { | |
if (choice == "papel") msg = "You lost."; | |
else if (choice == "tesoura") msg = "You won!"; | |
else msg = "DRAW."; | |
} | |
else if (userChoice == "papel") { | |
if (choice == "tesoura") msg = "You lost."; | |
else if (choice == "pedra") msg = "You won!"; | |
else msg = "DRAW."; | |
} | |
else { | |
if (choice == "pedra") msg = "You lost."; | |
else if (choice == "papel") msg = "You won!"; | |
else msg = "DRAW."; | |
} | |
}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: const Text("JokenPo"), | |
), | |
body: Column( | |
crossAxisAlignment: CrossAxisAlignment.center, | |
children: <Widget>[ | |
// primeira área da tela: TEXTO | |
const Padding( | |
padding: EdgeInsets.only(top: 100, bottom: 16), | |
child: Text( | |
"ENEMY", | |
textAlign: TextAlign.center, | |
style: TextStyle( | |
fontSize: 20, | |
fontWeight: FontWeight.bold | |
), | |
), | |
), | |
// segunda area: imagem | |
Image(image: imgApp, height: 140), | |
// terceira area: texto | |
Padding( | |
padding: const EdgeInsets.only(top: 50, bottom: 16), | |
child: Text( | |
msg, | |
textAlign: TextAlign.center, | |
style: const TextStyle( | |
fontSize: 20, | |
fontWeight: FontWeight.bold | |
), | |
), | |
), | |
// quarta area: imagem | |
Row( | |
mainAxisAlignment: MainAxisAlignment.spaceEvenly, | |
children: [ | |
GestureDetector( | |
onTap: () => selectedOption("pedra"), | |
child: Image.asset("images/pedra.png", height: 100,), | |
), | |
GestureDetector( | |
onTap: () => selectedOption("papel"), | |
child: Image.asset("images/papel.png", height: 100), | |
), | |
GestureDetector( | |
onTap: () => selectedOption("tesoura"), | |
child: Image.asset("images/tesoura.png", height: 100), | |
), | |
], | |
) | |
], | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment