Adding game to user when finished
continuous-integration/drone/push Build is passing Details

pull/25/head
Arthur VALIN 2 years ago
parent 824e8efc9d
commit 87d7c7c5a7

@ -73,7 +73,6 @@ abstract class AbstractRound {
void update(int val){ void update(int val){
points = (points ?? 0) + val; points = (points ?? 0) + val;
print("ROUND " + number.toString() + " - " + player.id.toString() + "Update points : " + points.toString());
previousRound?.update(val); previousRound?.update(val);
} }

@ -1,13 +1,15 @@
import 'Player.dart';
class Game { class Game {
int _id; int _id;
DateTime _date; DateTime _date;
int _pointsCurrentUser; int _pointsCurrentUser;
bool _isFinished; bool _isFinished;
List<int> _playersId = []; List<Player> _players = [];
// Constructor // Constructor
Game(this._id, this._date, this._pointsCurrentUser, this._isFinished, Game(this._id, this._date, this._pointsCurrentUser, this._isFinished,
this._playersId); this._players);
// Getters and setters // Getters and setters
int get id => _id; int get id => _id;
@ -34,9 +36,9 @@ class Game {
_isFinished = value; _isFinished = value;
} }
List<int> get playersId => _playersId; List<Player> get players => _players;
set playersId(List<int> value) { set playersId(List<Player> value) {
_playersId = value; _players = value;
} }
} }

@ -5,6 +5,7 @@ import 'package:bowl_in/model/LastRound.dart';
import 'Player.dart'; import 'Player.dart';
import 'Round.dart'; import 'Round.dart';
import 'User.dart';
class GameDetail { class GameDetail {
int _id; int _id;
@ -25,10 +26,10 @@ class GameDetail {
this.rounds.add(Round(null, null, 0, element, i)); this.rounds.add(Round(null, null, 0, element, i));
}); });
} }
players.forEach((element) { players.forEach((element) {
this.rounds.add(LastRound(null, null, 0, element, 10, null)); this.rounds.add(LastRound(null, null, 0, element, 10, null));
}); });
} }
// Getters and setters // Getters and setters
@ -83,6 +84,14 @@ class GameDetail {
Map<Player, int> get points => _points; Map<Player, int> get points => _points;
void addGameToUsers(){
for(var p in players){
if(p is User){
p.games.add(Game(this.id, this.time, points[p] ?? 0, true, players));
}
}
}
void computeScores(){ void computeScores(){
print("====COMPUTE POINTS===="); print("====COMPUTE POINTS====");
for(var element in rounds){ for(var element in rounds){
@ -90,6 +99,7 @@ class GameDetail {
points[element.player] = (points[element.player] ?? 0) + (element.points ?? 0); points[element.player] = (points[element.player] ?? 0) + (element.points ?? 0);
print(element.player.name + " : " + points[element.player].toString()); print(element.player.name + " : " + points[element.player].toString());
} }
addGameToUsers();
} }
Map<Player, int> getRank() { Map<Player, int> getRank() {

@ -1,6 +1,18 @@
import 'dart:math';
import 'Player.dart'; import 'Player.dart';
const _images = [
"./assets/images/image_user_cyan.png",
"./assets/images/image_user_red.png",
"./assets/images/image_user_yellow.png",
"./assets/images/image_user_pink.png",
"./assets/images/image_user_orange.png",
"./assets/images/image_user_green.png",
"./assets/images/image_user_purple.png",
];
class Guest extends Player { class Guest extends Player {
// Constructor // Constructor
Guest(int id, String image, String name) : super(id, image, name); Guest(String name) : super(name, _images[Random().nextInt(_images.length)]);
} }

@ -1,13 +1,10 @@
class Player { class Player {
final int _id;
String _name; String _name;
String _image; String _image;
// Constructor // Constructor
Player(this._id, this._name, this._image); Player(this._name, this._image);
// Getters and setters // Getters and setters
int get id => _id;
String get name => _name; String get name => _name;
@ -20,4 +17,7 @@ class Player {
set image(String value) { set image(String value) {
_image = value; _image = value;
} }
} }

@ -28,7 +28,6 @@ class Round extends AbstractRound{
@override @override
void computePoints() { void computePoints() {
points = (firstThrow ?? 0)+(secondThrow ?? 0); points = (firstThrow ?? 0)+(secondThrow ?? 0);
print("ROUND " + number.toString() + " - " + player.id.toString() + "Compute points : " + points.toString());
if(previousRound?.isStrike() ?? false){ if(previousRound?.isStrike() ?? false){
previousRound?.update(points ?? 0); previousRound?.update(points ?? 0);
} }

@ -28,7 +28,7 @@ class GameManager extends IGameManager {
List<GameDetail> games = []; List<GameDetail> games = [];
for (var element in parent.gameDetails) { for (var element in parent.gameDetails) {
for (Player player in element.players) { for (Player player in element.players) {
if (player.id == id) { if (player is User && player.id == id) {
games.add(element); games.add(element);
break; break;
} }
@ -41,7 +41,7 @@ class GameManager extends IGameManager {
List<GameDetail> games = []; List<GameDetail> games = [];
for (var element in parent.gameDetails) { for (var element in parent.gameDetails) {
for (Player player in element.players) { for (Player player in element.players) {
if (player.id == user.id) { if (player is User && user is User && player.id == user.id) {
games.add(element); games.add(element);
break; break;
} }

@ -1,5 +1,6 @@
library StubLib; library StubLib;
import '../Guest.dart';
import '../IManager.dart'; import '../IManager.dart';
import '../Game.dart'; import '../Game.dart';
import '../IUserManager.dart'; import '../IUserManager.dart';
@ -32,13 +33,13 @@ class StubData extends IManager {
IGameManager get gameMgr => _gameMgr; IGameManager get gameMgr => _gameMgr;
List<Player> players = [ List<Player> players = [
Player(1, "Mathieu", "./assets/images/image_user_cyan.png"), Guest("Mathieu"),
Player(2, "Robin", "./assets/images/image_user_purple.png"), Guest("Robin"),
Player(3, "Lucas", "./assets/images/image_user_red.png"), Guest("Lucas"),
Player(4, "Emre", "./assets/images/image_user_blue.png"), Guest("Emre"),
Player(5, "Louison", "./assets/images/image_user_cyan.png"), Guest("Louison"),
Player(6, "Arthur", "./assets/images/image_user_yellow.png"), Guest("Arthur"),
Player(7, "David", "./assets/images/image_user_pink.png"), Guest("David"),
User( User(
8, 8,
"Emre", "Emre",

@ -28,7 +28,7 @@ class UserManager extends IUserManager {
Player getUserById(int id) { Player getUserById(int id) {
for (var player in parent.players) { for (var player in parent.players) {
if (player.id == id) { if (player is User && player.id == id) {
return player; return player;
} }
} }

@ -4,6 +4,7 @@ import 'Player.dart';
import 'Stat.dart'; import 'Stat.dart';
class User extends Player { class User extends Player {
final int _id;
String _mail; String _mail;
List<Achievement> _achievements = <Achievement>[]; List<Achievement> _achievements = <Achievement>[];
List<User> _friends = <User>[]; List<User> _friends = <User>[];
@ -11,9 +12,11 @@ class User extends Player {
List<Game> games = []; List<Game> games = [];
// Constructor // Constructor
User(int id, String name, String image, this._mail, this._achievements, User(this._id, String name, String image, this._mail, this._achievements,
this._friends, this._stat) this._friends, this._stat)
: super(id, name, image); : super(name, image);
int get id => _id;
// Getters and setters // Getters and setters
String get mail => _mail; String get mail => _mail;

@ -6,6 +6,8 @@ import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:google_fonts/google_fonts.dart';
import '../model/Game.dart';
import '../model/Guest.dart';
import '../widgets/button_new_party.dart'; import '../widgets/button_new_party.dart';
import '../widgets/ingame_widgets.dart'; import '../widgets/ingame_widgets.dart';
import '../widgets/scores_list_widget.dart'; import '../widgets/scores_list_widget.dart';
@ -53,7 +55,7 @@ class _InGameScreenState extends State<InGameScreen> {
ElevatedButton( ElevatedButton(
onPressed: () { onPressed: () {
GameDetail gd = GameDetail(1, DateTime.now(), null, 123, false, GameDetail gd = GameDetail(1, DateTime.now(), null, 123, false,
MyApp.controller.userCurrent.id, [MyApp.controller.userCurrent, MyApp.controller.userMgr.getUserById(2)]); MyApp.controller.userCurrent.id, [MyApp.controller.userCurrent, new Guest("Louison")]);
MyApp.controller.gamePlayer.game = gd; MyApp.controller.gamePlayer.game = gd;
MyApp.controller.gameCurrent = gd; MyApp.controller.gameCurrent = gd;

@ -111,11 +111,9 @@ class CardGame extends StatelessWidget {
child: Wrap( child: Wrap(
spacing: 5, spacing: 5,
runSpacing: 5, runSpacing: 5,
children: game.playersId children: game.players
.map((e) => ProfilPicture( .map((e) => ProfilPicture(
path: MyApp.controller.userMgr path: e.image
.getUserById(e)
.image
.toString(), .toString(),
)) ))
.toList()))), .toList()))),

Loading…
Cancel
Save