Last active
October 17, 2020 16:40
-
-
Save Emeka-Chukwu/a1860c281ffe84b385eb30610f9a45e3 to your computer and use it in GitHub Desktop.
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'; | |
import 'package:game/util.dart'; | |
import 'package:game/style.dart'; | |
class PaperScissorRock extends StatefulWidget { | |
@override | |
_PaperScissorRockState createState() => _PaperScissorRockState(); | |
} | |
class _PaperScissorRockState extends State<PaperScissorRock> { | |
bool youWin = true; | |
var player = 0; | |
var computerPlayer = 0; | |
String result = ""; | |
String winner = "", action = "", loser = ""; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text( | |
"Hand Paper Scissor", | |
), | |
backgroundColor: Colors.green, | |
), | |
body: Container( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.spaceEvenly, | |
children: [ | |
Text( | |
"$result", | |
style: TextStyle( | |
fontSize: screenWidth(context, 5), | |
), | |
), | |
Text( | |
" $winner $action $loser", | |
style: youWin | |
? TextStyle( | |
color: Colors.green, | |
fontSize: screenWidth(context, 3), | |
) | |
: TextStyle( | |
color: Colors.red, | |
fontSize: screenWidth(context, 3), | |
), | |
), | |
Row( | |
mainAxisAlignment: MainAxisAlignment.spaceEvenly, | |
children: [ | |
Text("You", | |
style: TextStyle( | |
fontSize: screenWidth(context, 4), | |
)), | |
Text( | |
"Computer", | |
style: TextStyle( | |
fontSize: screenWidth(context, 4), | |
), | |
), | |
], | |
), | |
Row( | |
mainAxisAlignment: MainAxisAlignment.spaceEvenly, | |
children: [ | |
Text( | |
"$player", | |
style: player > computerPlayer | |
? playerLead(context) | |
: player == computerPlayer | |
? equal(context) | |
: computer(context), | |
), | |
Text( | |
"$computerPlayer", | |
style: computerPlayer > player | |
? playerLead(context) | |
: player == computerPlayer | |
? equal(context) | |
: computer(context), | |
), | |
], | |
), | |
Row( | |
mainAxisAlignment: MainAxisAlignment.spaceEvenly, | |
children: [ | |
GestureDetector( | |
onTap: () => play(1), | |
child: Container( | |
color: Colors.green, | |
height: screenHeight(context, 7), | |
width: screenWidth(context, 20), | |
child: Center( | |
child: Text( | |
"Paper", | |
style: TextStyle( | |
color: Colors.white, | |
fontSize: screenWidth(context, 3), | |
), | |
)), | |
)), | |
GestureDetector( | |
onTap: () => play(2), | |
child: Container( | |
color: Colors.green, | |
height: screenHeight(context, 7), | |
width: screenWidth(context, 20), | |
child: Center( | |
child: Text( | |
"Scissor", | |
style: TextStyle( | |
color: Colors.white, | |
fontSize: screenWidth(context, 3), | |
), | |
)), | |
)) | |
], | |
), | |
Row( | |
mainAxisAlignment: MainAxisAlignment.spaceEvenly, | |
children: [ | |
GestureDetector( | |
onTap: () => play(2), | |
child: Container( | |
color: Colors.green, | |
height: screenHeight(context, 7), | |
width: screenWidth(context, 20), | |
child: Center( | |
child: Text( | |
"Rock", | |
style: TextStyle( | |
color: Colors.white, | |
fontSize: screenWidth(context, 3), | |
), | |
)), | |
)), | |
GestureDetector( | |
onTap: reset, | |
child: Container( | |
color: Colors.green, | |
height: screenHeight(context, 7), | |
width: screenWidth(context, 20), | |
child: Center( | |
child: Text( | |
"Reset", | |
style: TextStyle( | |
color: Colors.white, | |
fontSize: screenWidth(context, 3), | |
), | |
)), | |
)) | |
], | |
) | |
], | |
), | |
), | |
); | |
} | |
void play(int index){} | |
void reset(){} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment