public void ProvideCards(int epoch) { if (GameCards == null) { throw new Exception("There are no cards!"); } if (Players == null) { throw new Exception("There are no players!"); } var rnd = new Random(); var cardsForCurrentPlayersNumber = GameCards.Where(c => c.MinPlayers <= Players.Count).ToList(); foreach (var player in Players) { for (int i = 0; i < EpochCardsAmount; i++) { var selectedCardId = rnd.Next(cardsForCurrentPlayersNumber.Count); var card = cardsForCurrentPlayersNumber[selectedCardId]; player.CardsOnHand.Add(card); cardsForCurrentPlayersNumber.Remove(card); } } }
private void processLobbyNotif(JObject data) { App.Current.Dispatcher.Invoke(delegate { bool needUpdate = ((data.GetValue("type").ToString() == "create" && data.GetValue("mode").ToString() == _selectedMode) || data.GetValue("type").ToString() == "delete"); if (needUpdate) { getLobbies(); } if (((string)data.GetValue("type") == "join")) { try { GameCards.SingleOrDefault(i => i.LobbyName == (string)data.GetValue("lobbyName")).Players.Add((string)data.GetValue("username")); } catch (Exception) { //fail silently } } if (((string)data.GetValue("type") == "leave")) { try { GameCards.SingleOrDefault(i => i.LobbyName == (string)data.GetValue("lobbyName")).Players.Remove((string)data.GetValue("username")); } catch (Exception) { // fail silently } } }); }
/// <summary> /// Handler for the game cards request, which means client /// will retrieve all the cards from the database /// </summary> /// <param name="netMsg"></param> private void OnGameCardsRequest(NetworkMessage netMsg) { //We better have cards var gameCards = GameCards.GetAll(); if (gameCards.Count > 0) { Server.SendToClient(netMsg.Sender, LoginEvent.GAME_CARDS_SUCCESS, gameCards); } else { Server.SendToClient(netMsg.Sender, LoginEvent.GAME_CARDS_FAIL, null); } }
public async void getLobbies() { await App.Current.Dispatcher.Invoke(async delegate { bool isExistingSelectedMode = (_selectedMode == Constants.MODE_FFA || _selectedMode == Constants.MODE_SOLO || _selectedMode == Constants.MODE_COOP); if (isExistingSelectedMode) { GameCards.Clear(); var response = await ServerService.instance.client.GetAsync(Constants.SERVER_PATH + Constants.GET_ACTIVE_LOBBY_PATH + "/" + _selectedMode); StreamReader streamReader = new StreamReader(await response.Content.ReadAsStreamAsync()); String responseData = streamReader.ReadToEnd(); var myData = JsonConvert.DeserializeObject <List <Lobby> >(responseData); foreach (var item in myData) { GameCard gameCard = new GameCard(item); GameCards.Add(gameCard); } } }); }
public void CreateCardsForGame(int row, int columns) { GameCards.Clear(); var rnd = new Random(); for (int i = 0; i < ((row * columns) / 2); i++) { int r = rnd.Next(AllCardList.Count); if (GameCards.Any(x => x.Number == AllCardList[r].Number)) { i--; continue; } // Clone Card object var pomC = (Card)AllCardList[r].Clone(); // Load img from file for first card BitmapImage bmp = new BitmapImage(AllCardList[r].UriPath); Image img = new Image(); img.Source = bmp; img.Width = PictureWidth; img.Height = PictureHeight; AllCardList[r].Img = img; GameCards.Add(AllCardList[r]); // Load img from file for second same card bmp = new BitmapImage(pomC.UriPath); img = new Image(); img.Source = bmp; img.Width = PictureWidth; img.Height = PictureHeight; pomC.Img = img; GameCards.Add(pomC); } GameCards.Shuffle(); }
public void Start() { gameCards = new GameCards(); }
public int GetCardIndex(Card card) { return(GameCards.FindIndex(x => x == card)); }
public GameCardBase() { gameCards = new GameCards(); players = new List <T>(); }