public async Task MovePlayer(Cell newCell) { var player = await GameInstance.GetPlayerInstance(); var currentCell = player.Cells.Single(c => c.PlayerPresence == true); currentCell.PlayerPresence = false; await cellsAccessLayer.UpdateAsync(currentCell); newCell.PlayerPresence = true; await cellsAccessLayer.UpdateAsync(newCell); Console.WriteLine($"newCellPlayer.posX: {newCell.PosX}"); Console.WriteLine($"newCellPlayer.posY: {newCell.PosY}"); Console.WriteLine($"You are on a : {newCell.Description}"); Console.ReadLine(); }
// Set the current cell id of the player randomly private async Task SpawnPlayer(Player player, Cell[] map) { Cell lastCell = map.Last(); int widthMap = lastCell.PosX; // Get width map int heightMap = lastCell.PosY; // Get height map int randomPositionOnWidthAxis; int randomPositionOnHeightAxis; Random random = new Random(); if (widthMap == 0) { randomPositionOnWidthAxis = random.Next(0, widthMap + 1); } else { randomPositionOnWidthAxis = random.Next(0, widthMap - 1); } if (heightMap == 0) { randomPositionOnHeightAxis = random.Next(0, heightMap + 1); } else { randomPositionOnHeightAxis = random.Next(0, heightMap - 1); } // Create a cell for the player to spawn int index = map.ToList().FindIndex(c => c.PosX == randomPositionOnWidthAxis && c.PosY == randomPositionOnHeightAxis); // Ensure that the cell is not a wall map[index].Description = CellsEnum.SPAWN.ToString(); map[index].CanMoveTo = true; map[index].PlayerPresence = true; await cellsAccessLayer.UpdateAsync(map[index]); var updatedPlayer = await GameInstance.GetPlayerInstance(); }