Commit 206a2efd authored by ghstLovrS's avatar ghstLovrS

games intergration

parent a520a579
import 'package:flutter/material.dart';
import 'package:jema_app/game1/the_memory_match_game.dart';
void main() {
runApp(
const TheMemoryMatchGame(),
);
}
import 'package:flutter/material.dart';
enum CardState { hidden, visible, guessed }
class CardItem {
CardItem({
required this.value,
required this.icon,
required this.color,
this.state = CardState.hidden,
});
final int value;
final IconData icon;
final Color color;
CardState state;
}
import 'dart:async';
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:jema_app/game1/models/card_item.dart';
import 'package:jema_app/game1/utils/icons.dart';
class Game {
Game(this.gridSize) {
generateCards();
}
final int gridSize;
List<CardItem> cards = [];
bool isGameOver = false;
Set<IconData> icons = {};
void generateCards() {
generateIcons();
cards = [];
final List<Color> cardColors = Colors.primaries.toList();
for (int i = 0; i < (gridSize * gridSize / 2); i++) {
final cardValue = i + 1;
final IconData icon = icons.elementAt(i);
final Color cardColor = cardColors[i % cardColors.length];
final List<CardItem> newCards =
_createCardItems(icon, cardColor, cardValue);
cards.addAll(newCards);
}
cards.shuffle(Random());
}
void generateIcons() {
icons = <IconData>{};
for (int j = 0; j < (gridSize * gridSize / 2); j++) {
final IconData icon = _getRandomCardIcon();
icons.add(icon);
icons.add(icon); // Add the icon twice to ensure pairs are generated.
}
}
void resetGame() {
generateCards();
isGameOver = false;
}
void onCardPressed(int index) {
cards[index].state = CardState.visible;
final List<int> visibleCardIndexes = _getVisibleCardIndexes();
if (visibleCardIndexes.length == 2) {
final CardItem card1 = cards[visibleCardIndexes[0]];
final CardItem card2 = cards[visibleCardIndexes[1]];
if (card1.value == card2.value) {
card1.state = CardState.guessed;
card2.state = CardState.guessed;
isGameOver = _isGameOver();
} else {
Future.delayed(const Duration(milliseconds: 1000), () {
card1.state = CardState.hidden;
card2.state = CardState.hidden;
});
}
}
}
List<CardItem> _createCardItems(
IconData icon, Color cardColor, int cardValue) {
return List.generate(
2,
(index) => CardItem(
value: cardValue,
icon: icon,
color: cardColor,
),
);
}
IconData _getRandomCardIcon() {
final Random random = Random();
IconData icon;
do {
icon = cardIcons[random.nextInt(cardIcons.length)];
} while (icons.contains(icon));
return icon;
}
List<int> _getVisibleCardIndexes() {
return cards
.asMap()
.entries
.where((entry) => entry.value.state == CardState.visible)
.map((entry) => entry.key)
.toList();
}
bool _isGameOver() {
return cards.every((card) => card.state == CardState.guessed);
}
}
import 'package:flutter/material.dart';
import 'package:jema_app/game1/ui/pages/startup_page.dart';
class TheMemoryMatchGame extends StatelessWidget {
const TheMemoryMatchGame({
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
home: const StartUpPage(),
title: 'Memory Match',
theme: ThemeData.dark(),
debugShowCheckedModeBanner: false,
);
}
}
import 'package:flutter/material.dart';
import 'package:jema_app/game1/ui/widgets/web/game_board.dart';
import 'package:jema_app/game1/ui/widgets/mobile/game_board_mobile.dart';
class MemoryMatchPage extends StatelessWidget {
const MemoryMatchPage({
required this.gameLevel,
super.key,
});
final int gameLevel;
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: LayoutBuilder(
builder: ((context, constraints) {
if (constraints.maxWidth > 720) {
return GameBoard(
gameLevel: gameLevel,
);
} else {
return GameBoardMobile(
gameLevel: gameLevel,
);
}
}),
),
),
);
}
}
//startup_page.dart
import 'package:flutter/material.dart';
import 'package:jema_app/game1/ui/widgets/game_options.dart';
import 'package:jema_app/game1/utils/constants.dart';
import 'package:jema_app/games.dart';
class StartUpPage extends StatelessWidget {
const StartUpPage({Key? key}) : super(key: key); // Fix super key
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
gameTitle,
style: TextStyle(fontSize: 24, color: Colors.white),
),
GameOptions(),
ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => GamesPage()),
);
},
child: Text('Quit'), // Add quit button
),
],
),
),
),
);
}
}
import 'package:flutter/material.dart';
class GameButton extends StatelessWidget {
const GameButton({
required this.title,
required this.onPressed,
required this.color,
this.height = 40,
this.width = double.infinity,
this.fontSize = 18,
Key? key,
}) : super(key: key);
final String title;
final VoidCallback onPressed;
final Color color;
final double height;
final double width;
final double fontSize;
@override
Widget build(BuildContext context) {
return SizedBox(
height: height,
width: width,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: color,
textStyle: TextStyle(fontSize: fontSize),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(height / 2),
),
),
),
onPressed: onPressed,
child: Text(title),
),
);
}
}
import 'package:confetti/confetti.dart';
import 'package:flutter/material.dart';
class GameConfetti extends StatefulWidget {
const GameConfetti({
super.key,
});
@override
State<GameConfetti> createState() => _GameConfettiState();
}
class _GameConfettiState extends State<GameConfetti> {
final controllerCenter =
ConfettiController(duration: const Duration(seconds: 10));
@override
void initState() {
super.initState();
controllerCenter.play();
}
@override
void dispose() {
controllerCenter.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Align(
alignment: Alignment.topCenter,
child: ConfettiWidget(
confettiController: controllerCenter,
blastDirectionality: BlastDirectionality.explosive,
shouldLoop: false,
gravity: 0.5,
emissionFrequency: 0.05,
numberOfParticles: 20,
colors: const [
Colors.green,
Colors.blue,
Colors.pink,
Colors.orange,
Colors.purple
],
),
);
}
}
import 'package:flutter/material.dart';
import 'package:jema_app/game1/ui/pages/startup_page.dart';
import 'package:jema_app/game1/ui/widgets/game_button.dart';
import 'package:jema_app/game1/utils/constants.dart';
class GameControlsBottomSheet extends StatelessWidget {
const GameControlsBottomSheet({
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(20),
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Center(
child: Text(
'PAUSE',
style: TextStyle(fontSize: 24, color: Colors.white),
),
),
const SizedBox(height: 10),
GameButton(
onPressed: () => Navigator.of(context).pop(false),
title: 'CONTINUE',
color: continueButtonColor,
width: 200,
),
const SizedBox(height: 10),
GameButton(
onPressed: () => Navigator.of(context).pop(true),
title: 'RESTART',
color: restartButtonColor,
width: 200,
),
const SizedBox(height: 10),
GameButton(
onPressed: () {
Navigator.of(context).pushAndRemoveUntil(
MaterialPageRoute(
builder: (BuildContext context) {
return const StartUpPage();
},
),
(Route<dynamic> route) => false,
);
},
title: 'QUIT',
color: quitButtonColor,
width: 200,
),
const SizedBox(height: 20),
],
),
);
}
}
import 'package:flutter/material.dart';
import 'package:jema_app/game1/ui/pages/memory_match_page.dart';
import 'package:jema_app/game1/ui/widgets/game_button.dart';
import 'package:jema_app/game1/utils/constants.dart';
class GameOptions extends StatelessWidget {
const GameOptions({
super.key,
});
static Route<dynamic> _routeBuilder(BuildContext context, int gameLevel) {
return MaterialPageRoute(
builder: (_) {
return MemoryMatchPage(gameLevel: gameLevel);
},
);
}
@override
Widget build(BuildContext context) {
return Column(
children: gameLevels.map((level) {
return Padding(
padding: const EdgeInsets.all(10.0),
child: GameButton(
onPressed: () => Navigator.of(context).pushAndRemoveUntil(
_routeBuilder(context, level['level']),
(Route<dynamic> route) => false),
title: level['title'],
color: level['color']![700]!,
width: 250,
),
);
}).toList(),
);
}
}
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:jema_app/game1/models/card_item.dart';
class MemoryCard extends StatelessWidget {
const MemoryCard({
required this.card,
required this.index,
required this.onCardPressed,
super.key,
});
final CardItem card;
final int index;
final ValueChanged<int> onCardPressed;
void _handleCardTap() {
if (card.state == CardState.hidden) {
Timer(const Duration(milliseconds: 100), () {
onCardPressed(index);
});
}
}
@override
Widget build(BuildContext context) {
return InkWell(
onTap: _handleCardTap,
child: Card(
elevation: 8,
clipBehavior: Clip.antiAlias,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
color:
card.state == CardState.visible || card.state == CardState.guessed
? card.color
: Colors.grey,
child: Center(
child: card.state == CardState.hidden
? null
: SizedBox.expand(
child: FittedBox(
child: Icon(
card.icon,
color: Colors.white,
),
),
),
),
),
);
}
}
import 'package:flutter/material.dart';
class GameBestTimeMobile extends StatelessWidget {
const GameBestTimeMobile({
required this.bestTime,
super.key,
});
final int bestTime;
@override
Widget build(BuildContext context) {
return Card(
margin: const EdgeInsets.symmetric(
vertical: 50,
horizontal: 60,
),
elevation: 8,
clipBehavior: Clip.antiAlias,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15),
),
color: Colors.greenAccent[700],
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
const Expanded(
flex: 1,
child: Icon(
Icons.celebration,
size: 40,
),
),
Expanded(
flex: 2,
child: Text(
textAlign: TextAlign.center,
Duration(seconds: bestTime)
.toString()
.split('.')
.first
.padLeft(8, "0"),
style: const TextStyle(
fontSize: 28.0,
fontWeight: FontWeight.bold,
),
),
),
],
),
),
);
}
}
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:jema_app/game1/models/game.dart';
import 'package:jema_app/game1/ui/widgets/game_confetti.dart';
import 'package:jema_app/game1/ui/widgets/memory_card.dart';
import 'package:jema_app/game1/ui/widgets/mobile/game_best_time_mobile.dart';
import 'package:jema_app/game1/ui/widgets/mobile/game_timer_mobile.dart';
import 'package:jema_app/game1/ui/widgets/restart_game.dart';
class GameBoardMobile extends StatefulWidget {
const GameBoardMobile({
required this.gameLevel,
super.key,
});
final int gameLevel;
@override
State<GameBoardMobile> createState() => _GameBoardMobileState();
}
class _GameBoardMobileState extends State<GameBoardMobile> {
late Timer timer;
late Game game;
late Duration duration;
int bestTime = 0;
bool showConfetti = false;
@override
void initState() {
super.initState();
game = Game(widget.gameLevel);
duration = const Duration();
startTimer();
getBestTime();
}
void getBestTime() async {
SharedPreferences gameSP = await SharedPreferences.getInstance();
if (gameSP.getInt('${widget.gameLevel.toString()}BestTime') != null) {
bestTime = gameSP.getInt('${widget.gameLevel.toString()}BestTime')!;
}
setState(() {});
}
startTimer() {
timer = Timer.periodic(const Duration(seconds: 1), (_) async {
setState(() {
final seconds = duration.inSeconds + 1;
duration = Duration(seconds: seconds);
});
if (game.isGameOver) {
timer.cancel();
SharedPreferences gameSP = await SharedPreferences.getInstance();
if (gameSP.getInt('${widget.gameLevel.toString()}BestTime') == null ||
gameSP.getInt('${widget.gameLevel.toString()}BestTime')! >
duration.inSeconds) {
gameSP.setInt(
'${widget.gameLevel.toString()}BestTime', duration.inSeconds);
setState(() {
showConfetti = true;
bestTime = duration.inSeconds;
});
}
}
});
}
pauseTimer() {
timer.cancel();
}
void _resetGame() {
game.resetGame();
setState(() {
timer.cancel();
duration = const Duration();
startTimer();
});
}
@override
Widget build(BuildContext context) {
final aspectRatio = MediaQuery.of(context).size.aspectRatio;
return SafeArea(
child: Stack(
children: [
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const SizedBox(
height: 20,
),
RestartGame(
isGameOver: game.isGameOver,
pauseGame: () => pauseTimer(),
restartGame: () => _resetGame(),
continueGame: () => startTimer(),
color: Colors.amberAccent[700]!,
),
GameTimerMobile(
time: duration,
),
Expanded(
child: GridView.count(
crossAxisCount: game.gridSize,
childAspectRatio: aspectRatio * 2,
children: List.generate(game.cards.length, (index) {
return MemoryCard(
index: index,
card: game.cards[index],
onCardPressed: game.onCardPressed,
);
}),
),
),
GameBestTimeMobile(
bestTime: bestTime,
),
],
),
showConfetti ? const GameConfetti() : const SizedBox(),
],
),
);
}
}
import 'package:flutter/material.dart';
class GameTimerMobile extends StatelessWidget {
const GameTimerMobile({
required this.time,
super.key,
});
final Duration time;
@override
Widget build(BuildContext context) {
return Card(
margin: const EdgeInsets.symmetric(
vertical: 20,
horizontal: 60,
),
elevation: 8,
clipBehavior: Clip.antiAlias,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15),
),
color: Colors.red[700],
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
const Expanded(
flex: 1,
child: Icon(
Icons.timer,
size: 40,
),
),
Expanded(
flex: 2,
child: Text(
textAlign: TextAlign.center,
time.toString().split('.').first.padLeft(8, "0"),
style: const TextStyle(
fontSize: 28.0,
fontWeight: FontWeight.bold,
),
),
),
],
),
),
);
}
}
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:jema_app/game1/ui/pages/startup_page.dart';
import 'package:jema_app/game1/ui/widgets/game_controls_bottomsheet.dart';
class RestartGame extends StatelessWidget {
const RestartGame({
required this.isGameOver,
required this.pauseGame,
required this.restartGame,
required this.continueGame,
this.color = Colors.white,
super.key,
});
final VoidCallback pauseGame;
final VoidCallback restartGame;
final VoidCallback continueGame;
final bool isGameOver;
final Color color;
Future<void> showGameControls(BuildContext context) async {
pauseGame();
var value = await showModalBottomSheet<bool>(
isScrollControlled: true,
elevation: 5,
context: context,
builder: (sheetContext) {
return const GameControlsBottomSheet();
},
);
value ??= false;
if (value) {
restartGame();
} else {
continueGame();
}
}
void navigateback(BuildContext context) {
Navigator.of(context).pushAndRemoveUntil(
MaterialPageRoute(builder: (BuildContext context) {
return const StartUpPage();
}), (Route<dynamic> route) => false);
}
@override
Widget build(BuildContext context) {
return IconButton(
color: color,
icon: (isGameOver)
? const Icon(Icons.replay_circle_filled)
: const Icon(Icons.pause_circle_filled),
iconSize: 40,
onPressed: () =>
isGameOver ? navigateback(context) : showGameControls(context),
);
}
}
import 'package:flutter/material.dart';
class GameBestTime extends StatelessWidget {
const GameBestTime({
required this.bestTime,
super.key,
});
final int bestTime;
@override
Widget build(BuildContext context) {
return Text(
'Best: ${Duration(seconds: bestTime).toString().split('.').first.padLeft(8, "0")}',
textAlign: TextAlign.center,
style: const TextStyle(fontSize: 24.0, fontWeight: FontWeight.bold),
);
}
}
import 'dart:async';
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:jema_app/game1/models/game.dart';
import 'package:jema_app/game1/ui/widgets/game_confetti.dart';
import 'package:jema_app/game1/ui/widgets/memory_card.dart';
import 'package:jema_app/game1/ui/widgets/restart_game.dart';
import 'package:jema_app/game1/ui/widgets/web/game_best_time.dart';
import 'package:jema_app/game1/ui/widgets/web/game_timer.dart';
class GameBoard extends StatefulWidget {
const GameBoard({
required this.gameLevel,
super.key,
});
final int gameLevel;
@override
State<GameBoard> createState() => _GameBoardState();
}
class _GameBoardState extends State<GameBoard> {
late Timer timer;
late Game game;
late Duration duration;
int bestTime = 0;
bool showConfetti = false;
@override
void initState() {
super.initState();
game = Game(widget.gameLevel);
duration = const Duration();
startTimer();
getBestTime();
}
void getBestTime() async {
SharedPreferences gameSP = await SharedPreferences.getInstance();
if (gameSP.getInt('${widget.gameLevel.toString()}BestTime') != null) {
bestTime = gameSP.getInt('${widget.gameLevel.toString()}BestTime')!;
}
setState(() {});
}
startTimer() {
timer = Timer.periodic(const Duration(seconds: 1), (_) async {
setState(() {
final seconds = duration.inSeconds + 1;
duration = Duration(seconds: seconds);
});
if (game.isGameOver) {
timer.cancel();
SharedPreferences gameSP = await SharedPreferences.getInstance();
if (gameSP.getInt('${widget.gameLevel.toString()}BestTime') == null ||
gameSP.getInt('${widget.gameLevel.toString()}BestTime')! >
duration.inSeconds) {
gameSP.setInt(
'${widget.gameLevel.toString()}BestTime', duration.inSeconds);
setState(() {
showConfetti = true;
bestTime = duration.inSeconds;
});
}
}
});
}
pauseTimer() {
timer.cancel();
}
void _resetGame() {
game.resetGame();
setState(() {
timer.cancel();
duration = const Duration();
startTimer();
});
}
@override
Widget build(BuildContext context) {
final responsiveSpacing = sqrt(MediaQuery.of(context).size.width) *
sqrt(MediaQuery.of(context).size.height);
return Stack(
children: [
GridView.count(
padding: const EdgeInsets.fromLTRB(8.0, 80.0, 8.0, 8.0),
childAspectRatio: MediaQuery.of(context).size.aspectRatio * 1.2,
mainAxisSpacing: responsiveSpacing / 100,
crossAxisSpacing: responsiveSpacing / 100,
crossAxisCount: game.gridSize,
children: List.generate(game.cards.length, (index) {
return MemoryCard(
index: index,
card: game.cards[index],
onCardPressed: game.onCardPressed,
);
}),
),
Positioned(
top: 12.0,
right: 24.0,
child: RestartGame(
isGameOver: game.isGameOver,
pauseGame: () => pauseTimer(),
restartGame: () => _resetGame(),
continueGame: () => startTimer(),
),
),
Positioned(
bottom: 12.0,
right: 24.0,
child: GameTimer(
time: duration,
),
),
Positioned(
bottom: 12.0,
left: 24.0,
child: GameBestTime(
bestTime: bestTime,
),
),
showConfetti ? const GameConfetti() : const SizedBox(),
],
);
}
}
import 'package:flutter/material.dart';
class GameTimer extends StatelessWidget {
const GameTimer({
required this.time,
super.key,
});
final Duration time;
@override
Widget build(BuildContext context) {
return Text(
time.toString().split('.').first.padLeft(8, "0"),
textAlign: TextAlign.center,
style: const TextStyle(
fontSize: 24.0,
fontWeight: FontWeight.bold,
),
);
}
}
import 'package:flutter/material.dart';
const Color continueButtonColor = Color.fromRGBO(235, 32, 93, 1);
const Color restartButtonColor = Color.fromRGBO(243, 181, 45, 1);
const Color quitButtonColor = Color.fromRGBO(39, 162, 149, 1);
const List<Map<String, dynamic>> gameLevels = [
{'title': 'Easy', 'level': 4, 'color': Colors.amberAccent},
{'title': 'Medium', 'level': 6, 'color': Colors.blueAccent},
{'title': 'Hard', 'level': 8, 'color': Colors.cyanAccent},
];
const String gameTitle = 'MEMORY MATCH';
import 'package:flutter/material.dart';
const List<IconData> cardIcons = <IconData>[
Icons.celebration,
Icons.directions_car_filled,
Icons.directions_bike,
Icons.house,
Icons.local_shipping,
Icons.fastfood,
Icons.album_sharp,
Icons.forest,
Icons.anchor,
Icons.ac_unit,
Icons.android,
Icons.favorite,
Icons.light,
Icons.agriculture_sharp,
Icons.airplanemode_on,
Icons.umbrella,
Icons.alarm,
Icons.directions_subway_rounded,
Icons.person,
Icons.light_mode_outlined,
Icons.bedtime_sharp,
Icons.all_inclusive,
Icons.wine_bar,
Icons.star,
Icons.headset_rounded,
Icons.apple_sharp,
Icons.whatshot_outlined,
Icons.delete,
Icons.audiotrack_rounded,
Icons.back_hand_sharp,
Icons.visibility,
Icons.traffic_rounded,
Icons.beach_access_rounded,
Icons.battery_charging_full_sharp,
Icons.downhill_skiing_rounded,
Icons.directions_boat_rounded,
Icons.eco_sharp,
Icons.restaurant,
Icons.balance_sharp,
Icons.shopping_cart_rounded,
Icons.radar_sharp,
Icons.sports_esports_rounded,
];
//main.dart
import 'package:flutter/material.dart';
import 'package:jema_app/game2/song_tales.dart';
void main() => runApp(SongTalesApp()); // Using the specific name for the app
This diff is collapsed.
This diff is collapsed.
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'emoX.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: EmotionGame(),
);
}
}
class EmotionGame extends StatefulWidget {
@override
_EmotionGameState createState() => _EmotionGameState();
}
class _EmotionGameState extends State<EmotionGame> {
late String correctEmotion;
bool isCorrect = false;
int questionIndex = 0;
bool allQuestionsCompleted =
false; // Flag to track if all questions are completed
// Map containing emotions, questions, and corresponding image paths
final Map<String, Map<String, String>> emotionData = {
'Sad': {
'question': 'How Lili looks like if she is Sad?',
'image': 'gsad.png'
},
'Angry': {
'question': 'How Lili looks like if she is Angry?',
'image': 'gangry.png'
},
'Happy': {
'question': 'How Lili looks like if she is Happy?',
'image': 'ghappy.png'
},
'Confused': {
'question': 'How Lili looks like if she is Confused?',
'image': 'gconfused.png'
},
'Surprised': {
'question': 'How Lili looks like if she is Surprised?',
'image': 'gsurprised.png'
},
};
// Lists containing shuffled emotions and questions
late List<String> shuffledEmotions;
late List<String> shuffledQuestions;
@override
void initState() {
super.initState();
// Set preferred orientations to portrait mode after navigating to this screen
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
shuffledEmotions = List.from(emotionData.keys)..shuffle();
shuffledQuestions = List.from(emotionData.values.map((e) => e['question']!))
..shuffle();
correctEmotion = _getCorrectEmotion(shuffledQuestions[questionIndex]);
}
// Function to get the correct emotion based on the question
String _getCorrectEmotion(String question) {
return emotionData.entries
.firstWhere((entry) => entry.value['question'] == question)
.key;
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Emotion Game'),
),
body: Column(
children: [
Text(
shuffledQuestions[questionIndex],
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
),
),
SizedBox(height: 60.0),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: shuffledEmotions.map((emotion) {
return Draggable(
child: Image.asset(
'game_assets/${emotionData[emotion]!['image']}',
width: 65,
height: 65,
),
feedback: Image.asset(
'game_assets/${emotionData[emotion]!['image']}',
width: 60,
height: 60,
),
data: emotion,
);
}).toList(),
),
SizedBox(height: 70.0),
DragTarget<String>(
builder: (BuildContext context, List<String?> candidateData,
List<dynamic> rejectedData) {
return Container(
width: 240,
height: 240,
color: Color.fromARGB(255, 222, 214, 145).withOpacity(0.5),
child: isCorrect
? Image.asset(
'game_assets/${emotionData[correctEmotion]!['image']}')
: null,
);
},
onWillAccept: (data) => data == correctEmotion,
onAccept: (data) {
setState(() {
isCorrect = true;
});
},
),
SizedBox(height: 20.0),
ElevatedButton(
onPressed: () {
setState(() {
if (questionIndex < shuffledQuestions.length - 1) {
questionIndex++;
isCorrect = false;
correctEmotion =
_getCorrectEmotion(shuffledQuestions[questionIndex]);
} else {
// Last question, set the flag to true
allQuestionsCompleted = true;
}
});
},
child: Text(
questionIndex < shuffledQuestions.length - 1
? 'Next Question >>'
: 'Finish Game',
),
),
if (allQuestionsCompleted)
SizedBox(
height: 30,
), // Show the text only when all questions are completed
if (allQuestionsCompleted)
Text(
'Game Over! You Won!',
style: TextStyle(
color: Color.fromARGB(255, 48, 173, 26),
fontSize: 20.0,
fontWeight: FontWeight.bold,
),
),
if (allQuestionsCompleted)
SizedBox(
height: 10,
), // Show the single Quit button only when all questions are completed
if (allQuestionsCompleted)
ElevatedButton(
onPressed: () {
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (context) => LevelScreen()),
);
},
child: Text('Quit'),
style: ElevatedButton.styleFrom(
primary: Color.fromARGB(255, 247, 56, 35),
onPrimary: Colors.white,
),
),
],
),
);
}
}
import 'package:flutter/material.dart';
import 'emoX.dart';
class Level3 extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Level 3'),
),
body: SingleChildScrollView(
child: Column(
children: [
Padding(
padding: const EdgeInsets.only(top: 20.0),
child: Center(
child: Column(
children: [
Text(
"Let's Identify",
textAlign: TextAlign.center,
style: TextStyle(
color: Color.fromARGB(255, 48, 173, 26),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
Text(
"Different Human Emotions",
textAlign: TextAlign.center,
style: TextStyle(
color: Color.fromARGB(255, 48, 173, 26),
fontSize: 21,
fontWeight: FontWeight.bold,
),
),
],
),
),
),
// Display the first GIF (laugh.gif)
Image.asset(
'game_assets/laugh.gif',
width: 380,
height: 350,
),
SizedBox(height: 0), // Reduce the gap between GIFs
// Display the second GIF (sad.gif)
Image.asset(
'game_assets/sad.gif',
width: 380,
height: 350,
),
Padding(
padding: const EdgeInsets.only(top: 20.0, bottom: 20.0),
child: ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => NextPage()),
);
},
child: Text('Next page'),
style: ElevatedButton.styleFrom(
primary: Color.fromARGB(255, 120, 149, 145),
onPrimary: Colors.white,
),
),
),
],
),
),
);
}
}
class NextPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Next Page'),
),
body: SingleChildScrollView(
child: Column(
children: [
Padding(
padding: const EdgeInsets.only(top: 20.0),
child: Center(
child: Column(
children: [
Text(
"Let's Identify",
textAlign: TextAlign.center,
style: TextStyle(
color: Color.fromARGB(255, 48, 173, 26),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
Text(
"Different Human Emotions",
textAlign: TextAlign.center,
style: TextStyle(
color: Color.fromARGB(255, 48, 173, 26),
fontSize: 21,
fontWeight: FontWeight.bold,
),
),
],
),
),
),
// Display the first GIF (fear.gif)
Image.asset(
'game_assets/fear.gif',
width: 380,
height: 320,
),
SizedBox(height: 0), // Reduce the gap between GIFs
// Display the second GIF (anger.gif)
Image.asset(
'game_assets/anger.gif',
width: 380,
height: 350,
),
Padding(
padding: const EdgeInsets.only(top: 20.0, bottom: 20.0),
child: ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => FinalPage()),
);
},
child: Text('Next page'),
style: ElevatedButton.styleFrom(
primary: Color.fromARGB(255, 120, 149, 145),
onPrimary: Colors.white,
),
),
),
],
),
),
);
}
}
class FinalPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Final Page'),
),
body: SingleChildScrollView(
child: Column(
children: [
Padding(
padding: const EdgeInsets.only(top: 20.0),
child: Center(
child: Column(
children: [
Text(
"Let's Identify",
textAlign: TextAlign.center,
style: TextStyle(
color: Color.fromARGB(255, 48, 173, 26),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
Text(
"Different Human Emotions",
textAlign: TextAlign.center,
style: TextStyle(
color: Color.fromARGB(255, 48, 173, 26),
fontSize: 21,
fontWeight: FontWeight.bold,
),
),
],
),
),
),
// Display the first GIF (disgust.gif)
Image.asset(
'game_assets/disgust.gif',
width: 380,
height: 320,
),
SizedBox(height: 0), // Reduce the gap between GIFs
// Display the second GIF (surprise.gif)
Image.asset(
'game_assets/surprise.gif',
width: 380,
height: 350,
),
Padding(
padding: const EdgeInsets.only(top: 20.0, bottom: 20.0),
child: ElevatedButton(
onPressed: () {
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (context) => LevelScreen()),
);
},
child: Text('Finish'),
style: ElevatedButton.styleFrom(
primary: Color.fromARGB(255, 231, 65, 43),
onPrimary: Colors.white,
),
),
),
],
),
),
);
}
}
//main.dart
import 'package:flutter/material.dart';
import 'package:jema_app/game3/emoX.dart';
void main() => runApp(EmoXApp()); // Using the specific name for the app
This diff is collapsed.
import 'package:flutter/material.dart';
import 'package:jema_app/game4/Posture_pro.dart';
void main() => runApp(PosturePro());
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:jema_app/game1/the_memory_match_game.dart';
import 'package:jema_app/game2/song_tales.dart';
import 'package:jema_app/game3/emoX.dart';
import 'package:jema_app/game4/Posture_pro.dart';
class GamesPage extends StatelessWidget { class GamesPage extends StatelessWidget {
final List<Map<String, String>> gameData = [
{'game': 'Game 1', 'description': 'Description for Game 1'},
{'game': 'Game 2', 'description': 'Description for Game 2'},
// add list
];
final String commonImagePath = 'assets/act_photo.png'; final String commonImagePath = 'assets/act_photo.png';
@override @override
...@@ -29,31 +27,118 @@ class GamesPage extends StatelessWidget { ...@@ -29,31 +27,118 @@ class GamesPage extends StatelessWidget {
), ),
), ),
Expanded( Expanded(
child: ListView.builder( child: ListView(
itemCount: gameData.length, children: [
itemBuilder: (context, index) { // Game 1 Card/Button
var game = gameData[index]; Card(
return Card( child: ListTile(
contentPadding: EdgeInsets.all(16),
leading: Container(
width: 50,
height: 50,
child: CircleAvatar(
backgroundImage: AssetImage(commonImagePath),
),
),
title: Text(
'Game 1',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
subtitle: Text('Description for Game 1'),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => TheMemoryMatchGame()),
);
},
),
),
// Game 2 Card/Button
Card(
child: ListTile(
contentPadding: EdgeInsets.all(16),
leading: Container(
width: 50,
height: 50,
child: CircleAvatar(
backgroundImage: AssetImage(commonImagePath),
),
),
title: Text(
'Game 2',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
subtitle: Text('Description for Game 2'),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SongTalesApp()),
);
},
),
),
// Game 3 Card/Button
Card(
child: ListTile(
contentPadding: EdgeInsets.all(16),
leading: Container(
width: 50,
height: 50,
child: CircleAvatar(
backgroundImage: AssetImage(commonImagePath),
),
),
title: Text(
'Game 3',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
subtitle: Text('Description for Game 3'),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => EmoXApp()),
);
},
),
),
// Game 4 Card/Button
Card(
child: ListTile( child: ListTile(
contentPadding: EdgeInsets.all(16), contentPadding: EdgeInsets.all(16),
leading: Container( leading: Container(
width: 50, width: 50,
height: 50, height: 50,
child: CircleAvatar( child: CircleAvatar(
backgroundImage: AssetImage(commonImagePath), backgroundImage: AssetImage(commonImagePath),
), ),
), ),
title: Text( title: Text(
game['game'] ?? '', 'Game 4',
style: TextStyle( style: TextStyle(
fontSize: 18, fontSize: 18,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
subtitle: Text(game['description'] ?? ''), subtitle: Text('Description for Game 4'),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => PosturePro()),
);
},
), ),
); ),
}, ],
), ),
), ),
], ],
...@@ -83,33 +168,7 @@ class GamesPage extends StatelessWidget { ...@@ -83,33 +168,7 @@ class GamesPage extends StatelessWidget {
unselectedLabelStyle: TextStyle(color: Color.fromARGB(0, 197, 16, 16)), unselectedLabelStyle: TextStyle(color: Color.fromARGB(0, 197, 16, 16)),
currentIndex: 2, currentIndex: 2,
onTap: (index) { onTap: (index) {
switch (index) { // Your existing navigation logic
case 0:
// Navigate to Home
// Replace the code below with your home navigation logic
// Navigator.push(
// // context,
// // MaterialPageRoute(builder: (context) => AddClassroom()),
// );
break;
case 1:
// Navigate to Chat
// Navigator.push(
// // context,
// // MaterialPageRoute(builder: (context) => ChatScreen()),
// );
break;
case 2:
// Already on Games Page
break;
case 3:
// Navigate to Profile
// Navigator.push(
// // context,
// // MaterialPageRoute(builder: (context) => TeacherProfile()),
// );
break;
}
}, },
), ),
); );
......
...@@ -10,11 +10,13 @@ import file_selector_macos ...@@ -10,11 +10,13 @@ import file_selector_macos
import firebase_auth import firebase_auth
import firebase_core import firebase_core
import firebase_storage import firebase_storage
import package_info_plus
import path_provider_foundation import path_provider_foundation
import rive_common import rive_common
import shared_preferences_foundation import shared_preferences_foundation
import sqflite import sqflite
import url_launcher_macos import url_launcher_macos
import wakelock_plus
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FLTFirebaseFirestorePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseFirestorePlugin")) FLTFirebaseFirestorePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseFirestorePlugin"))
...@@ -22,9 +24,11 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { ...@@ -22,9 +24,11 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FLTFirebaseAuthPlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseAuthPlugin")) FLTFirebaseAuthPlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseAuthPlugin"))
FLTFirebaseCorePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseCorePlugin")) FLTFirebaseCorePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseCorePlugin"))
FLTFirebaseStoragePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseStoragePlugin")) FLTFirebaseStoragePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseStoragePlugin"))
FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
RivePlugin.register(with: registry.registrar(forPlugin: "RivePlugin")) RivePlugin.register(with: registry.registrar(forPlugin: "RivePlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin")) SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin")) UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
WakelockPlusMacosPlugin.register(with: registry.registrar(forPlugin: "WakelockPlusMacosPlugin"))
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment