} //Printing the board public Player PlayerName(int i, IManageScrabbleDb manageScrableDb) //OK Entering the names of players { Console.WriteLine(); string playerName = ""; int x = 0; while (x == 0) { Console.Write($"Enter player {i + 1} name: "); playerName = Console.ReadLine(); if (playerName.Length < 1) { Console.WriteLine("You havn't entered correct name"); } else { x = 1; } } if ((manageScrableDb.GetAllPlayers().Exists(p => p.PlayerName == playerName))) { Console.WriteLine($"Welcome {playerName} to the Scrabble again!"); } else { manageScrableDb.InsertPlayer(playerName); Console.WriteLine($"Welcome {playerName} to the Scrabble!"); } return(manageScrableDb.GetAllPlayers().FirstOrDefault(p => p.PlayerName == playerName)); }
public List <BoardCell> PlayersMove(int roundNUmber, int playerId, IManageScrabbleDb manageScrableDb, List <PlayerHand> playersHands, List <BoardCell> gameBoard, int roundNumber, List <Tile> bag, List <Tile> listOfUniqueTiles, int playerNumber, int gameId) { var playerName = manageScrableDb.GetAllPlayers().FirstOrDefault(p => p.PlayerId == playerId).PlayerName; var playerHand = GetPlayerHand(playerId, playersHands); Console.WriteLine($"Round nr.{roundNUmber}, player's {playerName} turn and letters on hand: {String.Join(' ',LettersFromHand(playerHand))}"); string wordToPlay = null; int horizontalPosition = 0; int verticalPosition = 0; char direction = ' '; var points = playersHands.FirstOrDefault(p => p.PlayerID == playerId).Points; int turnPoints = 0; bool correctPositioning = false; bool possibleToCreate = false; List <Tile> playedTiles = new List <Tile>(); while (correctPositioning is false || possibleToCreate is false) { Console.WriteLine("Enter the word to play"); wordToPlay = Console.ReadLine().ToUpper(); if (wordToPlay.Length == 0) { skipedMoves.Add(1); return(gameBoard); } else { skipedMoves.Clear(); } Console.WriteLine("Enter Horizontal position"); int.TryParse(Console.ReadLine(), out horizontalPosition); Console.WriteLine("Enter Vertical position"); int.TryParse(Console.ReadLine(), out verticalPosition); direction = Direction(); var chArrayOfWordToPlay = wordToPlay.ToArray(); correctPositioning = CheckTheWord(chArrayOfWordToPlay, horizontalPosition, verticalPosition, direction, gameBoard); //checking if it's possible to corectly place the word on board playedTiles = CheckIsItPossibleToCreateTheWord(wordToPlay.ToArray(), horizontalPosition, verticalPosition, direction, gameBoard, playerHand, roundNumber, listOfUniqueTiles); // cheking if there was any and returning it if the word was crossing other words on board if (playedTiles.Count > 0 || (roundNumber == 1 && playerNumber == 0)) //if it's first word on board it's not need to cross other word { possibleToCreate = true; } else { possibleToCreate = false; } } turnPoints = PointsOfPlacedWord(playedTiles, gameBoard, listOfUniqueTiles, wordToPlay.ToArray(), horizontalPosition, verticalPosition, direction); //points after turn Console.WriteLine($"Player {playerName} received {turnPoints} points"); points += turnPoints; Console.WriteLine($"Player {playerName} has total {points} points"); playersHands.FirstOrDefault(p => p.PlayerID == playerId).Points = points; Console.WriteLine(); manageScrableDb.InsertStatistic(playerId, gameId, playerHand, wordToPlay, horizontalPosition, verticalPosition, direction); //inserting statistic to DB var newPlayerHand = AddToHand(bag, playedTiles, playerHand); foreach (var player in playersHands) { if (player.PlayerID == playerId) { player.Hand = newPlayerHand; } } return(PlaceTheWordOnBoard(wordToPlay.ToArray(), horizontalPosition, verticalPosition, direction, gameBoard)); }