mirror of
https://github.com/tonytins/bullseye.git
synced 2025-03-15 04:11:22 +00:00
Game model
This commit is contained in:
parent
9c707d1e47
commit
36c7e3d59b
4 changed files with 78 additions and 23 deletions
|
@ -1,34 +1,45 @@
|
|||
import 'package:bullseye/game_model.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
|
||||
|
||||
class Control extends StatefulWidget {
|
||||
Control({Key? key}) : super(key: key);
|
||||
Control({Key? key, @required this.model}) : super(key: key);
|
||||
final GameModel? model;
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _ControlState();
|
||||
}
|
||||
|
||||
class _ControlState extends State<Control> {
|
||||
double _currentValue = 50.0;
|
||||
static const double PADDING = 45;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var currentValue = widget.model?.current;
|
||||
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
PlatformText("1"),
|
||||
PlatformSlider(
|
||||
value: _currentValue,
|
||||
onChanged: (newValue) {
|
||||
setState(() {
|
||||
_currentValue = newValue;
|
||||
print(_currentValue);
|
||||
});
|
||||
},
|
||||
min: 1.0,
|
||||
max: 100.0,
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(PADDING),
|
||||
child: PlatformText("1"),
|
||||
),
|
||||
PlatformText("100")
|
||||
Expanded(
|
||||
child: PlatformSlider(
|
||||
value: currentValue!.toDouble(),
|
||||
onChanged: (newValue) {
|
||||
setState(() {
|
||||
widget.model!.current = newValue.toInt();
|
||||
});
|
||||
},
|
||||
min: 1.0,
|
||||
max: 100.0,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(PADDING),
|
||||
child: PlatformText("100"),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
|
|
15
lib/game_model.dart
Normal file
15
lib/game_model.dart
Normal file
|
@ -0,0 +1,15 @@
|
|||
class GameModel {
|
||||
static const SLIDER_CONST = 50;
|
||||
static const SCORE_START = 0;
|
||||
static const ROUND_START = 0;
|
||||
|
||||
GameModel(this.target,
|
||||
[this.current = SLIDER_CONST,
|
||||
this.totalScore = SCORE_START,
|
||||
this.round = ROUND_START]);
|
||||
|
||||
int? target;
|
||||
int? current;
|
||||
int? totalScore;
|
||||
int? round;
|
||||
}
|
|
@ -1,9 +1,11 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:bullseye/prompt.dart';
|
||||
import 'package:bullseye/control.dart';
|
||||
import 'package:bullseye/score.dart';
|
||||
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
|
||||
import 'package:bullseye/game_model.dart';
|
||||
|
||||
void main() => runApp(BullsEyeApp());
|
||||
|
||||
|
@ -33,6 +35,13 @@ class GamePage extends StatefulWidget {
|
|||
|
||||
class _GamePageState extends State<GamePage> {
|
||||
bool _alertIsVisable = false;
|
||||
GameModel _model = GameModel(50);
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_model = GameModel(50);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -41,15 +50,15 @@ class _GamePageState extends State<GamePage> {
|
|||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Prompt(targetValue: 100),
|
||||
Control(),
|
||||
Prompt(targetValue: _model.target),
|
||||
Control(model: _model),
|
||||
PlatformTextButton(
|
||||
child: PlatformText('Hit me!'),
|
||||
onPressed: () {
|
||||
this._alertIsVisable = true;
|
||||
_showAlert(context);
|
||||
}),
|
||||
Score()
|
||||
Score(totalScore: _model.totalScore, round: _model.round)
|
||||
],
|
||||
),
|
||||
),
|
||||
|
|
|
@ -2,19 +2,39 @@ import 'package:flutter/material.dart';
|
|||
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
|
||||
|
||||
class Score extends StatelessWidget {
|
||||
Score({Key? key, @required this.totalScore, @required this.round})
|
||||
: super(key: key);
|
||||
|
||||
final int? totalScore;
|
||||
final int? round;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
children: [
|
||||
PlatformButton(
|
||||
child: PlatformText("Start Over"),
|
||||
onPressed: () {},
|
||||
),
|
||||
PlatformText("Score:"),
|
||||
PlatformText("999"),
|
||||
PlatformText("Round:"),
|
||||
PlatformText("999"),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Row(
|
||||
children: [
|
||||
PlatformText("Score:"),
|
||||
PlatformText("$totalScore"),
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Row(
|
||||
children: [
|
||||
PlatformText("Round:"),
|
||||
PlatformText("$round"),
|
||||
],
|
||||
),
|
||||
),
|
||||
PlatformButton(
|
||||
child: PlatformText("Info"),
|
||||
onPressed: () {},
|
||||
|
|
Loading…
Add table
Reference in a new issue