Skip to content

Instantly share code, notes, and snippets.

@Emeka-Chukwu
Last active October 17, 2020 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Emeka-Chukwu/a1860c281ffe84b385eb30610f9a45e3 to your computer and use it in GitHub Desktop.
Save Emeka-Chukwu/a1860c281ffe84b385eb30610f9a45e3 to your computer and use it in GitHub Desktop.
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