kz_educa/lib/screens/game_screen.dart

286 lines
8.9 KiB
Dart

// lib/screens/game_screen.dart
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:kzeduca_app/providers/game_state_provider.dart';
import 'package:kzeduca_app/models/attributes.dart';
import 'package:kzeduca_app/models/game_event.dart';
import 'package:kzeduca_app/screens/player_profile_screen.dart';
import 'package:kzeduca_app/screens/game_over_screen.dart'; // Importa a tela de fim de jogo
import 'dart:math';
// Usaremos a biblioteca FontAwesome para ícones mais interessantes
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
class GameScreen extends StatelessWidget {
const GameScreen({super.key});
@override
Widget build(BuildContext context) {
return Consumer<GameStateProvider>(
builder: (context, gameState, child) {
// Verifica se o jogo terminou
if (gameState.isGameOver) {
// Navega para a tela de fim de jogo e remove a tela atual
WidgetsBinding.instance.addPostFrameCallback((_) {
Navigator.of(context).pushReplacement(
MaterialPageRoute(builder: (context) => const GameOverScreen()),
);
});
// Retorna um container vazio para evitar a renderização da tela de jogo
return const SizedBox.shrink();
}
final character = gameState.playerCharacter;
if (character == null) {
return const Center(
child: Text(
"Nenhum personagem selecionado.",
style: TextStyle(color: Colors.white),
),
);
}
final currentEvent = gameState.availableEvents.isNotEmpty
? gameState.availableEvents.first
: null;
return Scaffold(
backgroundColor: const Color(0xFF1E1C3A), // Cor de fundo principal
appBar: AppBar(
title: const Text("KzEduca",
style: TextStyle(
color: Colors.white, fontWeight: FontWeight.bold)),
backgroundColor: Colors.transparent,
elevation: 0,
actions: [
IconButton(
icon: const Icon(Icons.person, color: Colors.white),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const PlayerProfileScreen()),
);
},
),
Padding(
padding: const EdgeInsets.only(right: 16.0),
child: Center(
child: Text(
"Dia ${gameState.currentDay}",
style: const TextStyle(color: Colors.white, fontSize: 16),
),
),
),
],
),
body: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
_buildAttributesBar(character.attributes),
const SizedBox(height: 30),
Expanded(
child: currentEvent != null
? _buildEventCard(context, currentEvent, gameState)
: _buildNoEventsCard(context, gameState),
),
],
),
),
);
},
);
}
Widget _buildAttributesBar(Attributes attributes) {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
decoration: BoxDecoration(
color: const Color(0xFF2A284B),
borderRadius: BorderRadius.circular(15),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.3),
spreadRadius: 2,
blurRadius: 10,
offset: const Offset(0, 5),
),
],
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
_buildAttributeDisplay(
icon: FontAwesomeIcons.dollarSign,
label: "Dinheiro",
value: "${attributes.money.toStringAsFixed(0)} Kz",
color: Colors.greenAccent,
),
_buildAttributeDisplay(
icon: FontAwesomeIcons.heart,
label: "Saúde",
value: "${(attributes.health * 100).toStringAsFixed(0)}%",
color: Colors.redAccent,
),
_buildAttributeDisplay(
icon: FontAwesomeIcons.faceLaugh,
label: "Felicidade",
value: "${(attributes.happiness * 100).toStringAsFixed(0)}%",
color: Colors.yellowAccent,
),
],
),
);
}
Widget _buildAttributeDisplay({
required IconData icon,
required String label,
required String value,
required Color color,
}) {
return Column(
children: [
Icon(icon, color: color, size: 28),
const SizedBox(height: 4),
Text(
label,
style: const TextStyle(color: Colors.white70, fontSize: 12),
),
Text(
value,
style: TextStyle(
color: color, fontSize: 16, fontWeight: FontWeight.bold),
),
],
);
}
Widget _buildEventCard(
BuildContext context, GameEvent event, GameStateProvider gameState) {
return Container(
padding: const EdgeInsets.all(24),
decoration: BoxDecoration(
color: const Color(0xFF2A284B),
borderRadius: BorderRadius.circular(20),
boxShadow: [
BoxShadow(
color: const Color(0xFFDA70D6).withOpacity(0.2),
spreadRadius: 2,
blurRadius: 15,
offset: const Offset(0, 8),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
event.title,
style: const TextStyle(
color: Colors.white,
fontSize: 26,
fontWeight: FontWeight.bold,
shadows: [
Shadow(
blurRadius: 10.0,
color: Colors.white30,
offset: Offset(0, 0),
),
],
),
),
const SizedBox(height: 15),
Text(
event.description,
style: const TextStyle(color: Colors.white70, fontSize: 16),
),
const Spacer(),
...event.decisions.map((decision) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 10.0),
child: _buildGradientButton(
text: decision.text,
onPressed: () {
gameState.processDecision(event, decision);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(decision.consequenceText),
backgroundColor: const Color(0xFF8A2BE2),
),
);
},
),
);
}).toList(),
],
),
);
}
Widget _buildNoEventsCard(BuildContext context, GameStateProvider gameState) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
"Você não tem eventos pendentes.",
style: TextStyle(color: Colors.white, fontSize: 18),
textAlign: TextAlign.center,
),
const SizedBox(height: 20),
_buildGradientButton(
text: "Avançar",
onPressed: () {
gameState.generateNewEvent();
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text("Avançando para o próximo evento...")),
);
},
),
],
),
);
}
Widget _buildGradientButton({required String text, required VoidCallback onPressed}) {
return Container(
width: double.infinity,
decoration: BoxDecoration(
gradient: const LinearGradient(
colors: [Color(0xFF8A2BE2), Color(0xFFDA70D6)],
begin: Alignment.centerLeft,
end: Alignment.centerRight,
),
borderRadius: BorderRadius.circular(12),
boxShadow: [
BoxShadow(
color: const Color(0xFFDA70D6).withOpacity(0.5),
spreadRadius: 2,
blurRadius: 8,
offset: const Offset(0, 4),
),
],
),
child: ElevatedButton(
onPressed: onPressed,
style: ElevatedButton.styleFrom(
backgroundColor: Colors.transparent,
shadowColor: Colors.transparent,
padding: const EdgeInsets.symmetric(vertical: 18),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
),
child: Text(
text,
style: const TextStyle(
fontSize: 18, fontWeight: FontWeight.bold, color: Colors.white),
),
),
);
}
}