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
* @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
*/
@ -102,87 +102,99 @@ class _WordleDisplayWidgetState extends State<WordleDisplayWidget> with TickerPr
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
for(int i = 0; i < 6; i++)
Expanded(
flex: 1,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
for(int j = 0; j < 5; j++)
AnimatedBuilder(
animation: inputs[i][j]["InputAnimationController"],
builder: (context, child) {
return Transform.scale(
scale: Tween<double>(begin: 1, end: 1.1).evaluate(inputs[i][j]["InputAnimationController"]),
child: child,
);
},
child: AspectRatio(
aspectRatio: 1,
child: LayoutBuilder(
builder: (context, constraints) {
return AnimatedSwitcher(
duration: const Duration(milliseconds: 750),
switchInCurve: Curves.easeOut,
reverseDuration: const Duration(milliseconds: 10),
transitionBuilder: (child, animation) {
return AnimatedBuilder(
animation: animation,
child: child,
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: [
for(int i = 0; i < 6; i++)
Expanded(
flex: 1,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
for (int j = 0; j < 5; j++)
AnimatedBuilder(
animation: inputs[i][j]["InputAnimationController"],
builder: (context, child) {
var _animation = Tween<double>(begin: math.pi / 2, end: 0).animate(animation);
// return ConstrainedBox(
// constraints: BoxConstraints.tightFor(height: constraints.maxHeight * _animation.value),
// child: child,
// );
return Transform(
transform: Matrix4.rotationX(_animation.value),
alignment: Alignment.center,
return Transform.scale(
scale: Tween<double>(begin: 1, end: 1.1).evaluate(inputs[i][j]["InputAnimationController"]),
child: child,
);
}
);
},
child: Padding(
key: ValueKey((inputs[i][j]["State"] == 0 || inputs[i][j]["State"] == 3) ? 0 : 1),
padding: const EdgeInsets.all(5.0),
child: DecoratedBox(
decoration: BoxDecoration(
border: Border.all(
color: inputs[i][j]["State"] == 1 ? Colors.green[600]! :
inputs[i][j]["State"] == 2 ? Colors.yellow[800]! :
inputs[i][j]["State"] == 3 ? Colors.grey[850]! :
inputs[i][j]["State"] == -1 ? Colors.grey[700]! :
Colors.grey[400]!,
width: 3.0,
},
child: AspectRatio(
aspectRatio: 1,
child: LayoutBuilder(
builder: (context, constraints) {
return AnimatedSwitcher(
duration: const Duration(milliseconds: 750),
switchInCurve: Curves.easeOut,
reverseDuration: const Duration(milliseconds: 0),
transitionBuilder: (child, animation) {
return AnimatedBuilder(
animation: animation,
child: child,
builder: (context, child) {
var _animation = Tween<double>( begin: math.pi / 2, end: 0).animate(animation);
// return ConstrainedBox(
// constraints: BoxConstraints.tightFor(height: constraints.maxHeight * _animation.value),
// child: child,
// );
return Transform(
transform: Matrix4.rotationX( _animation.value),
alignment: Alignment.center,
child: child,
);
});
},
child: Padding(
key: ValueKey((inputs[i][j]["State"] == 0 || inputs[i][j]["State"] == 3) ? 0 : 1),
padding: const EdgeInsets.all(5.0),
child: DecoratedBox(
decoration: BoxDecoration(
border: Border.all(
color: inputs[i][j]["State"] == 1 ? Colors.green[600]! :
inputs[i][j]["State"] == 2 ? Colors.yellow[800]! :
inputs[i][j]["State"] == 3 ? Colors.grey[850]! :
inputs[i][j]["State"] == -1 ? Colors.grey[700]! :
Colors.grey[400]!,
width: 2.0,
),
color: inputs[i][j]["State"] == 1 ? Colors.green[600]! :
inputs[i][j]["State"] == 2 ? Colors.yellow[800]! :
inputs[i][j]["State"] == -1 ? Colors.grey[700]! :
Colors.white,
),
child: Center(
child: Text(
inputs[i][j]["Letter"],
style: TextStyle(
color: inputs[i][j]["State"] == 3 ? Colors.grey[850]! :Colors.white,
fontSize: 30,
fontWeight: FontWeight.bold,
),
),
),
),
),
);
},
),
color: inputs[i][j]["State"] == 1 ? Colors.green[600]! :
inputs[i][j]["State"] == 2 ? Colors.yellow[800]! :
inputs[i][j]["State"] == -1 ? Colors.grey[700]! :
Colors.white,
),
child: Center(
child: Text(
inputs[i][j]["Letter"],
style: TextStyle(
color: inputs[i][j]["State"] == 3 ? Colors.grey[850]! : Colors.white,
fontSize: 30,
fontWeight: FontWeight.bold,
),
),
),
),
),
);
},
)),
],
),
),
)
),
],
],
),
),
),
),
),
const Padding(
padding: EdgeInsets.fromLTRB(10.0, 10.0, 10.0, 30.0),
child: InputPannelWidget(),

View File

@ -1,7 +1,7 @@
/*
* @Author : Linloir
* @Date : 2022-03-06 15:03:57
* @LastEditTime : 2022-03-06 16:16:14
* @LastEditTime : 2022-03-06 23:11:33
* @Description : Word generator
*/
@ -11,10 +11,31 @@ import 'dart:math';
abstract class Words {
static Set<String> dataBase = <String>{};
static int _length = 0;
//static Map<String, String> explainations = {};
static Future<void> importWordsDatabase() async {
var data = await rootBundle.loadString('assets/txt/words_alpha.txt');
dataBase.addAll(LineSplitter.split(data));
static Future<void> importWordsDatabase({int length = 5}) async {
//explainations.clear();
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{

View File

@ -1,7 +1,7 @@
/*
* @Author : Linloir
* @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
*/
@ -80,164 +80,188 @@ class _InputPannelWidgetState extends State<InputPannelWidget> {
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
return Center(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 720),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
for(int i = 0; i < 10; i++)
Padding(
padding: const EdgeInsets.fromLTRB(5.0, 5.0, 5.0, 5.0),
child: SizedBox(
width: 25.0,
height: 50.0,
child: ElevatedButton(
style: ButtonStyle(
shape: MaterialStateProperty.all<OutlinedBorder?>(RoundedRectangleBorder(borderRadius: BorderRadius.circular(5.0))),
backgroundColor: MaterialStateProperty.all<Color?>(
_keyState[_keyPos[0][i]]! == 0 ? Colors.grey[400] :
_keyState[_keyPos[0][i]]! == 1 ? Colors.green[600] :
_keyState[_keyPos[0][i]]! == 2 ? Colors.orange[600] :
Colors.grey[850]
Row(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: [
const Spacer(flex: 1,),
for(int i = 0; i < 10; i++)
Expanded(
flex: 2,
child:Padding(
padding: const EdgeInsets.fromLTRB(3.0, 5.0, 3.0, 5.0),
child: ConstrainedBox(
constraints: const BoxConstraints.expand(height: 50.0),
child: ElevatedButton(
style: ButtonStyle(
shape: MaterialStateProperty.all<OutlinedBorder?>(RoundedRectangleBorder(borderRadius: BorderRadius.circular(5.0))),
backgroundColor: MaterialStateProperty.all<Color?>(
_keyState[_keyPos[0][i]]! == 0 ? Colors.grey[400] :
_keyState[_keyPos[0][i]]! == 1 ? Colors.green[600] :
_keyState[_keyPos[0][i]]! == 2 ? Colors.orange[600] :
Colors.grey[850]
),
padding: MaterialStateProperty.all<EdgeInsets?>(const EdgeInsets.all(0)),
),
child: Center(
child: Text(
_keyPos[0][i],
style: TextStyle (
fontSize: 16,
fontWeight: FontWeight.bold,
color: _keyState[_keyPos[0][i]]! == 0 ? Colors.grey[850] : Colors.white,
),
),
),
onPressed: () {
InputNotification(type: InputType.singleCharacter, msg: _keyPos[0][i]).dispatch(context);
},
)
),
),
child: Center(
child: Text(
_keyPos[0][i],
style: TextStyle (
fontSize: 14,
fontWeight: FontWeight.bold,
color: _keyState[_keyPos[0][i]]! == 0 ? Colors.grey[850] : Colors.white,
),
),
),
onPressed: () {
InputNotification(type: InputType.singleCharacter, msg: _keyPos[0][i]).dispatch(context);
},
)
),
)
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: [
for(int i = 0; i < 9; i++)
Padding(
padding: const EdgeInsets.fromLTRB(5.0, 5.0, 5.0, 5.0),
child: SizedBox(
width: 25.0,
height: 50.0,
child: ElevatedButton(
style: ButtonStyle(
shape: MaterialStateProperty.all<OutlinedBorder?>(RoundedRectangleBorder(borderRadius: BorderRadius.circular(5.0))),
backgroundColor: MaterialStateProperty.all<Color?>(
_keyState[_keyPos[1][i]]! == 0 ? Colors.grey[400] :
_keyState[_keyPos[1][i]]! == 1 ? Colors.green[600] :
_keyState[_keyPos[1][i]]! == 2 ? Colors.orange[600] :
Colors.grey[850]
),
),
child: Center(
child: Text(
_keyPos[1][i],
style: TextStyle (
fontSize: 14,
fontWeight: FontWeight.bold,
color: _keyState[_keyPos[1][i]]! == 0 ? Colors.grey[850] : Colors.white,
),
),
),
onPressed: () {
InputNotification(type: InputType.singleCharacter, msg: _keyPos[1][i]).dispatch(context);
},
)
),
),
Padding(
padding: const EdgeInsets.fromLTRB(5.0, 5.0, 5.0, 5.0),
child: SizedBox(
width: 50,
height: 50.0,
child: ElevatedButton(
style: ButtonStyle(
shape: MaterialStateProperty.all<OutlinedBorder?>(RoundedRectangleBorder(borderRadius: BorderRadius.circular(5.0))),
backgroundColor: MaterialStateProperty.all<Color?>(Colors.grey[700]),
),
child: const Icon(
Icons.backspace_rounded,
color: Colors.white,
const Spacer(flex: 1,),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: [
for(int i = 0; i < 9; i++)
Expanded(
flex: 1,
child:Padding(
padding: const EdgeInsets.fromLTRB(3.0, 5.0, 3.0, 5.0),
child: ConstrainedBox(
constraints: const BoxConstraints.expand(height: 50.0),
child: ElevatedButton(
style: ButtonStyle(
shape: MaterialStateProperty.all<OutlinedBorder?>(RoundedRectangleBorder(borderRadius: BorderRadius.circular(5.0))),
backgroundColor: MaterialStateProperty.all<Color?>(
_keyState[_keyPos[1][i]]! == 0 ? Colors.grey[400] :
_keyState[_keyPos[1][i]]! == 1 ? Colors.green[600] :
_keyState[_keyPos[1][i]]! == 2 ? Colors.orange[600] :
Colors.grey[850]
),
padding: MaterialStateProperty.all<EdgeInsets?>(const EdgeInsets.all(0)),
),
child: Center(
child: Text(
_keyPos[1][i],
style: TextStyle (
fontSize: 16,
fontWeight: FontWeight.bold,
color: _keyState[_keyPos[1][i]]! == 0 ? Colors.grey[850] : Colors.white,
),
),
),
onPressed: () {
InputNotification(type: InputType.singleCharacter, msg: _keyPos[1][i]).dispatch(context);
},
)
),
),
),
Expanded(
flex: 2,
child: Padding(
padding: const EdgeInsets.fromLTRB(5.0, 5.0, 5.0, 5.0),
child: ConstrainedBox(
constraints: const BoxConstraints.expand(height: 50.0),
child: ElevatedButton(
style: ButtonStyle(
shape: MaterialStateProperty.all<OutlinedBorder?>(RoundedRectangleBorder(borderRadius: BorderRadius.circular(5.0))),
backgroundColor: MaterialStateProperty.all<Color?>(Colors.grey[700]),
padding: MaterialStateProperty.all<EdgeInsets?>(const EdgeInsets.all(0)),
),
child: const Icon(
Icons.keyboard_backspace_rounded,
color: Colors.white,
),
onPressed: () {
const InputNotification(type: InputType.backSpace, msg: "").dispatch(context);
},
),
),
),
onPressed: () {
const InputNotification(type: InputType.backSpace, msg: "").dispatch(context);
},
),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: [
const Spacer(flex: 1,),
for(int i = 0; i < 7; i++)
Expanded(
flex: 2,
child:Padding(
padding: const EdgeInsets.fromLTRB(3.0, 5.0, 3.0, 5.0),
child: ConstrainedBox(
constraints: const BoxConstraints.expand(height: 50.0),
child: ElevatedButton(
style: ButtonStyle(
shape: MaterialStateProperty.all<OutlinedBorder?>(RoundedRectangleBorder(borderRadius: BorderRadius.circular(5.0))),
backgroundColor: MaterialStateProperty.all<Color?>(
_keyState[_keyPos[2][i]]! == 0 ? Colors.grey[400] :
_keyState[_keyPos[2][i]]! == 1 ? Colors.green[600] :
_keyState[_keyPos[2][i]]! == 2 ? Colors.orange[600] :
Colors.grey[850]
),
padding: MaterialStateProperty.all<EdgeInsets?>(const EdgeInsets.all(0)),
),
child: Center(
child: Text(
_keyPos[2][i],
style: TextStyle (
fontSize: 16,
fontWeight: FontWeight.bold,
color: _keyState[_keyPos[2][i]]! == 0 ? Colors.grey[850] : Colors.white,
),
),
),
onPressed: () {
InputNotification(type: InputType.singleCharacter, msg: _keyPos[2][i]).dispatch(context);
},
)
),
),
),
Expanded(
flex: 6,
child: Padding(
padding: const EdgeInsets.fromLTRB(5.0, 5.0, 5.0, 5.0),
child: ConstrainedBox(
constraints: const BoxConstraints.expand(height: 50.0),
child: ElevatedButton(
style: ButtonStyle(
shape: MaterialStateProperty.all<OutlinedBorder?>(RoundedRectangleBorder(borderRadius: BorderRadius.circular(5.0))),
backgroundColor: MaterialStateProperty.all<Color?>(Colors.green[600]),
padding: MaterialStateProperty.all<EdgeInsets?>(const EdgeInsets.all(0)),
),
child: const Icon(
Icons.keyboard_return_rounded,
color: Colors.white,
),
onPressed: () {
const InputNotification(type: InputType.inputConfirmation, msg: "").dispatch(context);
},
),
),
),
),
const Spacer(flex: 1,),
],
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: [
for(int i = 0; i < 7; i++)
Padding(
padding: const EdgeInsets.fromLTRB(5.0, 5.0, 5.0, 5.0),
child: SizedBox(
width: 25.0,
height: 50.0,
child: ElevatedButton(
style: ButtonStyle(
shape: MaterialStateProperty.all<OutlinedBorder?>(RoundedRectangleBorder(borderRadius: BorderRadius.circular(5.0))),
backgroundColor: MaterialStateProperty.all<Color?>(
_keyState[_keyPos[2][i]]! == 0 ? Colors.grey[400] :
_keyState[_keyPos[2][i]]! == 1 ? Colors.green[600] :
_keyState[_keyPos[2][i]]! == 2 ? Colors.orange[600] :
Colors.grey[850]
),
),
child: Center(
child: Text(
_keyPos[2][i],
style: TextStyle (
fontSize: 14,
fontWeight: FontWeight.bold,
color: _keyState[_keyPos[2][i]]! == 0 ? Colors.grey[850] : Colors.white,
),
),
),
onPressed: () {
InputNotification(type: InputType.singleCharacter, msg: _keyPos[2][i]).dispatch(context);
},
)
),
),
Padding(
padding: const EdgeInsets.fromLTRB(5.0, 5.0, 5.0, 5.0),
child: SizedBox(
width: 70,
height: 50.0,
child: ElevatedButton(
style: ButtonStyle(
shape: MaterialStateProperty.all<OutlinedBorder?>(RoundedRectangleBorder(borderRadius: BorderRadius.circular(5.0))),
backgroundColor: MaterialStateProperty.all<Color?>(Colors.green[600]),
),
child: const Icon(
Icons.keyboard_return_rounded,
color: Colors.white,
),
onPressed: () {
const InputNotification(type: InputType.inputConfirmation, msg: "").dispatch(context);
},
),
),
)
],
),
],
),
);
}
}

View File

@ -1,10 +1,11 @@
/*
* @Author : Linloir
* @Date : 2022-03-05 20:21:34
* @LastEditTime : 2022-03-06 16:08:09
* @LastEditTime : 2022-03-06 23:07:38
* @Description :
*/
import 'package:flutter/material.dart';
import 'package:wordle/event_bus.dart';
import './offline.dart';
import './generator.dart';
@ -21,12 +22,13 @@ class MyApp extends StatelessWidget {
return MaterialApp(
title: 'Wordle',
theme: ThemeData(
primarySwatch: Colors.blue
primarySwatch: Colors.grey
),
routes: {
"/": (context) => const HomePage(),
"/Offline": (context) => const OfflinePage(),
},
initialRoute: "/",
);
}
}
@ -42,20 +44,88 @@ class HomePage extends StatelessWidget {
if(snapshot.connectionState == ConnectionState.done) {
return Scaffold(
body: Center(
child: ElevatedButton(
child: const Text('Offline'),
onPressed: () => Navigator.of(context).pushNamed("/Offline"),
),
child: Padding(
padding: const EdgeInsets.all(50.0),
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 {
return const Center(
child: SizedBox(
height: 100.0,
width: 100.0,
child: CircularProgressIndicator(
strokeWidth: 5.0,
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
height: 60.0,
width: 60.0,
child: CircularProgressIndicator(
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
* @Date : 2022-03-05 20:41:41
* @LastEditTime : 2022-03-06 17:25:21
* @LastEditTime : 2022-03-06 22:59:34
* @Description : Offline page
*/
@ -44,9 +44,12 @@ class _OfflinePageState extends State<OfflinePage> {
)
],
),
body: const ValidationProvider(
child: WordleDisplayWidget(),
)
body: Container(
child: const ValidationProvider(
child: WordleDisplayWidget(),
),
color: Colors.white,
),
);
}
}

View File

@ -1,7 +1,7 @@
/*
* @Author : Linloir
* @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
*/
@ -72,7 +72,7 @@ class _ValidationProviderState extends State<ValidationProvider> {
builder: (context) {
return AlertDialog(
title: const Text('Result'),
content: Text(result ? "Won" : "Lost"),
content: Text(result ? "Won" : "Lost, answer is $answer"),
actions: [
TextButton(
child: const Text('Back'),

View File

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