Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'dart:math';
- import 'package:flutter/material.dart';
- import 'package:math_fighter/game_page.dart';
- void main() => runApp(MyApp());
- class MyApp extends StatelessWidget {
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- title: 'Material App',
- home: Scaffold(
- appBar: AppBar(
- title: Text('Material App Bar'),
- ),
- body: Body(),
- ),
- );
- }
- }
- class Body extends StatefulWidget {
- const Body({
- Key key,
- }) : super(key: key);
- @override
- _BodyState createState() => _BodyState();
- }
- class _BodyState extends State<Body> {
- Random _random = Random();
- // int numOne = _random.nextInt(15);
- GoGame() {
- Navigator.push(context, GamePage(datas: '+'));
- setState(() {});
- }
- GoGame2() {
- Navigator.push(context, GamePage(datas: '-'));
- setState(() {});
- }
- GoGame3() {
- Navigator.push(context, GamePage(datas: 'x'));
- setState(() {});
- }
- GoGameDiv() {
- Navigator.push(context, GamePage(datas: '÷'));
- setState(() {});
- }
- GoGameMix() {
- List opslist = ['+', '-', 'x', '÷'];
- Navigator.push(
- context, GamePage(datas: opslist[_random.nextInt(opslist.length)]))
- .toString();
- setState(() {});
- }
- GoGame5() {
- Navigator.push(context, GamePage(datas: 'this is btn2'));
- setState(() {});
- }
- @override
- Widget build(BuildContext context) {
- return Center(
- child: Column(
- mainAxisAlignment: MainAxisAlignment.spaceEvenly,
- children: [
- Container(
- width: 200,
- height: 50,
- child: RaisedButton(
- onPressed: () {
- GoGame();
- },
- child: Text('Game ADD')),
- ),
- Container(
- width: 200,
- height: 50,
- child: RaisedButton(
- onPressed: () {
- GoGame2();
- },
- child: Text('Game Sub')),
- ),
- Container(
- width: 200,
- height: 50,
- child: RaisedButton(
- onPressed: () {
- GoGame3();
- },
- child: Text('Game Mul')),
- ),
- Container(
- width: 200,
- height: 50,
- child: RaisedButton(
- onPressed: () {
- GoGameDiv();
- },
- child: Text('Game Div')),
- ),
- Container(
- width: 200,
- height: 50,
- child: RaisedButton(
- onPressed: () {
- GoGameMix();
- },
- child: Text('Mix Game')),
- ),
- Container(
- width: 200,
- height: 50,
- child: RaisedButton(
- //onPressed: () {GoGame();},
- child: Text('Game Laevl')),
- ),
- ],
- ),
- );
- }
- }
- ============================================
- GamePage
- ======================================
- import 'dart:math';
- import 'package:flutter/material.dart';
- import 'package:math_expressions/math_expressions.dart';
- class GamePage extends MaterialPageRoute {
- final datas;
- GamePage({this.datas})
- : super(
- builder: (context) {
- Random _random = Random();
- int winTex = 0;
- int lowTex = 0;
- int numOne = _random.nextInt(15);
- int numTwo = _random.nextInt(15);
- int btn1 = numOne + numTwo;
- int btn2 = numOne - numTwo;
- int btn3 = numOne ~/ numTwo;
- int btn4 = numOne * numTwo;
- String str='Math Fighter Game ';
- // if (datas == btn2) {
- // numOne++;
- // }
- return Scaffold(
- appBar: AppBar(
- title: Text(str),
- ),
- body: Column(
- children: [
- Expanded(
- child: Container(
- padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
- alignment: Alignment.center,
- color: Colors.white70,
- child: Column(
- mainAxisAlignment: MainAxisAlignment.spaceAround,
- children: [
- Row(
- mainAxisSize: MainAxisSize.max,
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Text('$numOne'),
- Text(datas,
- style: TextStyle(
- color: Colors.red, fontSize: 25)),
- Text('$numTwo')
- ]),
- Container(
- padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
- child: Row(
- crossAxisAlignment: CrossAxisAlignment.center,
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Column(
- children: [
- Text('Win',
- style: TextStyle(
- color: Colors.green, fontSize: 25)),
- Text('$winTex',
- style: TextStyle(
- color: Colors.lightGreen,
- fontSize: 25)),
- ],
- ),
- Column(
- children: [
- Text(
- 'Low',
- style: TextStyle(
- color: Colors.red, fontSize: 25),
- ),
- Text(
- '$lowTex',
- style: TextStyle(
- color: Colors.red, fontSize: 25),
- ),
- ],
- ),
- ],
- ),
- ),
- ],
- ),
- ),
- ),
- Expanded(
- flex: 2,
- child: Container(
- alignment: Alignment.center,
- color: Colors.blueGrey,
- child: Column(
- mainAxisAlignment: MainAxisAlignment.spaceEvenly,
- children: [
- SizedBox(
- width: 200.0,
- height: 80,
- child: RaisedButton(
- onPressed: () {},
- child: Text('$btn1'),
- ),
- ),
- SizedBox(
- width: 200,
- height: 80,
- child: RaisedButton(
- onPressed: () {},
- child: Text('$btn2'),
- ),
- ),
- SizedBox(
- width: 200,
- height: 80,
- child: RaisedButton(
- onPressed: () {},
- child: Text('$btn3'),
- ),
- ),
- SizedBox(
- width: 200,
- height: 80,
- child: RaisedButton(
- onPressed: () {
- //equsa();
- },
- child: Text('$btn4'),
- ),
- )
- ],
- ),
- ),
- )
- ],
- ),
- );
- },
- );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement