mirror of
https://github.com/johrpan/christmas_cats.git
synced 2025-10-28 19:27:25 +01:00
Version 0.1.0
This commit is contained in:
commit
5dda59a6cd
73 changed files with 5741 additions and 0 deletions
130
lib/screens/game.dart
Normal file
130
lib/screens/game.dart
Normal file
|
|
@ -0,0 +1,130 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:sprintf/sprintf.dart';
|
||||
|
||||
import '../game.dart';
|
||||
import '../localizations.dart';
|
||||
import '../storage.dart';
|
||||
import '../widgets/transparent_route.dart';
|
||||
|
||||
import 'game_over.dart';
|
||||
import 'pause.dart';
|
||||
|
||||
class GameScreen extends StatefulWidget {
|
||||
@override
|
||||
_GameScreenState createState() => _GameScreenState();
|
||||
}
|
||||
|
||||
class _GameScreenState extends State<GameScreen> {
|
||||
int paws = 3;
|
||||
int score = 0;
|
||||
bool paused = false;
|
||||
ChristmasCats game;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final localizations = ChristmasCatsLocalizations.of(context);
|
||||
|
||||
return Scaffold(
|
||||
resizeToAvoidBottomInset: false,
|
||||
body: Stack(
|
||||
children: <Widget>[
|
||||
LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
if (game == null) {
|
||||
game = ChristmasCats(
|
||||
localizations: localizations,
|
||||
size: constraints.biggest,
|
||||
onPawsChanged: (paws) {
|
||||
setState(() {
|
||||
this.paws = paws;
|
||||
});
|
||||
},
|
||||
onScoreChanged: (score) {
|
||||
setState(() {
|
||||
this.score = score;
|
||||
});
|
||||
},
|
||||
onGameOver: () async {
|
||||
storage.addScore(score);
|
||||
|
||||
final tryAgain = await Navigator.push(
|
||||
context,
|
||||
TransparentRoute(
|
||||
builder: (context) => GameOverScreen(
|
||||
score: score,
|
||||
),
|
||||
));
|
||||
|
||||
if (tryAgain != null && tryAgain) {
|
||||
game.reset();
|
||||
game.play();
|
||||
|
||||
setState(() {
|
||||
paws = 3;
|
||||
score = 0;
|
||||
});
|
||||
} else {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
game.reset();
|
||||
game.play();
|
||||
}
|
||||
|
||||
return game.widget;
|
||||
},
|
||||
),
|
||||
Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
for (var i = 0; i < paws; i++) Icon(Icons.favorite),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Align(
|
||||
alignment: Alignment.topCenter,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(top: 16.0),
|
||||
child: Text(
|
||||
sprintf(localizations.score, [score]),
|
||||
style: TextStyle(
|
||||
fontSize: 32.0,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Align(
|
||||
alignment: Alignment.topRight,
|
||||
child: IconButton(
|
||||
icon: const Icon(Icons.pause),
|
||||
onPressed: () async {
|
||||
game.pause();
|
||||
|
||||
final unpause = await Navigator.push(
|
||||
context,
|
||||
TransparentRoute(
|
||||
builder: (context) => PauseScreen(
|
||||
score: score,
|
||||
),
|
||||
));
|
||||
|
||||
if (unpause == null || unpause) {
|
||||
game.play();
|
||||
} else {
|
||||
storage.addScore(score);
|
||||
Navigator.pop(context);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
37
lib/screens/game_over.dart
Normal file
37
lib/screens/game_over.dart
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:sprintf/sprintf.dart';
|
||||
|
||||
import '../localizations.dart';
|
||||
import '../widgets/menu.dart';
|
||||
import '../widgets/menu_entry.dart';
|
||||
|
||||
class GameOverScreen extends StatelessWidget {
|
||||
final int score;
|
||||
|
||||
GameOverScreen({
|
||||
this.score,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final localizations = ChristmasCatsLocalizations.of(context);
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: Color(0xccffffff),
|
||||
body: Menu(
|
||||
title: localizations.gameOver,
|
||||
subtitle: sprintf(localizations.score, [score]),
|
||||
children: <Widget>[
|
||||
MenuEntry(
|
||||
text: localizations.tryAgain,
|
||||
onTap: () => Navigator.pop(context, true),
|
||||
),
|
||||
MenuEntry(
|
||||
text: localizations.exit,
|
||||
onTap: () => Navigator.pop(context, false),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
82
lib/screens/home.dart
Normal file
82
lib/screens/home.dart
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
import 'package:firebase_admob/firebase_admob.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../localizations.dart';
|
||||
import '../widgets/menu.dart';
|
||||
import '../widgets/menu_entry.dart';
|
||||
|
||||
import 'game.dart';
|
||||
import 'intro.dart';
|
||||
import 'records.dart';
|
||||
|
||||
class HomeScreen extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final localizations = ChristmasCatsLocalizations.of(context);
|
||||
|
||||
return Scaffold(
|
||||
resizeToAvoidBottomInset: false,
|
||||
body: Menu(
|
||||
title: localizations.title,
|
||||
subtitle: localizations.dedication,
|
||||
children: <Widget>[
|
||||
MenuEntry(
|
||||
text: localizations.play,
|
||||
onTap: () => Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => GameScreen(),
|
||||
)),
|
||||
),
|
||||
MenuEntry(
|
||||
text: localizations.records,
|
||||
onTap: () => Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => RecordsScreen(),
|
||||
)),
|
||||
),
|
||||
MenuEntry(
|
||||
text: localizations.intro,
|
||||
onTap: () => Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => IntroScreen(),
|
||||
)),
|
||||
),
|
||||
Builder(
|
||||
builder: (context) => MenuEntry(
|
||||
text: localizations.ad,
|
||||
onTap: () {
|
||||
final ad = RewardedVideoAd.instance;
|
||||
|
||||
ad.listener = (event, {rewardAmount, rewardType}) {
|
||||
if (event == RewardedVideoAdEvent.loaded) {
|
||||
ad.show();
|
||||
} else if (event == RewardedVideoAdEvent.failedToLoad) {
|
||||
Scaffold.of(context).showSnackBar(SnackBar(
|
||||
content: Text(localizations.noAds),
|
||||
duration: const Duration(seconds: 2),
|
||||
));
|
||||
} else if (event == RewardedVideoAdEvent.rewarded) {
|
||||
// TODO: Reward user
|
||||
}
|
||||
};
|
||||
|
||||
ad.load(
|
||||
adUnitId: 'ca-app-pub-4129701777413448/6712208196',
|
||||
targetingInfo: MobileAdTargetingInfo(),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
MenuEntry(
|
||||
text: localizations.exit,
|
||||
onTap: () => SystemNavigator.pop(),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
24
lib/screens/intro.dart
Normal file
24
lib/screens/intro.dart
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../localizations.dart';
|
||||
import '../widgets/menu.dart';
|
||||
import '../widgets/menu_entry.dart';
|
||||
|
||||
class IntroScreen extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final localizations = ChristmasCatsLocalizations.of(context);
|
||||
|
||||
return Scaffold(
|
||||
body: Menu(
|
||||
title: localizations.intro,
|
||||
children: <Widget>[
|
||||
MenuEntry(
|
||||
text: localizations.poem,
|
||||
),
|
||||
],
|
||||
showBackButton: true,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
37
lib/screens/pause.dart
Normal file
37
lib/screens/pause.dart
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:sprintf/sprintf.dart';
|
||||
|
||||
import '../localizations.dart';
|
||||
import '../widgets/menu.dart';
|
||||
import '../widgets/menu_entry.dart';
|
||||
|
||||
class PauseScreen extends StatelessWidget {
|
||||
final int score;
|
||||
|
||||
PauseScreen({
|
||||
this.score,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final localizations = ChristmasCatsLocalizations.of(context);
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: Color(0xccffffff),
|
||||
body: Menu(
|
||||
title: localizations.paused,
|
||||
subtitle: sprintf(localizations.score, [score]),
|
||||
children: <Widget>[
|
||||
MenuEntry(
|
||||
text: localizations.unpause,
|
||||
onTap: () => Navigator.pop(context, true),
|
||||
),
|
||||
MenuEntry(
|
||||
text: localizations.exit,
|
||||
onTap: () => Navigator.pop(context, false),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
32
lib/screens/records.dart
Normal file
32
lib/screens/records.dart
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:sprintf/sprintf.dart';
|
||||
|
||||
import '../localizations.dart';
|
||||
import '../storage.dart';
|
||||
import '../widgets/menu.dart';
|
||||
import '../widgets/menu_entry.dart';
|
||||
|
||||
class RecordsScreen extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final localizations = ChristmasCatsLocalizations.of(context);
|
||||
|
||||
return Scaffold(
|
||||
body: Menu(
|
||||
title: localizations.records,
|
||||
children: <Widget>[
|
||||
MenuEntry(
|
||||
text: sprintf(localizations.records1, [storage.highScore1]),
|
||||
),
|
||||
MenuEntry(
|
||||
text: sprintf(localizations.records2, [storage.highScore2]),
|
||||
),
|
||||
MenuEntry(
|
||||
text: sprintf(localizations.records3, [storage.highScore3]),
|
||||
),
|
||||
],
|
||||
showBackButton: true,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue