Compare commits

..

No commits in common. "8cca5a64dee20fa8158bb7d47e8d927c1a9cdbef" and "6592b3575599271765be1c08f6d2cfb01cebb49e" have entirely different histories.

6 changed files with 69 additions and 463 deletions

View File

@ -101,12 +101,4 @@ class PokedexDatabase {
int count = result.isNotEmpty ? (result.first.values.first as int? ?? 0) : 0; int count = result.isNotEmpty ? (result.first.values.first as int? ?? 0) : 0;
return count; return count;
} }
// Obtenir le nombre de pokémon vus
static Future<int> getSeenCount() async {
Database database = await getDatabase();
var result = await database.rawQuery("SELECT COUNT(*) FROM pokemon WHERE isSeen = 1");
int count = result.isNotEmpty ? (result.first.values.first as int? ?? 0) : 0;
return count;
}
} }

View File

@ -4,7 +4,6 @@ import 'pages/pokemon_detail.dart';
import 'pages/main_page.dart'; import 'pages/main_page.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:google_fonts/google_fonts.dart';
import 'package:sqflite_common_ffi/sqflite_ffi.dart'; import 'package:sqflite_common_ffi/sqflite_ffi.dart';
import 'pages/game_over_page.dart';
void main() { void main() {
WidgetsFlutterBinding.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized();
@ -40,7 +39,6 @@ class MyApp extends StatelessWidget {
routes: { routes: {
'/': (context) => const MainPage(), // La route "/" est la page d'accueil avec BottomNav '/': (context) => const MainPage(), // La route "/" est la page d'accueil avec BottomNav
'/pokemon-detail':(context) => const PokemonDetailPage(), '/pokemon-detail':(context) => const PokemonDetailPage(),
'/game-over': (context) => const GameOverPage(),
} }
); );
} }

View File

@ -1,302 +0,0 @@
import 'package:flutter/material.dart';
import '../database/pokedex_database.dart';
class GameOverPage extends StatefulWidget {
const GameOverPage({Key? key}) : super(key: key);
@override
State<GameOverPage> createState() => _GameOverPageState();
}
class _GameOverPageState extends State<GameOverPage> {
int _seenCount = 0;
bool _isLoading = true;
@override
void initState() {
super.initState();
_loadSeenCount();
}
Future<void> _loadSeenCount() async {
int count = await PokedexDatabase.getSeenCount();
if (mounted) {
setState(() {
_seenCount = count;
_isLoading = false;
});
}
}
@override
Widget build(BuildContext context) {
final Map<String, dynamic>? args =
ModalRoute.of(context)!.settings.arguments as Map<String, dynamic>?;
final String pokemonImage = args?['pokemonImage'] ?? '';
final String pokemonName = args?['pokemonName'] ?? 'Unknown';
final int streak = args?['streak'] ?? 0;
// Pad streak with zeroes to 3 digits as in mockup (e.g. 004)
final String streakText = streak.toString().padLeft(3, '0');
// Define color palette from mockup
const Color pokedexRed = Color(0xFFD32F2F);
const Color darkRed = Color(0xFF9E1B1B);
const Color silverBg = Color(0xFFC8D1D8);
const Color messageBoxBg = Color(0xFF1B2333);
const Color statBoxBg = Color(0xFFD9E0E5); // slightly lighter/different silver for stats
const Color tryAgainBtn = Color(0xFF2962FF); // Blue
const Color backBtn = Color(0xFFA66A00); // Brown
return Scaffold(
backgroundColor: pokedexRed,
body: _isLoading
? const Center(child: CircularProgressIndicator(color: Colors.white))
: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
// Top Box: Pokemon Silhouette & GAME OVER
Container(
decoration: BoxDecoration(
color: darkRed, // Border color
border: Border.all(color: darkRed, width: 4),
),
child: Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(vertical: 32, horizontal: 16),
color: silverBg,
child: Column(
children: [
// GAME OVER Banner
Container(
color: darkRed,
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 8),
child: const Text(
"GAME OVER",
style: TextStyle(
fontSize: 26,
color: Colors.yellow,
fontWeight: FontWeight.bold,
letterSpacing: 2,
shadows: [
Shadow(
offset: Offset(1.5, 1.5),
color: Colors.black,
),
],
),
),
),
const SizedBox(height: 16),
// Pokemon Image and Name
if (pokemonImage.isNotEmpty)
SizedBox(
height: 140,
child: Image.network(pokemonImage, fit: BoxFit.contain),
),
const SizedBox(height: 12),
Text(
"It was $pokemonName!",
textAlign: TextAlign.center,
style: const TextStyle(
fontSize: 22,
fontWeight: FontWeight.bold,
color: Color(0xFF1B2333),
letterSpacing: 1,
),
),
const SizedBox(height: 8),
],
),
),
),
// Divider between boxes
Padding(
padding: const EdgeInsets.symmetric(vertical: 24.0),
child: Row(
children: [
Expanded(
child: Container(height: 2, color: darkRed),
),
const SizedBox(width: 8),
Row(
mainAxisSize: MainAxisSize.min,
children: List.generate(3, (index) =>
Container(
width: 8,
height: 8,
margin: const EdgeInsets.symmetric(horizontal: 4),
decoration: const BoxDecoration(
color: darkRed,
shape: BoxShape.circle,
),
)
),
),
const SizedBox(width: 8),
Expanded(
child: Container(height: 2, color: darkRed),
),
],
),
),
// Bottom Box: Message, Stats, Buttons
Container(
decoration: BoxDecoration(
color: darkRed,
border: Border.all(color: darkRed, width: 4),
),
child: Container(
width: double.infinity,
padding: const EdgeInsets.all(16),
color: silverBg,
child: Column(
children: [
// Message Box
Container(
width: double.infinity,
color: messageBoxBg,
padding: const EdgeInsets.all(24),
child: const Text(
"\"Looks like your journey\nends here. You've run out\nof energy!\"",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.normal,
height: 1.5,
),
),
),
const SizedBox(height: 16),
// Stats Row
Row(
children: [
Expanded(
child: Container(
color: statBoxBg,
padding: const EdgeInsets.symmetric(vertical: 12),
child: Column(
children: [
const Text(
"STREAK",
style: TextStyle(
color: Colors.red,
fontSize: 10,
fontWeight: FontWeight.bold,
letterSpacing: 1,
),
),
const SizedBox(height: 4),
Text(
streakText,
style: const TextStyle(
color: Colors.black,
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
],
),
),
),
const SizedBox(width: 16),
Expanded(
child: Container(
color: statBoxBg,
padding: const EdgeInsets.symmetric(vertical: 12),
child: Column(
children: [
const Text(
"SEEN",
style: TextStyle(
color: Colors.red,
fontSize: 10,
fontWeight: FontWeight.bold,
letterSpacing: 1,
),
),
const SizedBox(height: 4),
Text(
"$_seenCount/1025", // Gen 9 total
style: const TextStyle(
color: Colors.black,
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
],
),
),
),
],
),
const SizedBox(height: 16),
// Try Again Button
SizedBox(
width: double.infinity,
height: 60,
child: ElevatedButton.icon(
onPressed: () {
Navigator.pop(context, true);
},
icon: const Icon(Icons.refresh, color: Colors.white, size: 24),
label: const Text(
"TRY AGAIN",
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold,
letterSpacing: 2,
),
),
style: ElevatedButton.styleFrom(
backgroundColor: tryAgainBtn,
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.zero),
),
),
),
const SizedBox(height: 16),
// Back to Pokedex Button
SizedBox(
width: double.infinity,
height: 60,
child: ElevatedButton.icon(
onPressed: () {
Navigator.pop(context, false);
},
icon: const Icon(Icons.menu_book, color: Colors.white, size: 24),
label: const Text(
"BACK TO POKEDEX",
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold,
letterSpacing: 2,
),
),
style: ElevatedButton.styleFrom(
backgroundColor: backBtn,
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.zero),
),
),
),
],
),
),
),
],
),
),
),
);
}
}

View File

@ -3,7 +3,6 @@ import 'dart:math';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import '../models/pokemon.dart'; import '../models/pokemon.dart';
import '../database/pokedex_database.dart'; import '../database/pokedex_database.dart';
import 'main_page.dart';
class GuessPage extends StatefulWidget { class GuessPage extends StatefulWidget {
const GuessPage({Key? key}) : super(key: key); const GuessPage({Key? key}) : super(key: key);
@ -16,10 +15,6 @@ class _GuessPageState extends State<GuessPage> {
Pokemon? _currentPokemon; Pokemon? _currentPokemon;
final TextEditingController _guessController = TextEditingController(); final TextEditingController _guessController = TextEditingController();
int _lives = 3; int _lives = 3;
int _skips = 3;
int _hints = 3;
int _sessionCorrectCount = 0;
bool _isGuessed = false;
bool _isLoading = true; bool _isLoading = true;
bool _isHintUsed = false; bool _isHintUsed = false;
bool _isShiny = false; bool _isShiny = false;
@ -30,17 +25,6 @@ class _GuessPageState extends State<GuessPage> {
void initState() { void initState() {
super.initState(); super.initState();
_loadBestScore(); _loadBestScore();
_startNewGame();
}
void _startNewGame() {
setState(() {
_lives = 3;
_skips = 3;
_hints = 3;
_sessionCorrectCount = 0;
_currentScore = 0;
});
_loadRandomPokemon(); _loadRandomPokemon();
} }
@ -64,7 +48,7 @@ class _GuessPageState extends State<GuessPage> {
Future<void> _loadRandomPokemon() async { Future<void> _loadRandomPokemon() async {
setState(() { setState(() {
_isLoading = true; _isLoading = true;
_isGuessed = false; _lives = 3;
_isHintUsed = false; _isHintUsed = false;
_isShiny = Random().nextInt(10) == 0; // 10% chance for shiny _isShiny = Random().nextInt(10) == 0; // 10% chance for shiny
_guessController.clear(); _guessController.clear();
@ -126,10 +110,6 @@ class _GuessPageState extends State<GuessPage> {
if (mounted) { if (mounted) {
setState(() { setState(() {
_currentScore += _isShiny ? 20 : 10; _currentScore += _isShiny ? 20 : 10;
_isGuessed = true;
_sessionCorrectCount++;
if (_sessionCorrectCount % 5 == 0) _hints++;
if (_sessionCorrectCount % 10 == 0) _skips++;
}); });
} }
await _saveBestScore(); await _saveBestScore();
@ -143,7 +123,9 @@ class _GuessPageState extends State<GuessPage> {
backgroundColor: _isShiny ? Colors.amber[800] : Colors.green backgroundColor: _isShiny ? Colors.amber[800] : Colors.green
), ),
); );
// Wait for user to click Continue
// Load next
_loadRandomPokemon();
} else { } else {
// Wrong // Wrong
if (mounted) { if (mounted) {
@ -153,28 +135,17 @@ class _GuessPageState extends State<GuessPage> {
} }
if (_lives <= 0) { if (_lives <= 0) {
if (!mounted) return; if (mounted) {
final bool? playAgain = await Navigator.pushNamed( setState(() {
context, _currentScore = 0; // Reset score only when all lives are lost
'/game-over', });
arguments: {
'pokemonName': _currentPokemon!.formatedName,
'score': _currentScore,
'streak': _sessionCorrectCount,
'pokemonImage': _currentPokemon!.imageUrl,
},
) as bool?;
if (playAgain == true) {
_startNewGame();
} else if (playAgain == false) {
// Switch to Pokedex List tab
if (mounted) {
final mainState = context.findAncestorStateOfType<MainPageState>();
mainState?.setIndex(0); // Index 0 is Pokemon List
_startNewGame(); // Reset game state for next time
}
} }
if (!mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Out of lives! It was ${_currentPokemon!.formatedName}.'), backgroundColor: Colors.red),
);
// Load next
_loadRandomPokemon();
} else { } else {
if (!mounted) return; if (!mounted) return;
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
@ -185,20 +156,17 @@ class _GuessPageState extends State<GuessPage> {
} }
void _useHint() { void _useHint() {
if (_currentPokemon == null || _isHintUsed || _hints <= 0) return; if (_currentPokemon == null || _isHintUsed) return;
setState(() { setState(() {
_isHintUsed = true; _isHintUsed = true;
_hints--; // Provide a hint like replacing some characters with underscores, or telling type
// For simplicity, we put the first letter and last letter
}); });
} String name = _currentPokemon!.formatedName;
String hint = '${name[0]}${List.filled(name.length - 2, '_').join()}${name[name.length - 1]}';
void _useSkip() { ScaffoldMessenger.of(context).showSnackBar(
if (_skips > 0) { SnackBar(content: Text('Hint: $hint'), duration: const Duration(seconds: 4)),
setState(() { );
_skips--;
});
_loadRandomPokemon();
}
} }
String _normalizeString(String input) { String _normalizeString(String input) {
@ -257,15 +225,13 @@ class _GuessPageState extends State<GuessPage> {
Expanded( Expanded(
child: Padding( child: Padding(
padding: const EdgeInsets.all(16.0), padding: const EdgeInsets.all(16.0),
child: _isGuessed child: ColorFiltered(
? Image.network(_currentPokemon!.imageUrl, fit: BoxFit.contain) colorFilter: ColorFilter.mode(
: ColorFiltered( _isShiny ? Colors.yellow[700]! : Colors.black,
colorFilter: ColorFilter.mode( BlendMode.srcIn
_isShiny ? Colors.yellow[700]! : Colors.black, ),
BlendMode.srcIn child: Image.network(_currentPokemon!.imageUrl, fit: BoxFit.contain),
), ),
child: Image.network(_currentPokemon!.imageUrl, fit: BoxFit.contain),
),
), ),
), ),
Container( Container(
@ -311,22 +277,6 @@ class _GuessPageState extends State<GuessPage> {
style: TextStyle(color: Colors.black54, fontSize: 12, fontWeight: FontWeight.bold), style: TextStyle(color: Colors.black54, fontSize: 12, fontWeight: FontWeight.bold),
), ),
const SizedBox(height: 4), const SizedBox(height: 4),
if (_isHintUsed && _currentPokemon != null)
Container(
width: double.infinity,
margin: const EdgeInsets.only(bottom: 12),
padding: const EdgeInsets.symmetric(vertical: 12),
decoration: BoxDecoration(
color: Colors.amber[100],
border: Border.all(color: Colors.amber[600]!, width: 2),
borderRadius: BorderRadius.circular(8),
),
child: Text(
"HINT: ${_currentPokemon!.formatedName[0]}${List.filled(_currentPokemon!.formatedName.length - 2, '_').join()}${_currentPokemon!.formatedName[_currentPokemon!.formatedName.length - 1]}",
textAlign: TextAlign.center,
style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold, color: Colors.amber[900], letterSpacing: 4),
),
),
Container( Container(
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.white, color: Colors.white,
@ -344,69 +294,51 @@ class _GuessPageState extends State<GuessPage> {
), ),
), ),
const SizedBox(height: 16), const SizedBox(height: 16),
if (_isGuessed) SizedBox(
SizedBox( width: double.infinity,
width: double.infinity, height: 60,
height: 60, child: ElevatedButton(
child: ElevatedButton( onPressed: _checkGuess,
onPressed: _loadRandomPokemon, style: ElevatedButton.styleFrom(
style: ElevatedButton.styleFrom( backgroundColor: const Color(0xFF3B6EE3),
backgroundColor: Colors.green, shape: const RoundedRectangleBorder(borderRadius: BorderRadius.zero),
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.zero),
),
child: const Text(
"CONTINUE",
style: TextStyle(fontSize: 24, color: Colors.white, fontWeight: FontWeight.bold, letterSpacing: 2),
),
), ),
) child: const Text(
else ...[ "GUESS!",
SizedBox( style: TextStyle(fontSize: 24, color: Colors.white, fontWeight: FontWeight.bold, letterSpacing: 2),
width: double.infinity,
height: 60,
child: ElevatedButton(
onPressed: _checkGuess,
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF3B6EE3),
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.zero),
),
child: const Text(
"GUESS!",
style: TextStyle(fontSize: 24, color: Colors.white, fontWeight: FontWeight.bold, letterSpacing: 2),
),
), ),
), ),
const SizedBox(height: 16), ),
Row( const SizedBox(height: 16),
children: [ Row(
Expanded( children: [
child: ElevatedButton.icon( Expanded(
onPressed: (_isHintUsed || _hints <= 0) ? null : _useHint, child: ElevatedButton.icon(
icon: const Icon(Icons.lightbulb, color: Colors.black87), onPressed: _isHintUsed ? null : _useHint,
label: Text("HINT ($_hints)", style: const TextStyle(color: Colors.black87, fontWeight: FontWeight.bold, fontSize: 18)), icon: const Icon(Icons.lightbulb, color: Colors.black87),
style: ElevatedButton.styleFrom( label: const Text("HINT", style: TextStyle(color: Colors.black87, fontWeight: FontWeight.bold, fontSize: 18)),
backgroundColor: Colors.amber, style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(vertical: 16), backgroundColor: Colors.amber,
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.zero), padding: const EdgeInsets.symmetric(vertical: 16),
), shape: const RoundedRectangleBorder(borderRadius: BorderRadius.zero),
), ),
), ),
const SizedBox(width: 8), ),
Expanded( const SizedBox(width: 8),
child: ElevatedButton.icon( Expanded(
onPressed: _skips > 0 ? _useSkip : null, child: ElevatedButton.icon(
icon: const Icon(Icons.skip_next, color: Colors.black87), onPressed: _loadRandomPokemon,
label: Text("SKIP ($_skips)", style: const TextStyle(color: Colors.black87, fontWeight: FontWeight.bold, fontSize: 18)), icon: const Icon(Icons.skip_next, color: Colors.black87),
style: ElevatedButton.styleFrom( label: const Text("SKIP", style: TextStyle(color: Colors.black87, fontWeight: FontWeight.bold, fontSize: 18)),
backgroundColor: Colors.grey[400], style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(vertical: 16), backgroundColor: Colors.grey[400],
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.zero), padding: const EdgeInsets.symmetric(vertical: 16),
), shape: const RoundedRectangleBorder(borderRadius: BorderRadius.zero),
), ),
), ),
], ),
), ],
], ),
const SizedBox(height: 24), const SizedBox(height: 24),
// Score Display // Score Display

View File

@ -6,18 +6,12 @@ class MainPage extends StatefulWidget {
const MainPage({Key? key}) : super(key: key); const MainPage({Key? key}) : super(key: key);
@override @override
State<MainPage> createState() => MainPageState(); State<MainPage> createState() => _MainPageState();
} }
class MainPageState extends State<MainPage> { class _MainPageState extends State<MainPage> {
int _currentIndex = 0; int _currentIndex = 0;
void setIndex(int index) {
setState(() {
_currentIndex = index;
});
}
final List<Widget> _pages = [ final List<Widget> _pages = [
const PokemonListPage(), const PokemonListPage(),
const GuessPage(), const GuessPage(),

View File

@ -1,8 +0,0 @@
{
"folders": [
{
"path": "../.."
}
],
"settings": {}
}