mirror of
https://github.com/tonytins/bullseye.git
synced 2025-03-21 22:52:19 +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/material.dart';
|
||||||
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
|
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
|
||||||
|
|
||||||
class Control extends StatefulWidget {
|
class Control extends StatefulWidget {
|
||||||
Control({Key? key}) : super(key: key);
|
Control({Key? key, @required this.model}) : super(key: key);
|
||||||
|
final GameModel? model;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<StatefulWidget> createState() => _ControlState();
|
State<StatefulWidget> createState() => _ControlState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _ControlState extends State<Control> {
|
class _ControlState extends State<Control> {
|
||||||
double _currentValue = 50.0;
|
static const double PADDING = 45;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
var currentValue = widget.model?.current;
|
||||||
|
|
||||||
return Row(
|
return Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
PlatformText("1"),
|
Padding(
|
||||||
PlatformSlider(
|
padding: const EdgeInsets.all(PADDING),
|
||||||
value: _currentValue,
|
child: PlatformText("1"),
|
||||||
onChanged: (newValue) {
|
|
||||||
setState(() {
|
|
||||||
_currentValue = newValue;
|
|
||||||
print(_currentValue);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
min: 1.0,
|
|
||||||
max: 100.0,
|
|
||||||
),
|
),
|
||||||
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/material.dart';
|
||||||
|
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
|
||||||
|
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:bullseye/prompt.dart';
|
import 'package:bullseye/prompt.dart';
|
||||||
import 'package:bullseye/control.dart';
|
import 'package:bullseye/control.dart';
|
||||||
import 'package:bullseye/score.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());
|
void main() => runApp(BullsEyeApp());
|
||||||
|
|
||||||
|
@ -33,6 +35,13 @@ class GamePage extends StatefulWidget {
|
||||||
|
|
||||||
class _GamePageState extends State<GamePage> {
|
class _GamePageState extends State<GamePage> {
|
||||||
bool _alertIsVisable = false;
|
bool _alertIsVisable = false;
|
||||||
|
GameModel _model = GameModel(50);
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_model = GameModel(50);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
@ -41,15 +50,15 @@ class _GamePageState extends State<GamePage> {
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
Prompt(targetValue: 100),
|
Prompt(targetValue: _model.target),
|
||||||
Control(),
|
Control(model: _model),
|
||||||
PlatformTextButton(
|
PlatformTextButton(
|
||||||
child: PlatformText('Hit me!'),
|
child: PlatformText('Hit me!'),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
this._alertIsVisable = true;
|
this._alertIsVisable = true;
|
||||||
_showAlert(context);
|
_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';
|
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
|
||||||
|
|
||||||
class Score extends StatelessWidget {
|
class Score extends StatelessWidget {
|
||||||
|
Score({Key? key, @required this.totalScore, @required this.round})
|
||||||
|
: super(key: key);
|
||||||
|
|
||||||
|
final int? totalScore;
|
||||||
|
final int? round;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Row(
|
return Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: <Widget>[
|
children: [
|
||||||
PlatformButton(
|
PlatformButton(
|
||||||
child: PlatformText("Start Over"),
|
child: PlatformText("Start Over"),
|
||||||
onPressed: () {},
|
onPressed: () {},
|
||||||
),
|
),
|
||||||
PlatformText("Score:"),
|
Padding(
|
||||||
PlatformText("999"),
|
padding: const EdgeInsets.all(8.0),
|
||||||
PlatformText("Round:"),
|
child: Row(
|
||||||
PlatformText("999"),
|
children: [
|
||||||
|
PlatformText("Score:"),
|
||||||
|
PlatformText("$totalScore"),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
PlatformText("Round:"),
|
||||||
|
PlatformText("$round"),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
PlatformButton(
|
PlatformButton(
|
||||||
child: PlatformText("Info"),
|
child: PlatformText("Info"),
|
||||||
onPressed: () {},
|
onPressed: () {},
|
||||||
|
|
Loading…
Add table
Reference in a new issue