Advertisement
ZawXtut

flutter_SanDevGame

Nov 7th, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 8.60 KB | None | 0 0
  1. import 'dart:math';
  2.  
  3. import 'package:flutter/material.dart';
  4. import 'package:math_fighter/game_page.dart';
  5.  
  6. void main() => runApp(MyApp());
  7.  
  8. class MyApp extends StatelessWidget {
  9.   @override
  10.   Widget build(BuildContext context) {
  11.     return MaterialApp(
  12.       title: 'Material App',
  13.       home: Scaffold(
  14.         appBar: AppBar(
  15.           title: Text('Material App Bar'),
  16.         ),
  17.         body: Body(),
  18.       ),
  19.     );
  20.   }
  21. }
  22.  
  23. class Body extends StatefulWidget {
  24.   const Body({
  25.     Key key,
  26.   }) : super(key: key);
  27.  
  28.   @override
  29.   _BodyState createState() => _BodyState();
  30. }
  31.  
  32. class _BodyState extends State<Body> {
  33.   Random _random = Random();
  34.   // int numOne = _random.nextInt(15);
  35.  
  36.   GoGame() {
  37.     Navigator.push(context, GamePage(datas: '+'));
  38.     setState(() {});
  39.   }
  40.  
  41.   GoGame2() {
  42.     Navigator.push(context, GamePage(datas: '-'));
  43.     setState(() {});
  44.   }
  45.  
  46.   GoGame3() {
  47.     Navigator.push(context, GamePage(datas: 'x'));
  48.     setState(() {});
  49.   }
  50.  
  51.   GoGameDiv() {
  52.     Navigator.push(context, GamePage(datas: '÷'));
  53.     setState(() {});
  54.   }
  55.  
  56.   GoGameMix() {
  57.     List opslist = ['+', '-', 'x', '÷'];
  58.  
  59.     Navigator.push(
  60.             context, GamePage(datas: opslist[_random.nextInt(opslist.length)]))
  61.         .toString();
  62.     setState(() {});
  63.   }
  64.  
  65.   GoGame5() {
  66.     Navigator.push(context, GamePage(datas: 'this is btn2'));
  67.     setState(() {});
  68.   }
  69.  
  70.   @override
  71.   Widget build(BuildContext context) {
  72.     return Center(
  73.       child: Column(
  74.         mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  75.         children: [
  76.           Container(
  77.             width: 200,
  78.             height: 50,
  79.             child: RaisedButton(
  80.                 onPressed: () {
  81.                   GoGame();
  82.                 },
  83.                 child: Text('Game ADD')),
  84.           ),
  85.           Container(
  86.             width: 200,
  87.             height: 50,
  88.             child: RaisedButton(
  89.                 onPressed: () {
  90.                   GoGame2();
  91.                 },
  92.                 child: Text('Game Sub')),
  93.           ),
  94.           Container(
  95.             width: 200,
  96.             height: 50,
  97.             child: RaisedButton(
  98.                 onPressed: () {
  99.                   GoGame3();
  100.                 },
  101.                 child: Text('Game Mul')),
  102.           ),
  103.           Container(
  104.             width: 200,
  105.             height: 50,
  106.             child: RaisedButton(
  107.                 onPressed: () {
  108.                   GoGameDiv();
  109.                 },
  110.                 child: Text('Game Div')),
  111.           ),
  112.           Container(
  113.             width: 200,
  114.             height: 50,
  115.             child: RaisedButton(
  116.                 onPressed: () {
  117.                   GoGameMix();
  118.                 },
  119.                 child: Text('Mix Game')),
  120.           ),
  121.           Container(
  122.             width: 200,
  123.             height: 50,
  124.             child: RaisedButton(
  125.                 //onPressed: () {GoGame();},
  126.                 child: Text('Game Laevl')),
  127.           ),
  128.         ],
  129.       ),
  130.     );
  131.   }
  132. }
  133. ============================================
  134. GamePage
  135. ======================================
  136. import 'dart:math';
  137.  
  138. import 'package:flutter/material.dart';
  139. import 'package:math_expressions/math_expressions.dart';
  140.  
  141. class GamePage extends MaterialPageRoute {
  142.   final datas;
  143.  
  144.   GamePage({this.datas})
  145.       : super(
  146.           builder: (context) {
  147.             Random _random = Random();
  148.             int winTex = 0;
  149.             int lowTex = 0;
  150.            
  151.             int numOne = _random.nextInt(15);
  152.             int numTwo = _random.nextInt(15);
  153.  
  154.             int btn1 = numOne + numTwo;
  155.             int btn2 = numOne - numTwo;
  156.             int btn3 = numOne ~/ numTwo;
  157.             int btn4 = numOne * numTwo;
  158.             String str='Math Fighter Game ';
  159.             // if (datas == btn2) {
  160.             //   numOne++;
  161.             // }
  162.  
  163.             return Scaffold(
  164.               appBar: AppBar(
  165.                 title: Text(str),
  166.               ),
  167.               body: Column(
  168.                 children: [
  169.                   Expanded(
  170.                     child: Container(
  171.                       padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
  172.                       alignment: Alignment.center,
  173.                       color: Colors.white70,
  174.                       child: Column(
  175.                         mainAxisAlignment: MainAxisAlignment.spaceAround,
  176.                         children: [
  177.                           Row(
  178.                               mainAxisSize: MainAxisSize.max,
  179.                               mainAxisAlignment: MainAxisAlignment.spaceBetween,
  180.                               children: [
  181.                                 Text('$numOne'),
  182.                                 Text(datas,
  183.                                     style: TextStyle(
  184.                                         color: Colors.red, fontSize: 25)),
  185.                                 Text('$numTwo')
  186.                               ]),
  187.                           Container(
  188.                             padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
  189.                             child: Row(
  190.                               crossAxisAlignment: CrossAxisAlignment.center,
  191.                               mainAxisAlignment: MainAxisAlignment.spaceBetween,
  192.                               children: [
  193.                                 Column(
  194.                                   children: [
  195.                                     Text('Win',
  196.                                         style: TextStyle(
  197.                                             color: Colors.green, fontSize: 25)),
  198.                                     Text('$winTex',
  199.                                         style: TextStyle(
  200.                                             color: Colors.lightGreen,
  201.                                             fontSize: 25)),
  202.                                   ],
  203.                                 ),
  204.                                 Column(
  205.                                   children: [
  206.                                     Text(
  207.                                       'Low',
  208.                                       style: TextStyle(
  209.                                           color: Colors.red, fontSize: 25),
  210.                                     ),
  211.                                     Text(
  212.                                       '$lowTex',
  213.                                       style: TextStyle(
  214.                                           color: Colors.red, fontSize: 25),
  215.                                     ),
  216.                                   ],
  217.                                 ),
  218.                               ],
  219.                             ),
  220.                           ),
  221.                         ],
  222.                       ),
  223.                     ),
  224.                   ),
  225.                   Expanded(
  226.                     flex: 2,
  227.                     child: Container(
  228.                       alignment: Alignment.center,
  229.                       color: Colors.blueGrey,
  230.                       child: Column(
  231.                         mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  232.                         children: [
  233.                           SizedBox(
  234.                             width: 200.0,
  235.                             height: 80,
  236.                             child: RaisedButton(
  237.                               onPressed: () {},
  238.                               child: Text('$btn1'),
  239.                             ),
  240.                           ),
  241.                           SizedBox(
  242.                             width: 200,
  243.                             height: 80,
  244.                             child: RaisedButton(
  245.                               onPressed: () {},
  246.                               child: Text('$btn2'),
  247.                             ),
  248.                           ),
  249.                           SizedBox(
  250.                             width: 200,
  251.                             height: 80,
  252.                             child: RaisedButton(
  253.                               onPressed: () {},
  254.                               child: Text('$btn3'),
  255.                             ),
  256.                           ),
  257.                           SizedBox(
  258.                             width: 200,
  259.                             height: 80,
  260.                             child: RaisedButton(
  261.                               onPressed: () {
  262.                                 //equsa();
  263.                               },
  264.                               child: Text('$btn4'),
  265.                             ),
  266.                           )
  267.                         ],
  268.                       ),
  269.                     ),
  270.                   )
  271.                 ],
  272.               ),
  273.             );
  274.           },
  275.         );
  276. }
  277.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement