218 lines
5.8 KiB
Dart
218 lines
5.8 KiB
Dart
import 'package:flame/game.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'src/game/iron_arc_game.dart';
|
|
|
|
void main() => runApp(const IronArcApp());
|
|
|
|
class IronArcApp extends StatelessWidget {
|
|
const IronArcApp({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
title: 'Iron Arc',
|
|
debugShowCheckedModeBanner: false,
|
|
theme: ThemeData.dark(useMaterial3: true),
|
|
home: const MatchScreen(),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// One hotseat match; restart creates a new game with a new seed.
|
|
class MatchScreen extends StatefulWidget {
|
|
const MatchScreen({super.key});
|
|
|
|
@override
|
|
State<MatchScreen> createState() => _MatchScreenState();
|
|
}
|
|
|
|
class _MatchScreenState extends State<MatchScreen> {
|
|
int _seed = 42;
|
|
late IronArcGame _game = IronArcGame(seed: _seed);
|
|
|
|
void _restart() {
|
|
setState(() {
|
|
_seed += 1;
|
|
_game = IronArcGame(seed: _seed);
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: const Color(0xFF05070A),
|
|
body: SafeArea(
|
|
child: Stack(
|
|
children: [
|
|
Positioned.fill(child: GameWidget(game: _game)),
|
|
Positioned.fill(
|
|
child: GestureDetector(
|
|
behavior: HitTestBehavior.translucent,
|
|
onPanStart: (d) => _game.beginAim(d.localPosition),
|
|
onPanUpdate: (d) => _game.updateAim(d.localPosition),
|
|
onPanEnd: (_) => _game.releaseAim(),
|
|
),
|
|
),
|
|
Positioned(
|
|
top: 8,
|
|
left: 12,
|
|
right: 12,
|
|
child: ValueListenableBuilder<HudState>(
|
|
valueListenable: _game.hud,
|
|
builder: (context, hud, _) => _Hud(hud: hud),
|
|
),
|
|
),
|
|
Positioned(
|
|
bottom: 16,
|
|
left: 16,
|
|
right: 16,
|
|
child: ValueListenableBuilder<HudState>(
|
|
valueListenable: _game.hud,
|
|
builder: (context, hud, _) => hud.isFinished
|
|
? _GameOver(hud: hud, onRestart: _restart)
|
|
: _Hint(hud: hud),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _Hud extends StatelessWidget {
|
|
const _Hud({required this.hud});
|
|
final HudState hud;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Row(
|
|
children: [
|
|
_Pill(
|
|
label: 'P1',
|
|
value: '${hud.hp0} HP',
|
|
color: const Color(0xFFFF8A3D),
|
|
active: hud.current == 0 && !hud.isFinished,
|
|
),
|
|
const SizedBox(width: 8),
|
|
Expanded(
|
|
child: Column(
|
|
children: [
|
|
Text('Zug ${hud.turn}',
|
|
style: const TextStyle(
|
|
fontSize: 13, fontWeight: FontWeight.w700)),
|
|
const SizedBox(height: 2),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
const Icon(Icons.air, size: 14),
|
|
const SizedBox(width: 4),
|
|
Text('${hud.wind > 0 ? '+' : ''}${hud.wind}',
|
|
style: const TextStyle(fontSize: 13)),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(width: 8),
|
|
_Pill(
|
|
label: 'P2',
|
|
value: '${hud.hp1} HP',
|
|
color: const Color(0xFF4DD0E1),
|
|
active: hud.current == 1 && !hud.isFinished,
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
class _Pill extends StatelessWidget {
|
|
const _Pill({
|
|
required this.label,
|
|
required this.value,
|
|
required this.color,
|
|
required this.active,
|
|
});
|
|
final String label;
|
|
final String value;
|
|
final Color color;
|
|
final bool active;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
|
decoration: BoxDecoration(
|
|
color: color.withValues(alpha: active ? 0.28 : 0.10),
|
|
borderRadius: BorderRadius.circular(10),
|
|
border: Border.all(
|
|
color: color.withValues(alpha: active ? 0.9 : 0.3),
|
|
width: active ? 2 : 1,
|
|
),
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(label,
|
|
style: TextStyle(
|
|
fontSize: 11,
|
|
color: color,
|
|
fontWeight: FontWeight.w800)),
|
|
Text(value, style: const TextStyle(fontSize: 15)),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _Hint extends StatelessWidget {
|
|
const _Hint({required this.hud});
|
|
final HudState hud;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final text = hud.phase == 1
|
|
? 'Projektil im Flug…'
|
|
: 'Ziehen zum Zielen · Loslassen zum Schießen';
|
|
return Center(
|
|
child: Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 8),
|
|
decoration: BoxDecoration(
|
|
color: const Color(0xCC0B1220),
|
|
borderRadius: BorderRadius.circular(20),
|
|
),
|
|
child: Text(text, style: const TextStyle(fontSize: 13)),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _GameOver extends StatelessWidget {
|
|
const _GameOver({required this.hud, required this.onRestart});
|
|
final HudState hud;
|
|
final VoidCallback onRestart;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final text = switch (hud.winner) {
|
|
0 => 'Spieler 1 gewinnt',
|
|
1 => 'Spieler 2 gewinnt',
|
|
_ => 'Unentschieden',
|
|
};
|
|
return Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Text(text,
|
|
style: const TextStyle(fontSize: 26, fontWeight: FontWeight.w800)),
|
|
const SizedBox(height: 12),
|
|
FilledButton.icon(
|
|
onPressed: onRestart,
|
|
icon: const Icon(Icons.refresh),
|
|
label: const Text('Neuer Match'),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|