rename container folders
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
class BoardSquare {
|
||||
bool hasBomb;
|
||||
int bombsAround;
|
||||
bool isOpened;
|
||||
bool isFlagged;
|
||||
|
||||
BoardSquare({
|
||||
this.hasBomb = false,
|
||||
this.bombsAround = 0,
|
||||
this.isOpened = false,
|
||||
this.isFlagged = false,
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:ken_logger/ken_logger.dart';
|
||||
import 'package:mzansi_innovation_hub/main.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_circle_avatar.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart';
|
||||
import 'package:redacted/redacted.dart';
|
||||
|
||||
class LeaderboardUserRanking extends StatelessWidget {
|
||||
final int index;
|
||||
final String proPicUrl;
|
||||
final String username;
|
||||
final dynamic gameScore;
|
||||
final String gameTime;
|
||||
final bool isCurrentUser;
|
||||
final Future<ImageProvider<Object>?> Function(String) getUserPicture;
|
||||
|
||||
const LeaderboardUserRanking({
|
||||
super.key,
|
||||
required this.index,
|
||||
required this.proPicUrl,
|
||||
required this.username,
|
||||
required this.gameScore,
|
||||
required this.gameTime,
|
||||
required this.isCurrentUser,
|
||||
required this.getUserPicture,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FutureBuilder(
|
||||
future: getUserPicture(proPicUrl),
|
||||
builder: (context, asyncSnapshot) {
|
||||
bool isLoading =
|
||||
asyncSnapshot.connectionState == ConnectionState.waiting;
|
||||
|
||||
KenLogger.success("URL: ${asyncSnapshot.data.toString()}");
|
||||
return ListTile(
|
||||
leading: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
"#${index + 1}",
|
||||
style: const TextStyle(
|
||||
fontSize: 25,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
MihCircleAvatar(
|
||||
key: ValueKey(asyncSnapshot.data
|
||||
.toString()), // Use ValueKey for stable identity
|
||||
imageFile: asyncSnapshot.data,
|
||||
width: 60,
|
||||
editable: false,
|
||||
fileNameController: null,
|
||||
userSelectedfile: null,
|
||||
frameColor: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
backgroundColor: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
onChange: () {},
|
||||
),
|
||||
],
|
||||
),
|
||||
title: Text(
|
||||
"$username${isCurrentUser ? " (You)" : ""}",
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
),
|
||||
).redacted(context: context, redact: isLoading),
|
||||
subtitle: Text(
|
||||
"Score: $gameScore\nTime: $gameTime",
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
color: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
),
|
||||
).redacted(context: context, redact: isLoading),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:mzansi_innovation_hub/main.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_button.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_dropdwn_field.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_form.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_package_window.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_providers/mih_mine_sweeper_provider.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class MihMineSweeperStartGameWindow extends StatefulWidget {
|
||||
final void Function()? onPressed;
|
||||
const MihMineSweeperStartGameWindow({
|
||||
super.key,
|
||||
required this.onPressed,
|
||||
});
|
||||
|
||||
@override
|
||||
State<MihMineSweeperStartGameWindow> createState() =>
|
||||
_MihMineSweeperStartGameWindowState();
|
||||
}
|
||||
|
||||
class _MihMineSweeperStartGameWindowState
|
||||
extends State<MihMineSweeperStartGameWindow> {
|
||||
TextEditingController modeController = TextEditingController();
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
|
||||
void applyGameSettings(MihMineSweeperProvider mihMineSweeperProvider) {
|
||||
mihMineSweeperProvider.setDifficulty(modeController.text);
|
||||
switch (mihMineSweeperProvider.difficulty) {
|
||||
case ("Very Easy"):
|
||||
mihMineSweeperProvider.setRowCount(6);
|
||||
mihMineSweeperProvider.setCoulmnCount(6);
|
||||
mihMineSweeperProvider.setTotalMines(5);
|
||||
// mihMineSweeperProvider.setRowCount(5);
|
||||
// mihMineSweeperProvider.setCoulmnCount(5);
|
||||
// mihMineSweeperProvider.setTotalMines(3);
|
||||
break;
|
||||
case ("Easy"):
|
||||
mihMineSweeperProvider.setRowCount(8);
|
||||
mihMineSweeperProvider.setCoulmnCount(8);
|
||||
mihMineSweeperProvider.setTotalMines(10);
|
||||
// mihMineSweeperProvider.setRowCount(10);
|
||||
// mihMineSweeperProvider.setCoulmnCount(10);
|
||||
// mihMineSweeperProvider.setTotalMines(15);
|
||||
break;
|
||||
case ("Intermediate"):
|
||||
mihMineSweeperProvider.setRowCount(10);
|
||||
mihMineSweeperProvider.setCoulmnCount(10);
|
||||
mihMineSweeperProvider.setTotalMines(18);
|
||||
// mihMineSweeperProvider.setRowCount(15);
|
||||
// mihMineSweeperProvider.setCoulmnCount(10);
|
||||
// mihMineSweeperProvider.setTotalMines(23);
|
||||
break;
|
||||
case ("Hard"):
|
||||
mihMineSweeperProvider.setRowCount(12);
|
||||
mihMineSweeperProvider.setCoulmnCount(10);
|
||||
mihMineSweeperProvider.setTotalMines(30);
|
||||
// mihMineSweeperProvider.setRowCount(20);
|
||||
// mihMineSweeperProvider.setCoulmnCount(10);
|
||||
// mihMineSweeperProvider.setTotalMines(30);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
String getModeConfig() {
|
||||
switch (modeController.text) {
|
||||
case ("Very Easy"):
|
||||
return "Columns: 6\nRows: 6\nBombs: 5";
|
||||
case ("Easy"):
|
||||
return "Columns: 8\nRows: 8\nBombs: 10";
|
||||
case ("Intermediate"):
|
||||
return "Columns: 10\nRows: 10\nBombs: 18";
|
||||
case ("Hard"):
|
||||
return "Columns: 10\nRows: 12\nBombs: 30";
|
||||
default:
|
||||
return "Error";
|
||||
}
|
||||
}
|
||||
|
||||
void _onModeChanged() {
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
modeController.removeListener(_onModeChanged);
|
||||
modeController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
modeController.text = context.read<MihMineSweeperProvider>().difficulty;
|
||||
modeController.addListener(_onModeChanged);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MihPackageWindow(
|
||||
fullscreen: false,
|
||||
windowTitle: "New Game Settings",
|
||||
onWindowTapClose: () {
|
||||
context.pop();
|
||||
},
|
||||
windowBody: Consumer<MihMineSweeperProvider>(
|
||||
builder: (BuildContext context,
|
||||
MihMineSweeperProvider mihMineSweeperProvider, Widget? child) {
|
||||
return Column(
|
||||
children: [
|
||||
MihForm(
|
||||
formKey: _formKey,
|
||||
formFields: [
|
||||
MihDropdownField(
|
||||
controller: modeController,
|
||||
hintText: "Difficulty",
|
||||
dropdownOptions: [
|
||||
"Very Easy",
|
||||
"Easy",
|
||||
"Intermediate",
|
||||
"Hard"
|
||||
],
|
||||
requiredText: true,
|
||||
editable: true,
|
||||
enableSearch: false,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Text(
|
||||
getModeConfig(),
|
||||
style: TextStyle(
|
||||
color: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 25),
|
||||
Center(
|
||||
child: MihButton(
|
||||
onPressed: () {
|
||||
applyGameSettings(mihMineSweeperProvider);
|
||||
context.pop();
|
||||
widget.onPressed?.call();
|
||||
},
|
||||
buttonColor: MihColors.getGreenColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
width: 300,
|
||||
child: Text(
|
||||
"Start Game",
|
||||
style: TextStyle(
|
||||
color: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
112
mih_ui/lib/mih_packages/mine_sweeper/components/mine_tile.dart
Normal file
112
mih_ui/lib/mih_packages/mine_sweeper/components/mine_tile.dart
Normal file
@@ -0,0 +1,112 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:mzansi_innovation_hub/main.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_button.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_packages/mine_sweeper/components/board_square.dart';
|
||||
|
||||
class MineTile extends StatelessWidget {
|
||||
final BoardSquare square;
|
||||
final VoidCallback onTap;
|
||||
final VoidCallback onLongPress;
|
||||
|
||||
const MineTile({
|
||||
super.key,
|
||||
required this.square,
|
||||
required this.onTap,
|
||||
required this.onLongPress,
|
||||
});
|
||||
|
||||
Widget _getTileContent(BuildContext context) {
|
||||
if (square.isFlagged) {
|
||||
return Icon(
|
||||
Icons.flag,
|
||||
color: MihColors.getRedColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode != "Dark",
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (square.isOpened) {
|
||||
if (square.hasBomb) {
|
||||
return const Icon(FontAwesomeIcons.bomb, color: Colors.black);
|
||||
} else if (square.bombsAround > 0) {
|
||||
// Display bomb count
|
||||
return Center(
|
||||
child: Text(
|
||||
'${square.bombsAround}',
|
||||
style: TextStyle(
|
||||
fontSize: 25,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: _getTileColor(square.bombsAround, context),
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
// Opened, but no bomb count (empty square)
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
}
|
||||
|
||||
// Default: Unopened tile
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
Color _getTileColor(int bombsAround, BuildContext context) {
|
||||
// Choose colors based on standard Minesweeper appearance
|
||||
switch (bombsAround) {
|
||||
case 1:
|
||||
return MihColors.getBluishPurpleColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode != "Dark",
|
||||
);
|
||||
// return Colors.blue;
|
||||
case 2:
|
||||
return MihColors.getGreenColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode != "Dark",
|
||||
);
|
||||
// return Colors.green;
|
||||
case 3:
|
||||
return MihColors.getRedColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode != "Dark",
|
||||
);
|
||||
// return Colors.red;
|
||||
case 4:
|
||||
return MihColors.getPurpleColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode != "Dark",
|
||||
);
|
||||
// return Colors.purple;
|
||||
case 5:
|
||||
return MihColors.getOrangeColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode != "Dark",
|
||||
);
|
||||
// return Colors.brown;
|
||||
default:
|
||||
// return MihColors.getBluishPurpleColor(
|
||||
// MzansiInnovationHub.of(context)!.theme.mode == "Dark",
|
||||
// );
|
||||
return Colors.black;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(1.0),
|
||||
child: MihButton(
|
||||
onPressed: onTap,
|
||||
onLongPressed: onLongPress,
|
||||
buttonColor: square.isOpened
|
||||
? MihColors.getGreyColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark",
|
||||
)
|
||||
: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark",
|
||||
),
|
||||
width: 50,
|
||||
height: 50,
|
||||
borderRadius: 3,
|
||||
child: _getTileContent(context),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user