private void btnPlaySavedGame_Click(object sender, RoutedEventArgs e) { if (BoardDb.CheckIfBoardDbContainsPlayerId(Services.Player.PlayerId)) { Services.NoveltyOfGame = NoveltyOfGame.OLD; Services.Player.GetSavedGameFromDb(); PlayGame game = new PlayGame(); game.ShowDialog(); } else { MessageBox.Show("Vous n'avez pas encore de partie sauvegardée"); } }
/// <summary> /// If it's the first time player saves the game -> Save board, if not the first time-> Update board /// </summary> /// <param name="turn">turn of which player?</param> /// <param name="player2Pseudo">pseudo of player number 2</param> /// <param name="playerId">player identity</param> public void SaveOrUpdateGame(string player2Pseudo, long turn, Board board) { bool contains = BoardDb.CheckIfBoardDbContainsPlayerId(PlayerId); if (contains) { BoardDb.Update(PlayerId, player2Pseudo, turn); SquareListDb.Update(PlayerId, board); PoolDb.Update(PlayerId, board); } else { BoardDb.Save(PlayerId, player2Pseudo, turn); SquareListDb.Save(PlayerId, board); PoolDb.Save(PlayerId, board); } }
public Board GetSavedGameFromDb() { Board board = new Board(); board.Turn = BoardDb.GetTurnFromDb(PlayerId); board.Player2Pseudo = BoardDb.GetPlayer2PseudoFromDb(PlayerId); board.PlayersList = new List <Player> { this, new Player(board.Player2Pseudo) }; //recover squareList with SmallTokenQty and BigTokenQty by reserving all other properties var squaresListDb = SquareListDb.GetSquareListDb(PlayerId); for (int i = 0; i < 12; i++) { board.SquaresList[i].Tokens = new List <Token>(); board.SquaresList[i].SmallTokenQty = squaresListDb[i].SmallTokenQty; board.SquaresList[i].BigTokenQty = squaresListDb[i].BigTokenQty; for (int j = 0; j < board.SquaresList[i].SmallTokenQty; j++) { board.SquaresList[i].Tokens.Add(new SmallToken()); } for (int j = 0; j < board.SquaresList[i].BigTokenQty; j++) { board.SquaresList[i].Tokens.Add(new BigToken()); } } var poolList = PoolDb.GetPoolListDb(PlayerId); //Recover pool of each player for (int i = 0; i < 2; i++) { board.PlayersList[i].Pool = new List <Token>(); for (int j = 0; j < poolList[i].SmallTokenQty; j++) { board.PlayersList[i].Pool.Add(new SmallToken()); } for (int j = 0; j < poolList[i].BigTokenQty; j++) { board.PlayersList[i].Pool.Add(new BigToken()); } } return(board); }
private void InitBoards() { boardDb = new BoardDb<TreeNode>(); var boardList = TrelloSerivce.Load(); if (boardList != null) { foreach (var item in boardList) { AddBoard(item); } } }