Update match creation to support 2v2 matches using TrueSkill as the ranking system

This commit is contained in:
Mercurio 2025-01-21 22:39:47 +01:00
parent b304ab3a7b
commit 94088c0338
2 changed files with 70 additions and 4 deletions

View file

@ -12,6 +12,7 @@ class CreateMatchPage extends StatefulWidget {
class _CreateMatchPageState extends State<CreateMatchPage> { class _CreateMatchPageState extends State<CreateMatchPage> {
String? _matchId; String? _matchId;
bool _isLoading = false; bool _isLoading = false;
bool _isTwoPlayerModeEnabled = false; // Track the toggle state
final String _createMatchApiUrl = '$apiurl/creatematch'; final String _createMatchApiUrl = '$apiurl/creatematch';
@ -101,6 +102,20 @@ class _CreateMatchPageState extends State<CreateMatchPage> {
child: Text('Create Match'), child: Text('Create Match'),
), ),
SizedBox(height: 16), SizedBox(height: 16),
SwitchListTile(
title: Text('Enable 2 player mode'),
value: _isTwoPlayerModeEnabled,
onChanged: (bool value) {
setState(() {
_isTwoPlayerModeEnabled = value;
});
if (_isTwoPlayerModeEnabled) {
_showToast(
'We\'re sorry, this feature isn\'t available yet');
}
},
),
SizedBox(height: 16),
if (_matchId != null) if (_matchId != null)
Text( Text(
'Your Match ID: $_matchId', 'Your Match ID: $_matchId',

View file

@ -16,6 +16,10 @@ class _JoinMatchPageState extends State<JoinMatchPage> {
int _player1Score = 0; int _player1Score = 0;
int _player2Score = 0; int _player2Score = 0;
String? _matchId; String? _matchId;
bool _showJoinAsCheckbox = false;
bool _joinAsPlayer2 = false;
bool _joinAsPlayer3 = false;
bool _joinAsPlayer4 = false;
final String _joinMatchApiUrl = '$apiurl/joinmatch'; final String _joinMatchApiUrl = '$apiurl/joinmatch';
final String _endMatchApiUrl = '$apiurl/endmatch'; final String _endMatchApiUrl = '$apiurl/endmatch';
@ -103,7 +107,6 @@ class _JoinMatchPageState extends State<JoinMatchPage> {
if (response.statusCode == 200) { if (response.statusCode == 200) {
_showToast('Match ended successfully!'); _showToast('Match ended successfully!');
Navigator.pop(context);
} else { } else {
_showToast('Failed to end match.'); _showToast('Failed to end match.');
} }
@ -122,6 +125,23 @@ class _JoinMatchPageState extends State<JoinMatchPage> {
); );
} }
@override
void initState() {
super.initState();
_matchIdController.addListener(() {
if (_matchIdController.text.contains(RegExp(r'[Dd]'))) {
setState(() {
_showJoinAsCheckbox = true;
});
_showToast('We\'re sorry, this feature isn\'t available yet');
} else {
setState(() {
_showJoinAsCheckbox = false;
});
}
});
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
@ -155,7 +175,6 @@ class _JoinMatchPageState extends State<JoinMatchPage> {
], ],
), ),
SizedBox(height: 16), SizedBox(height: 16),
// Player 2 Score Controls
Row( Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
@ -174,7 +193,6 @@ class _JoinMatchPageState extends State<JoinMatchPage> {
], ],
), ),
SizedBox(height: 32), SizedBox(height: 32),
// End Match Button
ElevatedButton( ElevatedButton(
onPressed: _endMatch, onPressed: _endMatch,
child: Text('End Match'), child: Text('End Match'),
@ -194,7 +212,6 @@ class _JoinMatchPageState extends State<JoinMatchPage> {
), ),
), ),
SizedBox(height: 16), SizedBox(height: 16),
// Join Match Button
ElevatedButton( ElevatedButton(
onPressed: () { onPressed: () {
if (_matchIdController.text.isNotEmpty) { if (_matchIdController.text.isNotEmpty) {
@ -205,6 +222,40 @@ class _JoinMatchPageState extends State<JoinMatchPage> {
}, },
child: Text('Join Match'), child: Text('Join Match'),
), ),
SizedBox(height: 16),
if (_showJoinAsCheckbox)
Column(
children: [
Text('Join as:'),
CheckboxListTile(
title: Text('Player 2'),
value: _joinAsPlayer2,
onChanged: (bool? value) {
setState(() {
_joinAsPlayer2 = value ?? false;
});
},
),
CheckboxListTile(
title: Text('Player 3'),
value: _joinAsPlayer3,
onChanged: (bool? value) {
setState(() {
_joinAsPlayer3 = value ?? false;
});
},
),
CheckboxListTile(
title: Text('Player 4'),
value: _joinAsPlayer4,
onChanged: (bool? value) {
setState(() {
_joinAsPlayer4 = value ?? false;
});
},
),
],
),
], ],
), ),
), ),