Fixed bugs and changed database

This commit is contained in:
Linloir 2022-03-07 00:00:41 +08:00
parent 6410944990
commit c67dce436e
9 changed files with 236265 additions and 16173 deletions

File diff suppressed because it is too large Load Diff

235887
assets/unixWords.txt Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
/* /*
* @Author : Linloir * @Author : Linloir
* @Date : 2022-03-05 20:56:05 * @Date : 2022-03-05 20:56:05
* @LastEditTime : 2022-03-06 17:32:26 * @LastEditTime : 2022-03-06 23:01:03
* @Description : The display widget of the wordle game * @Description : The display widget of the wordle game
*/ */
@ -101,6 +101,16 @@ class _WordleDisplayWidgetState extends State<WordleDisplayWidget> with TickerPr
return NotificationListener<InputNotification>( return NotificationListener<InputNotification>(
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
child: Padding(
padding: const EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 0.0),
child: Align(
alignment: Alignment.center,
child: AspectRatio(
aspectRatio: 5 / 6,
child: Column(
//Column(
children: [ children: [
for(int i = 0; i < 6; i++) for(int i = 0; i < 6; i++)
Expanded( Expanded(
@ -124,7 +134,7 @@ class _WordleDisplayWidgetState extends State<WordleDisplayWidget> with TickerPr
return AnimatedSwitcher( return AnimatedSwitcher(
duration: const Duration(milliseconds: 750), duration: const Duration(milliseconds: 750),
switchInCurve: Curves.easeOut, switchInCurve: Curves.easeOut,
reverseDuration: const Duration(milliseconds: 10), reverseDuration: const Duration(milliseconds: 0),
transitionBuilder: (child, animation) { transitionBuilder: (child, animation) {
return AnimatedBuilder( return AnimatedBuilder(
animation: animation, animation: animation,
@ -140,8 +150,7 @@ class _WordleDisplayWidgetState extends State<WordleDisplayWidget> with TickerPr
alignment: Alignment.center, alignment: Alignment.center,
child: child, child: child,
); );
} });
);
}, },
child: Padding( child: Padding(
key: ValueKey((inputs[i][j]["State"] == 0 || inputs[i][j]["State"] == 3) ? 0 : 1), key: ValueKey((inputs[i][j]["State"] == 0 || inputs[i][j]["State"] == 3) ? 0 : 1),
@ -154,7 +163,7 @@ class _WordleDisplayWidgetState extends State<WordleDisplayWidget> with TickerPr
inputs[i][j]["State"] == 3 ? Colors.grey[850]! : inputs[i][j]["State"] == 3 ? Colors.grey[850]! :
inputs[i][j]["State"] == -1 ? Colors.grey[700]! : inputs[i][j]["State"] == -1 ? Colors.grey[700]! :
Colors.grey[400]!, Colors.grey[400]!,
width: 3.0, width: 2.0,
), ),
color: inputs[i][j]["State"] == 1 ? Colors.green[600]! : color: inputs[i][j]["State"] == 1 ? Colors.green[600]! :
inputs[i][j]["State"] == 2 ? Colors.yellow[800]! : inputs[i][j]["State"] == 2 ? Colors.yellow[800]! :
@ -175,14 +184,17 @@ class _WordleDisplayWidgetState extends State<WordleDisplayWidget> with TickerPr
), ),
); );
}, },
), ),
) )),
],
),
), ),
], ],
), ),
), ),
),
),
),
const Padding( const Padding(
padding: EdgeInsets.fromLTRB(10.0, 10.0, 10.0, 30.0), padding: EdgeInsets.fromLTRB(10.0, 10.0, 10.0, 30.0),
child: InputPannelWidget(), child: InputPannelWidget(),

View File

@ -1,7 +1,7 @@
/* /*
* @Author : Linloir * @Author : Linloir
* @Date : 2022-03-06 15:03:57 * @Date : 2022-03-06 15:03:57
* @LastEditTime : 2022-03-06 16:16:14 * @LastEditTime : 2022-03-06 23:11:33
* @Description : Word generator * @Description : Word generator
*/ */
@ -11,10 +11,31 @@ import 'dart:math';
abstract class Words { abstract class Words {
static Set<String> dataBase = <String>{}; static Set<String> dataBase = <String>{};
static int _length = 0;
//static Map<String, String> explainations = {};
static Future<void> importWordsDatabase() async { static Future<void> importWordsDatabase({int length = 5}) async {
var data = await rootBundle.loadString('assets/txt/words_alpha.txt'); //explainations.clear();
dataBase.addAll(LineSplitter.split(data)); if(length != _length){
_length = length;
dataBase.clear();
var data = await rootBundle.loadString('assets/unixWords.txt');
// LineSplitter.split(data).forEach((line) {
// int seperatePos = line.indexOf(',');
// if(seperatePos != length + 2) {
// return;
// }
// var word = line.substring(1, seperatePos - 1);
// var expl = line.substring(seperatePos + 2, line.length - 1);
// dataBase.add(word);
// explainations[word] = expl;
// });
LineSplitter.split(data).forEach((line) {
if(line.length == length) {
dataBase.add(line);
}
});
}
} }
static Future<String> generateWord() async{ static Future<String> generateWord() async{

View File

@ -1,7 +1,7 @@
/* /*
* @Author : Linloir * @Author : Linloir
* @Date : 2022-03-05 20:55:53 * @Date : 2022-03-05 20:55:53
* @LastEditTime : 2022-03-06 17:28:40 * @LastEditTime : 2022-03-06 21:44:36
* @Description : Input pannel class * @Description : Input pannel class
*/ */
@ -80,19 +80,24 @@ class _InputPannelWidgetState extends State<InputPannelWidget> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Column( return Center(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 720),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: [ children: [
Row( Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.max, mainAxisSize: MainAxisSize.max,
children: [ children: [
const Spacer(flex: 1,),
for(int i = 0; i < 10; i++) for(int i = 0; i < 10; i++)
Padding( Expanded(
padding: const EdgeInsets.fromLTRB(5.0, 5.0, 5.0, 5.0), flex: 2,
child: SizedBox( child:Padding(
width: 25.0, padding: const EdgeInsets.fromLTRB(3.0, 5.0, 3.0, 5.0),
height: 50.0, child: ConstrainedBox(
constraints: const BoxConstraints.expand(height: 50.0),
child: ElevatedButton( child: ElevatedButton(
style: ButtonStyle( style: ButtonStyle(
shape: MaterialStateProperty.all<OutlinedBorder?>(RoundedRectangleBorder(borderRadius: BorderRadius.circular(5.0))), shape: MaterialStateProperty.all<OutlinedBorder?>(RoundedRectangleBorder(borderRadius: BorderRadius.circular(5.0))),
@ -102,12 +107,13 @@ class _InputPannelWidgetState extends State<InputPannelWidget> {
_keyState[_keyPos[0][i]]! == 2 ? Colors.orange[600] : _keyState[_keyPos[0][i]]! == 2 ? Colors.orange[600] :
Colors.grey[850] Colors.grey[850]
), ),
padding: MaterialStateProperty.all<EdgeInsets?>(const EdgeInsets.all(0)),
), ),
child: Center( child: Center(
child: Text( child: Text(
_keyPos[0][i], _keyPos[0][i],
style: TextStyle ( style: TextStyle (
fontSize: 14, fontSize: 16,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
color: _keyState[_keyPos[0][i]]! == 0 ? Colors.grey[850] : Colors.white, color: _keyState[_keyPos[0][i]]! == 0 ? Colors.grey[850] : Colors.white,
), ),
@ -118,7 +124,9 @@ class _InputPannelWidgetState extends State<InputPannelWidget> {
}, },
) )
), ),
) ),
),
const Spacer(flex: 1,),
], ],
), ),
Row( Row(
@ -126,11 +134,12 @@ class _InputPannelWidgetState extends State<InputPannelWidget> {
mainAxisSize: MainAxisSize.max, mainAxisSize: MainAxisSize.max,
children: [ children: [
for(int i = 0; i < 9; i++) for(int i = 0; i < 9; i++)
Padding( Expanded(
padding: const EdgeInsets.fromLTRB(5.0, 5.0, 5.0, 5.0), flex: 1,
child: SizedBox( child:Padding(
width: 25.0, padding: const EdgeInsets.fromLTRB(3.0, 5.0, 3.0, 5.0),
height: 50.0, child: ConstrainedBox(
constraints: const BoxConstraints.expand(height: 50.0),
child: ElevatedButton( child: ElevatedButton(
style: ButtonStyle( style: ButtonStyle(
shape: MaterialStateProperty.all<OutlinedBorder?>(RoundedRectangleBorder(borderRadius: BorderRadius.circular(5.0))), shape: MaterialStateProperty.all<OutlinedBorder?>(RoundedRectangleBorder(borderRadius: BorderRadius.circular(5.0))),
@ -140,12 +149,13 @@ class _InputPannelWidgetState extends State<InputPannelWidget> {
_keyState[_keyPos[1][i]]! == 2 ? Colors.orange[600] : _keyState[_keyPos[1][i]]! == 2 ? Colors.orange[600] :
Colors.grey[850] Colors.grey[850]
), ),
padding: MaterialStateProperty.all<EdgeInsets?>(const EdgeInsets.all(0)),
), ),
child: Center( child: Center(
child: Text( child: Text(
_keyPos[1][i], _keyPos[1][i],
style: TextStyle ( style: TextStyle (
fontSize: 14, fontSize: 16,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
color: _keyState[_keyPos[1][i]]! == 0 ? Colors.grey[850] : Colors.white, color: _keyState[_keyPos[1][i]]! == 0 ? Colors.grey[850] : Colors.white,
), ),
@ -157,18 +167,21 @@ class _InputPannelWidgetState extends State<InputPannelWidget> {
) )
), ),
), ),
Padding( ),
Expanded(
flex: 2,
child: Padding(
padding: const EdgeInsets.fromLTRB(5.0, 5.0, 5.0, 5.0), padding: const EdgeInsets.fromLTRB(5.0, 5.0, 5.0, 5.0),
child: SizedBox( child: ConstrainedBox(
width: 50, constraints: const BoxConstraints.expand(height: 50.0),
height: 50.0,
child: ElevatedButton( child: ElevatedButton(
style: ButtonStyle( style: ButtonStyle(
shape: MaterialStateProperty.all<OutlinedBorder?>(RoundedRectangleBorder(borderRadius: BorderRadius.circular(5.0))), shape: MaterialStateProperty.all<OutlinedBorder?>(RoundedRectangleBorder(borderRadius: BorderRadius.circular(5.0))),
backgroundColor: MaterialStateProperty.all<Color?>(Colors.grey[700]), backgroundColor: MaterialStateProperty.all<Color?>(Colors.grey[700]),
padding: MaterialStateProperty.all<EdgeInsets?>(const EdgeInsets.all(0)),
), ),
child: const Icon( child: const Icon(
Icons.backspace_rounded, Icons.keyboard_backspace_rounded,
color: Colors.white, color: Colors.white,
), ),
onPressed: () { onPressed: () {
@ -177,18 +190,21 @@ class _InputPannelWidgetState extends State<InputPannelWidget> {
), ),
), ),
), ),
),
], ],
), ),
Row( Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.max, mainAxisSize: MainAxisSize.max,
children: [ children: [
const Spacer(flex: 1,),
for(int i = 0; i < 7; i++) for(int i = 0; i < 7; i++)
Padding( Expanded(
padding: const EdgeInsets.fromLTRB(5.0, 5.0, 5.0, 5.0), flex: 2,
child: SizedBox( child:Padding(
width: 25.0, padding: const EdgeInsets.fromLTRB(3.0, 5.0, 3.0, 5.0),
height: 50.0, child: ConstrainedBox(
constraints: const BoxConstraints.expand(height: 50.0),
child: ElevatedButton( child: ElevatedButton(
style: ButtonStyle( style: ButtonStyle(
shape: MaterialStateProperty.all<OutlinedBorder?>(RoundedRectangleBorder(borderRadius: BorderRadius.circular(5.0))), shape: MaterialStateProperty.all<OutlinedBorder?>(RoundedRectangleBorder(borderRadius: BorderRadius.circular(5.0))),
@ -198,12 +214,13 @@ class _InputPannelWidgetState extends State<InputPannelWidget> {
_keyState[_keyPos[2][i]]! == 2 ? Colors.orange[600] : _keyState[_keyPos[2][i]]! == 2 ? Colors.orange[600] :
Colors.grey[850] Colors.grey[850]
), ),
padding: MaterialStateProperty.all<EdgeInsets?>(const EdgeInsets.all(0)),
), ),
child: Center( child: Center(
child: Text( child: Text(
_keyPos[2][i], _keyPos[2][i],
style: TextStyle ( style: TextStyle (
fontSize: 14, fontSize: 16,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
color: _keyState[_keyPos[2][i]]! == 0 ? Colors.grey[850] : Colors.white, color: _keyState[_keyPos[2][i]]! == 0 ? Colors.grey[850] : Colors.white,
), ),
@ -215,15 +232,18 @@ class _InputPannelWidgetState extends State<InputPannelWidget> {
) )
), ),
), ),
Padding( ),
Expanded(
flex: 6,
child: Padding(
padding: const EdgeInsets.fromLTRB(5.0, 5.0, 5.0, 5.0), padding: const EdgeInsets.fromLTRB(5.0, 5.0, 5.0, 5.0),
child: SizedBox( child: ConstrainedBox(
width: 70, constraints: const BoxConstraints.expand(height: 50.0),
height: 50.0,
child: ElevatedButton( child: ElevatedButton(
style: ButtonStyle( style: ButtonStyle(
shape: MaterialStateProperty.all<OutlinedBorder?>(RoundedRectangleBorder(borderRadius: BorderRadius.circular(5.0))), shape: MaterialStateProperty.all<OutlinedBorder?>(RoundedRectangleBorder(borderRadius: BorderRadius.circular(5.0))),
backgroundColor: MaterialStateProperty.all<Color?>(Colors.green[600]), backgroundColor: MaterialStateProperty.all<Color?>(Colors.green[600]),
padding: MaterialStateProperty.all<EdgeInsets?>(const EdgeInsets.all(0)),
), ),
child: const Icon( child: const Icon(
Icons.keyboard_return_rounded, Icons.keyboard_return_rounded,
@ -234,10 +254,14 @@ class _InputPannelWidgetState extends State<InputPannelWidget> {
}, },
), ),
), ),
) ),
),
const Spacer(flex: 1,),
], ],
), ),
], ],
),
),
); );
} }
} }

View File

@ -1,10 +1,11 @@
/* /*
* @Author : Linloir * @Author : Linloir
* @Date : 2022-03-05 20:21:34 * @Date : 2022-03-05 20:21:34
* @LastEditTime : 2022-03-06 16:08:09 * @LastEditTime : 2022-03-06 23:07:38
* @Description : * @Description :
*/ */
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:wordle/event_bus.dart';
import './offline.dart'; import './offline.dart';
import './generator.dart'; import './generator.dart';
@ -21,12 +22,13 @@ class MyApp extends StatelessWidget {
return MaterialApp( return MaterialApp(
title: 'Wordle', title: 'Wordle',
theme: ThemeData( theme: ThemeData(
primarySwatch: Colors.blue primarySwatch: Colors.grey
), ),
routes: { routes: {
"/": (context) => const HomePage(), "/": (context) => const HomePage(),
"/Offline": (context) => const OfflinePage(), "/Offline": (context) => const OfflinePage(),
}, },
initialRoute: "/",
); );
} }
} }
@ -42,20 +44,88 @@ class HomePage extends StatelessWidget {
if(snapshot.connectionState == ConnectionState.done) { if(snapshot.connectionState == ConnectionState.done) {
return Scaffold( return Scaffold(
body: Center( body: Center(
child: ElevatedButton( child: Padding(
child: const Text('Offline'), padding: const EdgeInsets.all(50.0),
onPressed: () => Navigator.of(context).pushNamed("/Offline"), child: AspectRatio(
aspectRatio: 16 / 9,
child: OutlinedButton(
child: Padding(
padding: const EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
child: Align(
alignment: Alignment.centerLeft,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'OFFLINE PLAYGROUND',
style: TextStyle(
color: Colors.grey[850]!,
fontSize: 20.0,
fontWeight: FontWeight.bold
), ),
), ),
// Padding(
// padding: const EdgeInsets.symmetric(vertical: 8.0),
// child: Container(
// width: 80.0,
// height: 8.0,
// decoration: BoxDecoration(
// color: Colors.grey[800],
// borderRadius: BorderRadius.circular(3.5),
// ),
// ),
// ),
Text(
'Play Wordle game offline using local word database',
style: TextStyle(
color: Colors.grey[500],
fontSize: 12.0,
),
),
],
),
),
),
style: ButtonStyle(
shape: MaterialStateProperty.all<OutlinedBorder?>(RoundedRectangleBorder(borderRadius: BorderRadius.circular(10))),
padding: MaterialStateProperty.all<EdgeInsets?>(const EdgeInsets.all(0)),
),
onPressed: () {
Navigator.of(context).pushNamed("/Offline");
mainBus.emit(event: "NewGame", args: []);
}
)
),
)
),
); );
} }
else { else {
return const Center( return Scaffold(
child: SizedBox( body: Center(
height: 100.0, child: Column(
width: 100.0, mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
height: 60.0,
width: 60.0,
child: CircularProgressIndicator( child: CircularProgressIndicator(
strokeWidth: 5.0, strokeWidth: 6.0,
color: Colors.grey[850],
),
),
Padding(
padding: const EdgeInsets.all(30.0),
child: Text('Loading library',
style: TextStyle(
color: Colors.grey[850]!,
fontSize: 16.0,
fontWeight: FontWeight.bold,
),
),
),
],
), ),
), ),
); );

View File

@ -1,7 +1,7 @@
/* /*
* @Author : Linloir * @Author : Linloir
* @Date : 2022-03-05 20:41:41 * @Date : 2022-03-05 20:41:41
* @LastEditTime : 2022-03-06 17:25:21 * @LastEditTime : 2022-03-06 22:59:34
* @Description : Offline page * @Description : Offline page
*/ */
@ -44,9 +44,12 @@ class _OfflinePageState extends State<OfflinePage> {
) )
], ],
), ),
body: const ValidationProvider( body: Container(
child: const ValidationProvider(
child: WordleDisplayWidget(), child: WordleDisplayWidget(),
) ),
color: Colors.white,
),
); );
} }
} }

View File

@ -1,7 +1,7 @@
/* /*
* @Author : Linloir * @Author : Linloir
* @Date : 2022-03-05 21:40:51 * @Date : 2022-03-05 21:40:51
* @LastEditTime : 2022-03-06 16:17:30 * @LastEditTime : 2022-03-06 23:13:23
* @Description : Validation Provider class * @Description : Validation Provider class
*/ */
@ -72,7 +72,7 @@ class _ValidationProviderState extends State<ValidationProvider> {
builder: (context) { builder: (context) {
return AlertDialog( return AlertDialog(
title: const Text('Result'), title: const Text('Result'),
content: Text(result ? "Won" : "Lost"), content: Text(result ? "Won" : "Lost, answer is $answer"),
actions: [ actions: [
TextButton( TextButton(
child: const Text('Back'), child: const Text('Back'),

View File

@ -62,7 +62,7 @@ flutter:
# - images/a_dot_burr.jpeg # - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg # - images/a_dot_ham.jpeg
assets: assets:
- assets/words_alpha.txt - assets/unixWords.txt
# An image asset can refer to one or more resolution-specific "variants", see # An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware. # https://flutter.dev/assets-and-images/#resolution-aware.