mirror of
https://github.com/jaysavsani07/math-metrix.git
synced 2025-05-21 02:46:21 +08:00
Square root game design changed
This commit is contained in:
@ -25,7 +25,7 @@ class CalculatorProvider extends GameProvider<Calculator> {
|
|||||||
loadNewDataIfRequired();
|
loadNewDataIfRequired();
|
||||||
_result = "";
|
_result = "";
|
||||||
if (timerStatus != TimerStatus.pause) {
|
if (timerStatus != TimerStatus.pause) {
|
||||||
startTimer();
|
restartTimer();
|
||||||
}
|
}
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
} else if (_result.length == currentState.answer.toString().length) {
|
} else if (_result.length == currentState.answer.toString().length) {
|
||||||
|
@ -40,7 +40,7 @@ class DialogListener<T extends GameProvider> extends StatelessWidget {
|
|||||||
barrierDismissible: false,
|
barrierDismissible: false,
|
||||||
).then((value) {
|
).then((value) {
|
||||||
if (value != null && value) {
|
if (value != null && value) {
|
||||||
context.read<T>().restart();
|
context.read<T>().restartTimer();
|
||||||
} else {
|
} else {
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
}
|
}
|
||||||
@ -63,7 +63,7 @@ class DialogListener<T extends GameProvider> extends StatelessWidget {
|
|||||||
isScrollControlled: true,
|
isScrollControlled: true,
|
||||||
).then((value) {
|
).then((value) {
|
||||||
if (value != null && value) {
|
if (value != null && value) {
|
||||||
context.read<T>().restart();
|
context.read<T>().restartTimer();
|
||||||
} else {
|
} else {
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ class TimeProvider with ChangeNotifier {
|
|||||||
_animationController.value = 1.0;
|
_animationController.value = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void restart() {
|
void restartTimer() {
|
||||||
_animationController.reverse(from: 1.0);
|
_animationController.reverse(from: 1.0);
|
||||||
timerStatus = TimerStatus.play;
|
timerStatus = TimerStatus.play;
|
||||||
dialogType = DialogType.non;
|
dialogType = DialogType.non;
|
||||||
|
@ -1,139 +1,124 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_neumorphic/flutter_neumorphic.dart';
|
||||||
|
import 'package:mathgame/src/core/color_scheme.dart';
|
||||||
|
import 'package:mathgame/src/data/models/square_root.dart';
|
||||||
|
import 'package:mathgame/src/ui/common/CommonNumberButton.dart';
|
||||||
|
import 'package:mathgame/src/ui/common/common_app_bar.dart';
|
||||||
|
import 'package:mathgame/src/ui/common/common_info_text_view.dart';
|
||||||
|
import 'package:mathgame/src/ui/common/dialog_listener.dart';
|
||||||
import 'package:mathgame/src/ui/squareRoot/square_root_view_model.dart';
|
import 'package:mathgame/src/ui/squareRoot/square_root_view_model.dart';
|
||||||
import 'package:mathgame/src/core/app_constant.dart';
|
import 'package:mathgame/src/core/app_constant.dart';
|
||||||
import 'package:mathgame/src/ui/squareRoot/square_root_button.dart';
|
|
||||||
import 'package:mathgame/src/ui/common/timer.dart';
|
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:vsync_provider/vsync_provider.dart';
|
||||||
|
|
||||||
class SquareRootView extends StatelessWidget {
|
class SquareRootView extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return ChangeNotifierProvider<SquareRootProvider>(
|
return MultiProvider(
|
||||||
create: (_) => SquareRootProvider(),
|
providers: [
|
||||||
child: WillPopScope(
|
const VsyncProvider(),
|
||||||
onWillPop: () => Future.value(false),
|
ChangeNotifierProvider<SquareRootProvider>(
|
||||||
|
create: (context) =>
|
||||||
|
SquareRootProvider(vsync: VsyncProvider.of(context)))
|
||||||
|
],
|
||||||
|
child: SafeArea(
|
||||||
|
top: true,
|
||||||
|
bottom: true,
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
body: SafeArea(
|
appBar: CommonAppBar<SquareRootProvider>(),
|
||||||
top: true,
|
body: DialogListener<SquareRootProvider>(
|
||||||
bottom: true,
|
gameCategoryType: GameCategoryType.SQUARE_ROOT,
|
||||||
child: Container(
|
child: Container(
|
||||||
margin: EdgeInsets.fromLTRB(20, 20, 20, 0),
|
margin: EdgeInsets.all(24),
|
||||||
constraints: BoxConstraints.expand(),
|
constraints: BoxConstraints.expand(),
|
||||||
child: Consumer<SquareRootProvider>(
|
child: Column(
|
||||||
builder: (context, squareRootProvider, child) {
|
children: <Widget>[
|
||||||
return Column(
|
CommonInfoTextView<SquareRootProvider>(
|
||||||
children: <Widget>[
|
gameCategoryType: GameCategoryType.SQUARE_ROOT),
|
||||||
Expanded(
|
Expanded(
|
||||||
flex: 10,
|
child: Column(
|
||||||
child: SizedBox(
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
child: Align(
|
children: [
|
||||||
alignment: Alignment.bottomLeft,
|
Selector<SquareRootProvider, SquareRoot>(
|
||||||
child: Timer(GameCategoryType.SQUARE_ROOT),
|
selector: (p0, p1) => p1.currentState,
|
||||||
),
|
builder: (context, currentState, child) {
|
||||||
)),
|
return Text(
|
||||||
Expanded(
|
currentState.question,
|
||||||
flex: 20,
|
style: Theme.of(context)
|
||||||
child: Center(
|
.textTheme
|
||||||
child: Visibility(
|
.subtitle2!
|
||||||
visible: !squareRootProvider.pause,
|
.copyWith(fontSize: 30),
|
||||||
child: Text(
|
);
|
||||||
squareRootProvider.currentState.question,
|
}),
|
||||||
style: Theme.of(context).textTheme.headline1,
|
SizedBox(height: 14),
|
||||||
),
|
Neumorphic(
|
||||||
),
|
style: NeumorphicStyle(
|
||||||
)),
|
// shape: NeumorphicShape.convex,
|
||||||
Expanded(
|
boxShape: NeumorphicBoxShape.roundRect(
|
||||||
flex: 60,
|
BorderRadius.circular(18)),
|
||||||
child: Align(
|
depth: -8,
|
||||||
|
lightSource: LightSource.topLeft,
|
||||||
|
color: Theme.of(context).colorScheme.iconBgColor,
|
||||||
|
),
|
||||||
|
child: Container(
|
||||||
|
height: 30,
|
||||||
|
width: 30,
|
||||||
alignment: Alignment.center,
|
alignment: Alignment.center,
|
||||||
child: SizedBox(
|
margin: const EdgeInsets.only(
|
||||||
height: 300,
|
left: 10, right: 10, bottom: 5, top: 10),
|
||||||
width: 500,
|
child: Selector<SquareRootProvider, String>(
|
||||||
child: Container(
|
selector: (p0, p1) => p1.result,
|
||||||
margin: EdgeInsets.fromLTRB(20, 0, 20, 0),
|
builder: (context, calculatorProvider, child) {
|
||||||
decoration: BoxDecoration(
|
return Text(
|
||||||
borderRadius:
|
calculatorProvider,
|
||||||
BorderRadius.all(Radius.circular(30)),
|
style: Theme.of(context)
|
||||||
),
|
.textTheme
|
||||||
child: Column(
|
.subtitle2!
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
.copyWith(
|
||||||
children: <Widget>[
|
fontSize: 30, color: Color(0xff4895EF)),
|
||||||
Expanded(
|
);
|
||||||
child: Row(
|
},
|
||||||
children: <Widget>[
|
|
||||||
SquareRootButton(
|
|
||||||
squareRootProvider
|
|
||||||
.currentState.firstAns,
|
|
||||||
BorderRadius.only(
|
|
||||||
topLeft:
|
|
||||||
Radius.circular(40))),
|
|
||||||
SquareRootButton(
|
|
||||||
squareRootProvider
|
|
||||||
.currentState.secondAns,
|
|
||||||
BorderRadius.only(
|
|
||||||
topRight:
|
|
||||||
Radius.circular(40)))
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Expanded(
|
|
||||||
child: Row(
|
|
||||||
children: <Widget>[
|
|
||||||
SquareRootButton(
|
|
||||||
squareRootProvider
|
|
||||||
.currentState.thirdAns,
|
|
||||||
BorderRadius.only(
|
|
||||||
bottomLeft:
|
|
||||||
Radius.circular(40))),
|
|
||||||
SquareRootButton(
|
|
||||||
squareRootProvider
|
|
||||||
.currentState.fourthAns,
|
|
||||||
BorderRadius.only(
|
|
||||||
bottomRight:
|
|
||||||
Radius.circular(40)))
|
|
||||||
],
|
|
||||||
),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Expanded(
|
|
||||||
flex: 10,
|
|
||||||
child: Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
|
||||||
children: <Widget>[
|
|
||||||
Consumer<SquareRootProvider>(
|
|
||||||
builder: (context, provider, child) {
|
|
||||||
return IconButton(
|
|
||||||
icon: provider.pause
|
|
||||||
? Icon(Icons.play_arrow)
|
|
||||||
: Icon(Icons.pause),
|
|
||||||
iconSize: 40,
|
|
||||||
onPressed: () {
|
|
||||||
provider.pauseTimer();
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
Consumer<SquareRootProvider>(
|
|
||||||
builder: (context, provider, child) {
|
|
||||||
return IconButton(
|
|
||||||
icon: Icon(Icons.info_outline),
|
|
||||||
iconSize: 40,
|
|
||||||
onPressed: () {
|
|
||||||
provider.showInfoDialog();
|
|
||||||
},
|
|
||||||
);
|
|
||||||
})
|
|
||||||
],
|
|
||||||
)),
|
|
||||||
],
|
],
|
||||||
);
|
),
|
||||||
},
|
),
|
||||||
)),
|
Selector<SquareRootProvider, SquareRoot>(
|
||||||
|
selector: (p0, p1) => p1.currentState,
|
||||||
|
builder: (context, currentState, child) {
|
||||||
|
return GridView(
|
||||||
|
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||||
|
crossAxisCount: 2),
|
||||||
|
shrinkWrap: true,
|
||||||
|
physics: NeverScrollableScrollPhysics(),
|
||||||
|
children: [
|
||||||
|
...[
|
||||||
|
currentState.firstAns,
|
||||||
|
currentState.secondAns,
|
||||||
|
currentState.thirdAns,
|
||||||
|
currentState.fourthAns,
|
||||||
|
].map(
|
||||||
|
(e) {
|
||||||
|
return CommonNumberButton(
|
||||||
|
text: e,
|
||||||
|
onTab: () {
|
||||||
|
context
|
||||||
|
.read<SquareRootProvider>()
|
||||||
|
.checkResult(e);
|
||||||
|
},
|
||||||
|
startColor: Color(0xff4895EF),
|
||||||
|
endColor: Color(0xff3f37c9),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
)
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -3,130 +3,35 @@ import 'dart:async';
|
|||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:mathgame/src/data/models/square_root.dart';
|
import 'package:mathgame/src/data/models/square_root.dart';
|
||||||
import 'package:mathgame/src/core/app_constant.dart';
|
import 'package:mathgame/src/core/app_constant.dart';
|
||||||
import 'package:mathgame/src/core/time_constant.dart';
|
import 'package:mathgame/src/ui/common/game_provider.dart';
|
||||||
|
|
||||||
import '../common/game_view_model.dart';
|
class SquareRootProvider extends GameProvider<SquareRoot> {
|
||||||
|
late String _result;
|
||||||
class SquareRootProvider
|
|
||||||
with ChangeNotifier
|
|
||||||
implements GameAccess<SquareRoot> {
|
|
||||||
late GameViewModelImp gameViewModel;
|
|
||||||
|
|
||||||
late String _result;
|
|
||||||
|
|
||||||
String get result => _result;
|
String get result => _result;
|
||||||
|
|
||||||
late int _time;
|
SquareRootProvider({required TickerProvider vsync})
|
||||||
|
: super(vsync: vsync, gameCategoryType: GameCategoryType.SQUARE_ROOT) {
|
||||||
int get time => _time;
|
|
||||||
|
|
||||||
bool _pause = false;
|
|
||||||
|
|
||||||
bool get pause => _pause;
|
|
||||||
|
|
||||||
late SquareRoot _currentState;
|
|
||||||
|
|
||||||
SquareRoot get currentState => _currentState;
|
|
||||||
|
|
||||||
double _currentScore = 0;
|
|
||||||
|
|
||||||
double get currentScore => _currentScore;
|
|
||||||
late bool _timeOut;
|
|
||||||
|
|
||||||
SquareRootProvider() {
|
|
||||||
gameViewModel = GameViewModelImp<SquareRoot>(
|
|
||||||
gameAccess: this, gameCategoryType: GameCategoryType.SQUARE_ROOT);
|
|
||||||
startGame1();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void startGame1() {
|
|
||||||
_time = TimeUtil.squareRootTimeOut;
|
|
||||||
_timeOut = false;
|
|
||||||
_result = "";
|
_result = "";
|
||||||
_currentScore = 0;
|
startGame();
|
||||||
gameViewModel.startGame();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> checkResult(String answer) async {
|
Future<void> checkResult(String answer) async {
|
||||||
if (_result.length < currentState.answer.toString().length && !_timeOut) {
|
if (_result.length < currentState.answer.toString().length &&
|
||||||
|
timerStatus != TimerStatus.pause) {
|
||||||
_result = answer;
|
_result = answer;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
if (int.parse(_result) == currentState.answer) {
|
if (int.parse(_result) == currentState.answer) {
|
||||||
await Future.delayed(Duration(milliseconds: 300));
|
await Future.delayed(Duration(milliseconds: 300));
|
||||||
/*<<<<<<< HEAD
|
loadNewDataIfRequired();
|
||||||
if (_list.length - 1 == _index) {
|
|
||||||
_list.addAll(
|
|
||||||
SquareRootQandSDataProvider.getSquareDataList(_index ~/ 5 + 2));
|
|
||||||
print("_index $_index");
|
|
||||||
}
|
|
||||||
_index = _index + 1;
|
|
||||||
currentScore = currentScore + ScoreUtil.squareRootScore;
|
|
||||||
_currentState = _list[_index];
|
|
||||||
=======*/
|
|
||||||
gameViewModel.loadNewDataIfRequired();
|
|
||||||
_result = "";
|
_result = "";
|
||||||
_time = TimeUtil.squareRootTimeOut;
|
if (timerStatus != TimerStatus.pause) {
|
||||||
if (!_timeOut) {
|
restartTimer();
|
||||||
gameViewModel.restartGame();
|
|
||||||
}
|
}
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
} else if (_result.length == currentState.answer.toString().length) {
|
} else if (_result.length == currentState.answer.toString().length) {
|
||||||
gameViewModel.wrongAnswer();
|
wrongAnswer();
|
||||||
_result = "";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
clear() {
|
|
||||||
_result = "";
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void onGameTimeOut() {
|
|
||||||
this._timeOut = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void onGameTimeUpdate(int time) {
|
|
||||||
_time = time;
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void onCurrentStateUpdate(SquareRoot currentState) {
|
|
||||||
_currentState = currentState;
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void onScoreUpdate(double time) {
|
|
||||||
_currentScore = time;
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void onResumeGame() {
|
|
||||||
_pause = false;
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
void pauseTimer() {
|
|
||||||
_pause = true;
|
|
||||||
gameViewModel.pauseGame();
|
|
||||||
notifyListeners();
|
|
||||||
gameViewModel.showPauseGameDialog();
|
|
||||||
}
|
|
||||||
|
|
||||||
void showInfoDialog() {
|
|
||||||
_pause = true;
|
|
||||||
gameViewModel.pauseGame();
|
|
||||||
gameViewModel.showInfoDialog();
|
|
||||||
}
|
|
||||||
|
|
||||||
void dispose() {
|
|
||||||
super.dispose();
|
|
||||||
gameViewModel.exitGame();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ class SignProvider extends GameProvider<Sign> {
|
|||||||
loadNewDataIfRequired();
|
loadNewDataIfRequired();
|
||||||
_result = "";
|
_result = "";
|
||||||
if (timerStatus != TimerStatus.pause) {
|
if (timerStatus != TimerStatus.pause) {
|
||||||
startTimer();
|
restartTimer();
|
||||||
}
|
}
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user