mirror of
https://github.com/flutter/samples.git
synced 2025-11-11 15:28:44 +00:00
Add game_template (#1180)
Adds a template / sample for games built in Flutter, with all the bells and whistles, like ads, in-app purchases, audio, main menu, settings, and so on. Co-authored-by: Parker Lougheed Co-authored-by: Shams Zakhour
This commit is contained in:
32
game_template/lib/src/game_internals/level_state.dart
Normal file
32
game_template/lib/src/game_internals/level_state.dart
Normal file
@@ -0,0 +1,32 @@
|
||||
// Copyright 2022, the Flutter project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
/// An extremely silly example of a game state.
|
||||
///
|
||||
/// Tracks only a single variable, [progress], and calls [onWin] when
|
||||
/// the value of [progress] reaches [goal].
|
||||
class LevelState extends ChangeNotifier {
|
||||
final VoidCallback onWin;
|
||||
|
||||
final int goal;
|
||||
|
||||
LevelState({required this.onWin, this.goal = 100});
|
||||
|
||||
int _progress = 0;
|
||||
|
||||
int get progress => _progress;
|
||||
|
||||
void setProgress(int value) {
|
||||
_progress = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void evaluate() {
|
||||
if (_progress >= goal) {
|
||||
onWin();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user