mirror of
https://github.com/tonytins/bullseye.git
synced 2025-03-22 07:02:20 +00:00
Calculate and update scores
This commit is contained in:
parent
4ac0e61ab7
commit
eeb5c9ac28
2 changed files with 18 additions and 11 deletions
|
@ -39,7 +39,7 @@ class BullsEyeApp extends StatelessWidget {
|
||||||
[DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight]);
|
[DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight]);
|
||||||
return PlatformApp(
|
return PlatformApp(
|
||||||
title: gameTitle,
|
title: gameTitle,
|
||||||
debugShowCheckedModeBanner: false,
|
// debugShowCheckedModeBanner: false,
|
||||||
home: GamePage(title: gameTitle));
|
home: GamePage(title: gameTitle));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,6 +63,15 @@ class _GamePageState extends State<GamePage> {
|
||||||
_model = GameModel(rng.nextInt(100) + 1);
|
_model = GameModel(rng.nextInt(100) + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int _sliderValue() => _model.current;
|
||||||
|
|
||||||
|
int _pointsForCurrentRound() {
|
||||||
|
var maxScore = 100;
|
||||||
|
var difference = (_model.target - _sliderValue()).abs();
|
||||||
|
|
||||||
|
return maxScore - difference;
|
||||||
|
}
|
||||||
|
|
||||||
Widget gameContainer() {
|
Widget gameContainer() {
|
||||||
return Column(
|
return Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
@ -72,8 +81,8 @@ class _GamePageState extends State<GamePage> {
|
||||||
PlatformTextButton(
|
PlatformTextButton(
|
||||||
child: PlatformText('Hit me!'),
|
child: PlatformText('Hit me!'),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
this._alertIsVisable = true;
|
|
||||||
_showAlert(context);
|
_showAlert(context);
|
||||||
|
this._alertIsVisable = true;
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
@ -116,20 +125,17 @@ class _GamePageState extends State<GamePage> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
int _pointsForCurrentRound() {
|
|
||||||
var maxScore = 100;
|
|
||||||
var difference = (_model.target - _model.current).abs();
|
|
||||||
|
|
||||||
return maxScore - difference;
|
|
||||||
}
|
|
||||||
|
|
||||||
void _showAlert(BuildContext context) {
|
void _showAlert(BuildContext context) {
|
||||||
var okButton = PlatformTextButton(
|
var okButton = PlatformTextButton(
|
||||||
child: PlatformText("Awesome!"),
|
child: PlatformText("Awesome!"),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
this._alertIsVisable = false;
|
this._alertIsVisable = false;
|
||||||
print("Awesome Pressed! $_alertIsVisable");
|
setState(() {
|
||||||
|
_model.totalScore += _pointsForCurrentRound();
|
||||||
|
var rng = Random();
|
||||||
|
_model.target = rng.nextInt(100) + 1;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
showPlatformDialog(
|
showPlatformDialog(
|
||||||
|
@ -137,7 +143,7 @@ class _GamePageState extends State<GamePage> {
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
return PlatformAlertDialog(
|
return PlatformAlertDialog(
|
||||||
title: PlatformText("Hello There."),
|
title: PlatformText("Hello There."),
|
||||||
content: PlatformText("The slider's value is ${_model.current}\n" +
|
content: PlatformText("The slider's value is ${_sliderValue()}\n" +
|
||||||
"You scored ${_pointsForCurrentRound()} points this round."),
|
"You scored ${_pointsForCurrentRound()} points this round."),
|
||||||
actions: <Widget>[okButton],
|
actions: <Widget>[okButton],
|
||||||
);
|
);
|
||||||
|
|
|
@ -30,6 +30,7 @@ dependencies:
|
||||||
google_fonts: ^2.1.0
|
google_fonts: ^2.1.0
|
||||||
flutter_platform_widgets: ^1.9.0
|
flutter_platform_widgets: ^1.9.0
|
||||||
bitsdojo_window: ^0.1.0+1
|
bitsdojo_window: ^0.1.0+1
|
||||||
|
font_awesome: ^5.10.1
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|
Loading…
Add table
Reference in a new issue