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
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:video_player/video_player.dart';
import 'package:chewie/chewie.dart';
import 'package:jema_app/games.dart';
void main() {
runApp(SongTalesApp());
}
class SongTalesApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: LevelScreen(),
);
}
}
class LevelButton extends StatelessWidget {
final String imagePath;
final String?
label; // Making label parameter optional by adding '?' after String
final VoidCallback onPressed;
const LevelButton({
required this.imagePath,
this.label, // Making label parameter optional
required this.onPressed,
});
@override
Widget build(BuildContext context) {
return ElevatedButton(
onPressed: onPressed,
style: ElevatedButton.styleFrom(
primary: Colors.transparent,
elevation: 0,
padding: EdgeInsets.zero,
),
child: Column(
children: [
Image.asset(
imagePath,
width: 400,
height: 150,
),
SizedBox(height: 8),
if (label != null) // Only show label if it's not null
Text(
label!,
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
),
],
),
);
}
}
class LevelScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Song Tales'),
),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
LevelButton(
imagePath: 'game_assets/slevel1_btn.png',
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Level1VideoScreen(),
),
);
},
),
SizedBox(height: 10),
LevelButton(
imagePath: 'game_assets/slevel2_btn.png',
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Level2VideoScreen(),
),
);
},
),
SizedBox(height: 10),
LevelButton(
imagePath: 'game_assets/slevel3_btn.png',
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Level3VideoScreen(),
),
);
},
),
],
),
),
),
SizedBox(height: 20),
ElevatedButton(
onPressed: () {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => GamesPage(),
),
);
},
child: Text('Quit Game'),
style: ElevatedButton.styleFrom(
primary: Color.fromARGB(255, 231, 65, 43),
onPrimary: Colors.white,
),
),
SizedBox(height: 40),
],
),
);
}
}
class Level1VideoScreen extends StatefulWidget {
@override
_Level1VideoScreenState createState() => _Level1VideoScreenState();
}
class _Level1VideoScreenState extends State<Level1VideoScreen> {
late VideoPlayerController _controller;
late ChewieController _chewieController;
int correctAnswersCount = 0;
@override
void initState() {
super.initState();
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]); // Lock orientation to landscape
_controller = VideoPlayerController.asset('game_assets/Level1_song.mp4')
..initialize().then((_) {
setState(() {});
_controller.play();
});
_chewieController = ChewieController(
videoPlayerController: _controller,
autoPlay: true,
looping: false,
allowMuting: false,
allowPlaybackSpeedChanging: true,
allowFullScreen: false,
showControlsOnInitialize: false,
customControls: MaterialControls(),
// Enforcing landscape mode
aspectRatio: 16 / 9,
// Setting the orientation to landscape
deviceOrientationsAfterFullScreen: [
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
],
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
Expanded(
child: Center(
child: _controller.value.isInitialized
? Chewie(
controller: _chewieController,
)
: CircularProgressIndicator(),
),
),
ElevatedButton(
onPressed: () {
_controller.pause();
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Level1QuestionScreen(
onCorrectAnswer: () {
correctAnswersCount++;
if (correctAnswersCount == 4) {
Navigator.pop(context); // Pop the QuestionScreen
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ResultScreen(),
),
);
}
},
),
),
);
},
child: Text('Answer Question'),
style: ElevatedButton.styleFrom(
primary: Color.fromARGB(255, 48, 173, 26),
onPrimary: Colors.white,
),
),
],
),
);
}
@override
void dispose() {
_controller.pause(); // Pause the video before disposing
_controller.dispose();
_chewieController.dispose();
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]); // Unlock orientation
super.dispose();
}
}
class Level1QuestionScreen extends StatefulWidget {
final VoidCallback onCorrectAnswer;
const Level1QuestionScreen({required this.onCorrectAnswer});
@override
_Level1QuestionScreenState createState() => _Level1QuestionScreenState();
}
class _Level1QuestionScreenState extends State<Level1QuestionScreen> {
late List<String> questions;
late Map<String, List<String>> questionImageMapping;
int currentQuestionIndex = 0;
late List<String> shuffledImages; // Add shuffled images list
@override
void initState() {
super.initState();
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]); // Lock orientation to landscape
questions = [
'Select the monkey',
'Select the giraffe',
'Select the lion',
'Select the elephant'
];
questionImageMapping = {
'Select the monkey': [
'monkey.png',
'giraffe.png',
'elephant.png',
'gorilla.png',
'koala.png',
'lion.png'
],
'Select the giraffe': [
'giraffe.png',
'lion.png',
'elephant.png',
'koala.png',
'gorilla.png',
'monkey.png'
],
'Select the lion': [
'lion.png',
'elephant.png',
'giraffe.png',
'koala.png',
'gorilla.png',
'monkey.png'
],
'Select the elephant': [
'elephant.png',
'monkey.png',
'gorilla.png',
'giraffe.png',
'koala.png',
'lion.png'
],
};
currentQuestionIndex = 0;
shuffledImages =
List.from(questionImageMapping[questions[currentQuestionIndex]]!)
..shuffle(); // Shuffle images for the first question
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Question Screen'),
leading: IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () {
Navigator.pop(context); // Navigate back
},
),
),
body: OrientationBuilder(
builder: (context, orientation) {
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]); // Lock orientation to landscape
return orientation == Orientation.landscape
? _buildLandscapeContent()
: _buildPortraitContent();
},
),
);
}
Widget _buildLandscapeContent() {
return Column(
children: [
Padding(
padding: const EdgeInsets.all(0.0),
child: Text(
questions[currentQuestionIndex],
style: TextStyle(
fontSize: 25.0,
fontWeight: FontWeight.bold,
),
),
),
Expanded(
child: GridView.count(
crossAxisCount: 3,
padding: EdgeInsets.all(20.0),
mainAxisSpacing: 20.0,
crossAxisSpacing: 2.0,
childAspectRatio: 2.5,
children: shuffledImages.map((imageName) {
return AnimalImage(
imageName: imageName,
correctAnswer: imageName ==
questionImageMapping[questions[currentQuestionIndex]]![0],
nextQuestion: moveToNextQuestion,
onCorrectAnswer: widget.onCorrectAnswer,
);
}).toList(),
),
),
],
);
}
Widget _buildPortraitContent() {
return Center(
child: Text(
'Please rotate your device to landscape mode.',
style: TextStyle(fontSize: 24.0),
),
);
}
void moveToNextQuestion() {
setState(() {
if (currentQuestionIndex < questions.length - 1) {
currentQuestionIndex++;
shuffledImages =
List.from(questionImageMapping[questions[currentQuestionIndex]]!)
..shuffle(); // Shuffle images for the next question
} else {
currentQuestionIndex = 0;
}
});
}
@override
void dispose() {
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]); // Lock orientation to landscape
super.dispose();
}
}
class Level2VideoScreen extends StatefulWidget {
@override
_Level2VideoScreenState createState() => _Level2VideoScreenState();
}
class _Level2VideoScreenState extends State<Level2VideoScreen> {
late VideoPlayerController _controller;
late ChewieController _chewieController;
int correctAnswersCount = 0;
@override
void initState() {
super.initState();
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]); // Lock orientation to landscape
_controller = VideoPlayerController.asset('game_assets/Level2_song.mp4')
..initialize().then((_) {
setState(() {});
_controller.play();
});
_chewieController = ChewieController(
videoPlayerController: _controller,
autoPlay: true,
looping: false,
allowMuting: false,
allowPlaybackSpeedChanging: true,
allowFullScreen: false,
showControlsOnInitialize: false,
customControls: MaterialControls(),
// Enforcing landscape mode
aspectRatio: 16 / 9,
// Setting the orientation to landscape
deviceOrientationsAfterFullScreen: [
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
],
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
Expanded(
child: Center(
child: _controller.value.isInitialized
? Chewie(
controller: _chewieController,
)
: CircularProgressIndicator(),
),
),
ElevatedButton(
onPressed: () {
_controller.pause();
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Level2QuestionScreen(
onCorrectAnswer: () {
correctAnswersCount++;
if (correctAnswersCount == 4) {
Navigator.pop(context); // Pop the QuestionScreen
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ResultScreen(),
),
);
}
},
),
),
);
},
child: Text('Answer Question'),
style: ElevatedButton.styleFrom(
primary: Color.fromARGB(255, 48, 173, 26),
onPrimary: Colors.white,
),
),
],
),
);
}
@override
void dispose() {
_controller.pause(); // Pause the video before disposing
_controller.dispose();
_chewieController.dispose();
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]); // Unlock orientation
super.dispose();
}
}
class Level2QuestionScreen extends StatefulWidget {
final VoidCallback onCorrectAnswer;
const Level2QuestionScreen({required this.onCorrectAnswer});
@override
_Level2QuestionScreenState createState() => _Level2QuestionScreenState();
}
class _Level2QuestionScreenState extends State<Level2QuestionScreen> {
late List<String> questions;
late Map<String, List<String>> questionImageMapping;
int currentQuestionIndex = 0;
late List<String> shuffledImages; // Add shuffled images list
@override
void initState() {
super.initState();
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]); // Lock orientation to landscape
questions = [
'Select the books',
'Select the eraser',
'Select the pen',
'Select the glue'
];
questionImageMapping = {
'Select the books': [
'books.png',
'eraser.png',
'pen.png',
'glue.png',
'scissors.png',
'highlighter.png'
],
'Select the eraser': [
'eraser.png',
'pen.png',
'glue.png',
'scissors.png',
'highlighter.png',
'books.png'
],
'Select the pen': [
'pen.png',
'glue.png',
'scissors.png',
'highlighter.png',
'books.png',
'eraser.png'
],
'Select the glue': [
'glue.png',
'scissors.png',
'highlighter.png',
'books.png',
'eraser.png',
'pen.png'
],
};
currentQuestionIndex = 0;
shuffledImages =
List.from(questionImageMapping[questions[currentQuestionIndex]]!)
..shuffle(); // Shuffle images for the first question
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Question Screen'),
leading: IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () {
Navigator.pop(context); // Navigate back
},
),
),
body: OrientationBuilder(
builder: (context, orientation) {
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]); // Lock orientation to landscape
return orientation == Orientation.landscape
? _buildLandscapeContent()
: _buildPortraitContent();
},
),
);
}
Widget _buildLandscapeContent() {
return Column(
children: [
Padding(
padding: const EdgeInsets.all(0.0),
child: Text(
questions[currentQuestionIndex],
style: TextStyle(
fontSize: 25.0,
fontWeight: FontWeight.bold,
),
),
),
Expanded(
child: GridView.count(
crossAxisCount: 3,
padding: EdgeInsets.all(20.0),
mainAxisSpacing: 20.0,
crossAxisSpacing: 2.0,
childAspectRatio: 2.5,
children: shuffledImages.map((imageName) {
return AnimalImage(
imageName: imageName,
correctAnswer: imageName ==
questionImageMapping[questions[currentQuestionIndex]]![0],
nextQuestion: moveToNextQuestion,
onCorrectAnswer: widget.onCorrectAnswer,
);
}).toList(),
),
),
],
);
}
Widget _buildPortraitContent() {
return Center(
child: Text(
'Please rotate your device to landscape mode.',
style: TextStyle(fontSize: 24.0),
),
);
}
void moveToNextQuestion() {
setState(() {
if (currentQuestionIndex < questions.length - 1) {
currentQuestionIndex++;
shuffledImages =
List.from(questionImageMapping[questions[currentQuestionIndex]]!)
..shuffle(); // Shuffle images for the next question
} else {
currentQuestionIndex = 0;
}
});
}
@override
void dispose() {
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]); // Lock orientation to landscape
super.dispose();
}
}
class Level3VideoScreen extends StatefulWidget {
@override
_Level3VideoScreenState createState() => _Level3VideoScreenState();
}
class _Level3VideoScreenState extends State<Level3VideoScreen> {
late VideoPlayerController _controller;
late ChewieController _chewieController;
int correctAnswersCount = 0;
@override
void initState() {
super.initState();
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]); // Lock orientation to landscape
_controller = VideoPlayerController.asset('game_assets/Level3_song.mp4')
..initialize().then((_) {
setState(() {});
_controller.play();
});
_chewieController = ChewieController(
videoPlayerController: _controller,
autoPlay: true,
looping: false,
allowMuting: false,
allowPlaybackSpeedChanging: true,
allowFullScreen: false,
showControlsOnInitialize: false,
customControls: MaterialControls(),
// Enforcing landscape mode
aspectRatio: 16 / 9,
// Setting the orientation to landscape
deviceOrientationsAfterFullScreen: [
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
],
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
Expanded(
child: Center(
child: _controller.value.isInitialized
? Chewie(
controller: _chewieController,
)
: CircularProgressIndicator(),
),
),
ElevatedButton(
onPressed: () {
_controller.pause();
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Level3QuestionScreen(
onCorrectAnswer: () {
correctAnswersCount++;
if (correctAnswersCount == 4) {
Navigator.pop(context); // Pop the QuestionScreen
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ResultScreen(),
),
);
}
},
),
),
);
},
child: Text('Answer Question'),
style: ElevatedButton.styleFrom(
primary: Color.fromARGB(255, 48, 173, 26),
onPrimary: Colors.white,
),
),
],
),
);
}
@override
void dispose() {
_controller.pause(); // Pause the video before disposing
_controller.dispose();
_chewieController.dispose();
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]); // Unlock orientation
super.dispose();
}
}
class Level3QuestionScreen extends StatefulWidget {
final VoidCallback onCorrectAnswer;
const Level3QuestionScreen({required this.onCorrectAnswer});
@override
_Level3QuestionScreenState createState() => _Level3QuestionScreenState();
}
class _Level3QuestionScreenState extends State<Level3QuestionScreen> {
late Map<String, List<String>> questionImageMap;
late List<String> questions;
int currentQuestionIndex = 0;
late List<String> shuffledImages; // Add shuffled images list
@override
void initState() {
super.initState();
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]); // Lock orientation to landscape
questionImageMap = {
'Select the heart': [
'heart.png',
'square.png',
'diamond.png',
'circle.png',
'star.png',
'triangle.png'
],
'Select the Square': [
'square.png',
'diamond.png',
'triangle.png',
'heart.png',
'star.png',
'circle.png'
],
'Select the Circle': [
'circle.png',
'heart.png',
'triangle.png',
'square.png',
'star.png',
'diamond.png'
],
'Select the Diamond': [
'diamond.png',
'triangle.png',
'square.png',
'star.png',
'heart.png',
'circle.png'
],
};
questions = questionImageMap.keys.toList();
currentQuestionIndex = 0;
shuffledImages =
List.from(questionImageMap[questions[currentQuestionIndex]]!)
..shuffle(); // Shuffle images for the first question
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Question Screen'),
leading: IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () {
Navigator.pop(context); // Navigate back
},
),
),
body: OrientationBuilder(
builder: (context, orientation) {
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]); // Lock orientation to landscape
return orientation == Orientation.landscape
? _buildLandscapeContent()
: _buildPortraitContent();
},
),
);
}
Widget _buildLandscapeContent() {
return Column(
children: [
Padding(
padding: const EdgeInsets.all(0.0),
child: Text(
questions[currentQuestionIndex],
style: TextStyle(
fontSize: 25.0,
fontWeight: FontWeight.bold,
),
),
),
Expanded(
child: GridView.count(
crossAxisCount: 3,
padding: EdgeInsets.all(20.0),
mainAxisSpacing: 20.0,
crossAxisSpacing: 2.0,
childAspectRatio: 2.5,
children: shuffledImages.map((imageName) {
return AnimalImage(
imageName: imageName,
correctAnswer: imageName ==
questionImageMap[questions[currentQuestionIndex]]![0],
nextQuestion: moveToNextQuestion,
onCorrectAnswer: widget.onCorrectAnswer,
);
}).toList(),
),
),
],
);
}
Widget _buildPortraitContent() {
return Center(
child: Text(
'Please rotate your device to landscape mode.',
style: TextStyle(fontSize: 24.0),
),
);
}
void moveToNextQuestion() {
setState(() {
if (currentQuestionIndex < questions.length - 1) {
currentQuestionIndex++;
shuffledImages =
List.from(questionImageMap[questions[currentQuestionIndex]]!)
..shuffle(); // Shuffle images for the next question
} else {
currentQuestionIndex = 0;
}
});
}
@override
void dispose() {
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]); // Lock orientation to landscape
super.dispose();
}
}
class AnimalImage extends StatelessWidget {
final String imageName;
final bool correctAnswer;
final Function nextQuestion;
final VoidCallback onCorrectAnswer;
const AnimalImage({
Key? key,
required this.imageName,
required this.correctAnswer,
required this.nextQuestion,
required this.onCorrectAnswer,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Result'),
content: Text(
correctAnswer ? 'You are correct!' : 'Try again.',
),
actions: <Widget>[
TextButton(
onPressed: () {
Navigator.of(context).pop();
if (correctAnswer) {
nextQuestion();
onCorrectAnswer(); // Notify parent about correct answer
}
},
child: Text('OK'),
),
],
);
},
);
},
child: Container(
margin: EdgeInsets.all(8.0),
child: Image.asset(
'game_assets/$imageName',
width: 80.0,
height: 80.0,
),
),
);
}
}
class ResultScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Result Screen'),
leading: IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () {
Navigator.popUntil(
context,
ModalRoute.withName(Navigator.defaultRouteName),
);
},
),
),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Center(
child: Padding(
padding:
EdgeInsets.only(top: 0.0), // Adjust the top padding as needed
child: Image.asset(
'game_assets/result.gif',
width: 500, // Adjust the width as needed
height: 250, // Adjust the height as needed
),
),
),
],
),
);
}
}
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:video_player/video_player.dart';
import 'package:chewie/chewie.dart';
import 'level2.dart';
import 'level3.dart';
import 'package:jema_app/games.dart';
void main() {
runApp(EmoXApp());
}
class EmoXApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: "Emotion Matching Game",
home: LevelScreen(),
);
}
}
class LevelScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('EmoX Game'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => Level1VideoScreen()),
);
},
style: ElevatedButton.styleFrom(
primary: Colors.transparent,
elevation: 0,
),
child: Image.asset(
'game_assets/btn_level1.png',
width: 350,
height: 160,
),
),
ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => Level2VideoScreen()),
);
},
style: ElevatedButton.styleFrom(
primary: Colors.transparent,
elevation: 0,
),
child: Image.asset(
'game_assets/btn_level2.png',
width: 350,
height: 160,
),
),
ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => Level3()),
);
},
style: ElevatedButton.styleFrom(
primary: Colors.transparent,
elevation: 0,
),
child: Image.asset(
'game_assets/btn_level3.png',
width: 350,
height: 160,
),
),
SizedBox(height: 60),
ElevatedButton(
onPressed: () {
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (context) => GamesPage()),
);
},
child: Text('Quit Game'),
style: ElevatedButton.styleFrom(
primary: Color.fromARGB(255, 231, 65, 43),
onPrimary: Colors.white,
),
),
SizedBox(height: 20),
],
),
),
);
}
}
class Level1VideoScreen extends StatefulWidget {
@override
_Level1VideoScreenState createState() => _Level1VideoScreenState();
}
class _Level1VideoScreenState extends State<Level1VideoScreen> {
late VideoPlayerController _controller;
late ChewieController _chewieController;
int correctAnswersCount = 0;
@override
void initState() {
super.initState();
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]); // Lock orientation to landscape
_controller = VideoPlayerController.asset('game_assets/EmoX_level1.mp4')
..initialize().then((_) {
setState(() {});
_controller.play();
});
_chewieController = ChewieController(
videoPlayerController: _controller,
autoPlay: true,
looping: false,
allowMuting: false,
allowPlaybackSpeedChanging: true,
allowFullScreen: false,
showControlsOnInitialize: false,
customControls: MaterialControls(),
// Enforcing landscape mode
aspectRatio: 16 / 9,
// Setting the orientation to landscape
deviceOrientationsAfterFullScreen: [
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
],
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
Expanded(
child: Center(
child: _controller.value.isInitialized
? Chewie(
controller: _chewieController,
)
: CircularProgressIndicator(),
),
),
ElevatedButton(
onPressed: () {
_controller.pause();
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => HomePage(level: 1),
),
);
},
child: Text('Play'),
),
],
),
);
}
@override
void dispose() {
super.dispose();
_controller.dispose();
_chewieController.dispose();
}
}
class Level2VideoScreen extends StatefulWidget {
@override
_Level2VideoScreenState createState() => _Level2VideoScreenState();
}
class _Level2VideoScreenState extends State<Level2VideoScreen> {
late VideoPlayerController _controller;
late ChewieController _chewieController;
int correctAnswersCount = 0;
@override
void initState() {
super.initState();
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]); // Lock orientation to landscape
_controller = VideoPlayerController.asset('game_assets/EmoX_level2.mp4')
..initialize().then((_) {
setState(() {});
_controller.play();
});
_chewieController = ChewieController(
videoPlayerController: _controller,
autoPlay: true,
looping: false,
allowMuting: false,
allowPlaybackSpeedChanging: true,
allowFullScreen: false,
showControlsOnInitialize: false,
customControls: MaterialControls(),
// Enforcing landscape mode
aspectRatio: 16 / 9,
// Setting the orientation to landscape
deviceOrientationsAfterFullScreen: [
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
],
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
Expanded(
child: Center(
child: _controller.value.isInitialized
? Chewie(
controller: _chewieController,
)
: CircularProgressIndicator(),
),
),
ElevatedButton(
onPressed: () {
_controller.pause();
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => EmotionGame(),
),
);
},
child: Text('Play'),
),
],
),
);
}
@override
void dispose() {
super.dispose();
_controller.dispose();
_chewieController.dispose();
}
}
class HomePage extends StatefulWidget {
final int level;
HomePage({required this.level});
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
late List<ItemModel> items;
late List<ItemModel> items2;
late int score;
late bool gameOver;
@override
void initState() {
super.initState();
initGame();
// Set preferred orientations to portrait mode
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
}
initGame() {
gameOver = false;
score = 0;
items = [
ItemModel(
name: "Happy",
value: "happy",
imagePath: "game_assets/happy.png",
),
ItemModel(
name: "Sad",
value: "sad",
imagePath: "game_assets/sad.png",
),
ItemModel(
name: "Angry",
value: "angry",
imagePath: "game_assets/angry.png",
),
ItemModel(
name: "Sleepy",
value: "sleepy",
imagePath: "game_assets/sleepy.png",
),
ItemModel(
name: "Surprised",
value: "surprised",
imagePath: "game_assets/surprised.png",
),
];
items2 = List<ItemModel>.from(items);
items.shuffle();
items2.shuffle();
}
@override
Widget build(BuildContext context) {
if (items.length == 0) gameOver = true;
return Scaffold(
backgroundColor: const Color.fromARGB(255, 233, 218, 176),
appBar: AppBar(
centerTitle: true,
title: Text('Mood Matching Game'),
),
body: SingleChildScrollView(
padding: const EdgeInsets.all(16.0),
child: Column(
children: <Widget>[
Text.rich(TextSpan(children: [
TextSpan(text: "Score: "),
TextSpan(
text: "$score",
style: TextStyle(
color: Colors.green,
fontWeight: FontWeight.bold,
fontSize: 30.0,
))
])),
if (!gameOver)
Row(
children: <Widget>[
Column(
children: items.map((item) {
return Container(
margin: const EdgeInsets.all(8.0),
child: Draggable<ItemModel>(
data: item,
childWhenDragging: Image.asset(
item.imagePath,
width: 90.0,
height: 90.0,
),
feedback: Image.asset(
item.imagePath,
width: 90.0,
height: 90.0,
),
child: Image.asset(
item.imagePath,
width: 90.0,
height: 90.0,
),
),
);
}).toList()),
Spacer(),
Column(
children: items2.map((item) {
return DragTarget<ItemModel>(
onAccept: (receivedItem) {
if (item.value == receivedItem.value) {
setState(() {
items.remove(receivedItem);
items2.remove(item);
score += 10;
item.accepting = false;
});
} else {
setState(() {
score -= 5;
item.accepting = false;
});
}
},
onLeave: (receivedItem) {
setState(() {
item.accepting = false;
});
},
onWillAccept: (receivedItem) {
setState(() {
item.accepting = true;
});
return true;
},
builder: (context, acceptedItems, rejectedItem) =>
Container(
color: item.accepting ? Colors.red : Colors.teal,
height: 50,
width: 100,
alignment: Alignment.center,
margin: const EdgeInsets.all(28.0),
child: Text(
item.name,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 18.0,
),
),
),
);
}).toList()),
],
),
if (gameOver)
Text(
"Game Over!",
style: TextStyle(
color: const Color.fromARGB(255, 164, 70, 63),
fontWeight: FontWeight.bold,
fontSize: 24.0,
),
),
if (gameOver)
SizedBox(
width: double.infinity,
child: Container(
margin:
EdgeInsets.only(top: 40.0), // Adjust top margin as needed
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () {
initGame();
setState(() {});
},
child: Text("New Game"),
style: ElevatedButton.styleFrom(
primary: Color.fromARGB(255, 22, 167, 42),
onPrimary: Colors.white,
),
),
SizedBox(
height: 10), // Add space between buttons if needed
ElevatedButton(
onPressed: () {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => LevelScreen(),
),
);
},
child: Text("Quit Game"),
style: ElevatedButton.styleFrom(
primary: Colors.red,
onPrimary: Colors.white,
),
),
],
),
),
),
],
),
),
);
}
}
class ItemModel {
final String name;
final String value;
final String imagePath;
bool accepting;
ItemModel(
{required this.name,
required this.value,
required this.imagePath,
this.accepting = false});
}
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
import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';
import 'package:chewie/chewie.dart';
import 'package:jema_app/games.dart';
void main() {
runApp(PosturePro());
}
class PosturePro extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: LevelScreen(),
);
}
}
class LevelScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Select Level'),
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(
padding: EdgeInsets.all(16.0),
child: Center(
child: Text(
"Let's get started!",
style: TextStyle(
color: Color.fromARGB(255, 48, 173, 26),
fontSize: 20,
fontWeight: FontWeight.bold),
),
),
),
Expanded(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
LevelButton(
imagePath: 'game_assets/level1_button.png',
level: 1,
),
SizedBox(height: 10), // Adjusted height between buttons
LevelButton(
imagePath: 'game_assets/level2_button.png',
level: 2,
),
SizedBox(height: 10), // Adjusted height between buttons
LevelButton(
imagePath: 'game_assets/level3_button.png',
level: 3,
),
],
),
),
),
SizedBox(height: 20),
// Add some spacing between the buttons and the quit button
ElevatedButton(
onPressed: () {
// Navigate back to the GamesSelectionScreen when the quit button is pressed
Navigator.push(
context,
MaterialPageRoute(builder: (context) => GamesPage()),
);
},
child: Text('Quit Game'),
style: ElevatedButton.styleFrom(
primary: Color.fromARGB(255, 231, 65, 43),
onPrimary: Colors.white,
),
),
SizedBox(height: 40),
],
),
);
}
}
class LevelButton extends StatelessWidget {
final String imagePath;
final int level;
const LevelButton({
required this.imagePath,
required this.level,
});
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
// Navigate to the selected level screen
Navigator.push(
context,
MaterialPageRoute(builder: (context) => getLevelScreen(level)),
);
},
child: Image.asset(
imagePath,
width: 500,
height: 160,
// You may adjust the width and height as needed
),
);
}
Widget getLevelScreen(int level) {
switch (level) {
case 1:
return Level1Screen(level: level);
case 2:
return Level2Screen(level: level);
case 3:
return Level3Screen(
level: level); // Changed to Level3Screen for level 3
default:
return Container(); // Return empty container for unknown level
}
}
}
class Level1Screen extends StatelessWidget {
final int level;
const Level1Screen({required this.level});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Level $level'),
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(
padding: EdgeInsets.all(20.0),
child: Text(
'Exercises List',
style: TextStyle(
color: Color.fromARGB(255, 48, 173, 26),
fontSize: 20,
fontWeight: FontWeight.bold),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: ListView(
children: [
Padding(
padding: const EdgeInsets.only(
bottom: 20.0), // Adjust the bottom padding as needed
child: Image.asset('game_assets/Exercise_list.png'),
),
],
),
),
),
ElevatedButton(
onPressed: () {
// Navigate to the exercise screen
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ExerciseScreen(level: level)),
);
},
child: Text('Start'),
style: ElevatedButton.styleFrom(
primary: Color.fromARGB(255, 43, 159, 231),
onPrimary: Colors.white,
),
),
SizedBox(height: 50),
],
),
);
}
}
class ExerciseScreen extends StatefulWidget {
final int level;
const ExerciseScreen({required this.level});
@override
_ExerciseScreenState createState() => _ExerciseScreenState();
}
class _ExerciseScreenState extends State<ExerciseScreen> {
late VideoPlayerController _videoPlayerController;
late ChewieController _chewieController;
@override
void initState() {
super.initState();
_videoPlayerController =
VideoPlayerController.asset('game_assets/level1_vid.mp4');
_chewieController = ChewieController(
videoPlayerController: _videoPlayerController,
autoPlay: true,
looping: true,
allowFullScreen: false,
allowMuting: true,
aspectRatio: 16 / 11,
);
}
@override
void dispose() {
_videoPlayerController.pause();
_videoPlayerController.dispose();
_chewieController.dispose();
super.dispose();
}
void pauseVideo() {
if (_videoPlayerController.value.isPlaying) {
_videoPlayerController.pause();
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Level ${widget.level} - Exercises'),
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
AspectRatio(
aspectRatio: 16 / 11,
child: Chewie(
controller: _chewieController,
),
),
SizedBox(height: 20),
Image.asset('game_assets/ex1_det.png'),
SizedBox(height: 30),
ElevatedButton(
onPressed: () {
pauseVideo();
Navigator.push(
context,
MaterialPageRoute(builder: (context) => ResultScreen()),
);
},
child: Text('Finish Exercise'),
style: ElevatedButton.styleFrom(
primary: Color.fromARGB(255, 48, 173, 26),
onPrimary: Colors.white,
),
),
],
),
);
}
}
class ResultScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Exercise Result'),
leading: IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () {
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (context) => LevelScreen()),
);
},
),
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(height: 0),
Image.asset(
'game_assets/result1.png',
height: 650,
width: 500, // Adjust the height of the image as needed
),
SizedBox(height: 20),
],
),
);
}
}
class Level2Screen extends StatelessWidget {
final int level;
const Level2Screen({required this.level});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Level $level'),
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(
padding: EdgeInsets.all(20.0),
child: Text(
'Behavior List',
style: TextStyle(
color: Color.fromARGB(255, 48, 173, 26),
fontSize: 20,
fontWeight: FontWeight.bold),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20.0),
child: ListView(
children: [
Image.asset(
'game_assets/Behavior_list.png'), // Use Behavior_list.png for Level 2
],
),
),
),
ElevatedButton(
onPressed: () {
// Navigate to the exercise screen
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Level2VideoScreen(level: level)),
);
},
child: Text('Start'),
style: ElevatedButton.styleFrom(
primary: Color.fromARGB(255, 43, 159, 231),
onPrimary: Colors.white,
),
),
SizedBox(height: 50),
],
),
);
}
}
class Level2VideoScreen extends StatefulWidget {
final int level;
const Level2VideoScreen({required this.level});
@override
_Level2VideoScreenState createState() => _Level2VideoScreenState();
}
class _Level2VideoScreenState extends State<Level2VideoScreen> {
late VideoPlayerController _videoPlayerController;
late ChewieController _chewieController;
@override
void initState() {
super.initState();
_videoPlayerController =
VideoPlayerController.asset('game_assets/level2_vid.mp4');
_chewieController = ChewieController(
videoPlayerController: _videoPlayerController,
autoPlay: true,
looping: true,
allowFullScreen: false,
allowMuting: true,
aspectRatio: 16 / 11,
);
}
@override
void dispose() {
_videoPlayerController.pause();
_videoPlayerController.dispose();
_chewieController.dispose();
super.dispose();
}
void pauseVideo() {
if (_videoPlayerController.value.isPlaying) {
_videoPlayerController.pause();
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Level ${widget.level} Video'),
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
AspectRatio(
aspectRatio: 16 / 11,
child: Chewie(
controller: _chewieController,
),
),
SizedBox(height: 20),
Image.asset('game_assets/ex2_det.png'),
SizedBox(height: 40),
ElevatedButton(
onPressed: () {
pauseVideo();
Navigator.push(
context,
MaterialPageRoute(builder: (context) => ResultScreen()),
);
},
child: Text('End Watching'),
style: ElevatedButton.styleFrom(
primary: Color.fromARGB(255, 48, 173, 26),
onPrimary: Colors.white,
),
),
],
),
);
}
}
class Level3Screen extends StatelessWidget {
final int level;
const Level3Screen({required this.level});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Level $level'),
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(
padding: EdgeInsets.all(16.0),
child: Text(
'Activity List', // Change to Activity List for Level 3
style: TextStyle(
color: Color.fromARGB(255, 48, 173, 26),
fontSize: 20,
fontWeight: FontWeight.bold),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20.0),
child: ListView(
children: [
Image.asset(
'game_assets/Activity_list.png'), // Use Activity_list.png for Level 3
],
),
),
),
ElevatedButton(
onPressed: () {
// Navigate to the exercise screen
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Level3VideoScreen(level: level)),
);
},
child: Text('Start'),
style: ElevatedButton.styleFrom(
primary: Color.fromARGB(255, 43, 159, 231),
onPrimary: Colors.white,
),
),
SizedBox(height: 50),
],
),
);
}
}
class Level3VideoScreen extends StatefulWidget {
final int level;
const Level3VideoScreen({required this.level});
@override
_Level3VideoScreenState createState() => _Level3VideoScreenState();
}
class _Level3VideoScreenState extends State<Level3VideoScreen> {
late VideoPlayerController _videoPlayerController;
late ChewieController _chewieController;
@override
void initState() {
super.initState();
_videoPlayerController =
VideoPlayerController.asset('game_assets/level3_vid.mp4');
_chewieController = ChewieController(
videoPlayerController: _videoPlayerController,
autoPlay: true,
looping: true,
allowFullScreen: false,
allowMuting: true,
aspectRatio: 16 / 11,
);
}
@override
void dispose() {
_videoPlayerController.pause();
_videoPlayerController.dispose();
_chewieController.dispose();
super.dispose();
}
void pauseVideo() {
if (_videoPlayerController.value.isPlaying) {
_videoPlayerController.pause();
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Level ${widget.level} Video'),
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
AspectRatio(
aspectRatio: 16 / 11,
child: Chewie(
controller: _chewieController,
),
),
SizedBox(height: 20),
Image.asset('game_assets/ex3_det.png'),
SizedBox(height: 20),
ElevatedButton(
onPressed: () {
pauseVideo();
Navigator.push(
context,
MaterialPageRoute(builder: (context) => ResultScreen()),
);
},
child: Text('End Watching'),
style: ElevatedButton.styleFrom(
primary: Color.fromARGB(255, 48, 173, 26),
onPrimary: Colors.white,
),
),
],
),
);
}
}
class Level3ResultScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Exercise Result'),
leading: IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () {
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (context) => LevelScreen()),
);
},
),
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(height: 0),
Image.asset(
'game_assets/result3.png', // Change to result3.png for Level 3
height: 650,
width: 500, // Adjust the height of the image as needed
),
SizedBox(height: 20),
],
),
);
}
}
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,11 +27,65 @@ class GamesPage extends StatelessWidget { ...@@ -29,11 +27,65 @@ 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( child: ListTile(
contentPadding: EdgeInsets.all(16), contentPadding: EdgeInsets.all(16),
leading: Container( leading: Container(
...@@ -44,20 +96,53 @@ class GamesPage extends StatelessWidget { ...@@ -44,20 +96,53 @@ class GamesPage extends StatelessWidget {
), ),
), ),
title: Text( title: Text(
game['game'] ?? '', 'Game 3',
style: TextStyle( style: TextStyle(
fontSize: 18, fontSize: 18,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
subtitle: Text(game['description'] ?? ''), subtitle: Text('Description for Game 3'),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => EmoXApp()),
);
},
),
), ),
// Game 4 Card/Button
Card(
child: ListTile(
contentPadding: EdgeInsets.all(16),
leading: Container(
width: 50,
height: 50,
child: CircleAvatar(
backgroundImage: AssetImage(commonImagePath),
),
),
title: Text(
'Game 4',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
subtitle: Text('Description for Game 4'),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => PosturePro()),
); );
}, },
), ),
), ),
], ],
), ),
),
],
),
bottomNavigationBar: BottomNavigationBar( bottomNavigationBar: BottomNavigationBar(
items: const [ items: const [
BottomNavigationBarItem( BottomNavigationBarItem(
...@@ -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