Skip to content

Commit

Permalink
[orange] player creation with name
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkbee1 committed Apr 9, 2024
1 parent e621983 commit be62477
Show file tree
Hide file tree
Showing 6 changed files with 234 additions and 10 deletions.
1 change: 1 addition & 0 deletions bluevsred_flutter/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Flame.device.setLandscape();
await Flame.device.fullScreen();
// runApp(const ProviderScope(child: MyGame()));
runApp(const MyGame());
}

Expand Down
12 changes: 12 additions & 0 deletions bluevsred_flutter/lib/player/active_game_player.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:bluevsred_shared/bluesvsred_shared.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'active_game_player.g.dart';

@riverpod
class ActiveGamePlayer extends _$ActiveGamePlayer {
@override
Future<GamePlayer> build(String creationName) async {
return GamePlayer(name: this.creationName);
}
}
175 changes: 175 additions & 0 deletions bluevsred_flutter/lib/player/active_game_player.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 19 additions & 10 deletions bluevsred_flutter/test/game_player_test.dart
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
// import 'package:bluevsred_shared/src/game_player/game_player.dart';
import 'package:bluevsred_flutter/player/active_game_player.dart';
import 'package:test/test.dart';

import 'provider_container.dart';

void main() {
// const String gamePlayer1Name = 'first test player';
// final List<GamePlayer> initialPlayerList = [GamePlayer(name: 'initial player 1'), GamePlayer(name: 'initial player 2'), GamePlayer(name: 'initial player 3'), GamePlayer(name: 'initial player 4'),];
group('player lifecycle', () {
test('when game player is created, he appear in the player list', () {
// Here comes the need of state management system
bool isPlayerInTheList = false;
test('When a player is created its name begin by given string ', () async {
final container = createContainer();
const expectedName = 'given name';
var state = container.read(activeGamePlayerProvider(expectedName).notifier);
expect((await state.future).name, equals(expectedName));
});

test('when game player is created, he gets a commander troop', () {
// Here comes the need of state management system
bool isPlayerInTheList = false;

/// check player is not in inital list
expect(isPlayerInTheList, equals(false));
/// Add new player to the list
isPlayerInTheList = true;
expect(isPlayerInTheList, equals(true));

} );
/// Add new player to the list
isPlayerInTheList = true;
expect(isPlayerInTheList, equals(true));
});

// test('when game player is created, his first commander is created', () {
// bool isPlayerCommanderCreated = false;
Expand All @@ -23,7 +32,7 @@ void main() {

// } );
// test('when game player is created, its name must be unique', () {
// final gamePlayer = GamePlayer(name: gamePlayer1Name);
// final gamePlayer = GamePlayer(name: gamePlayer1Name);
// } );
});
}
22 changes: 22 additions & 0 deletions bluevsred_flutter/test/provider_container.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:test/test.dart';

/// A testing utility which creates a [ProviderContainer] and automatically
/// disposes it at the end of the test.
ProviderContainer createContainer({
ProviderContainer? parent,
List<Override> overrides = const [],
List<ProviderObserver>? observers,
}) {
// Create a ProviderContainer, and optionally allow specifying parameters.
final container = ProviderContainer(
parent: parent,
overrides: overrides,
observers: observers,
);

// When the test ends, dispose the container.
addTearDown(container.dispose);

return container;
}
5 changes: 5 additions & 0 deletions bluevsred_shared/lib/bluesvsred_shared.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export 'src/battle/battle.dart';
export 'src/battle_map/battle_map.dart';
export 'src/game_player/game_player.dart';
export 'src/team/team.dart';
export 'src/troops/troop.dart';

0 comments on commit be62477

Please sign in to comment.