private void ConfirmCard(object sender, EventArgs args) { if (CardsAgainstHumility.IsCardCzar && _selectedCard != null) { if (CardsAgainstHumility.ReadyToSelectWinner) { CardsAgainstHumility.SelectWinner(_selectedCard); } else { RunOnUiThread(() => { var builder = new AlertDialog.Builder(this); builder.SetTitle("Still waiting on"); builder.SetMessage(string.Join(System.Environment.NewLine, CardsAgainstHumility.PlayersNotYetSubmitted)); builder.Create().Show(); }); } } else { if (CardsAgainstHumility.SelectedCard == null) { Console.WriteLine("User played \"{0}\" ", _selectedCard.Id); CardsAgainstHumility.SelectCard(_selectedCard); } } }
public LobbyViewModel() : base() { var thd = new Thread(() => { try { var games = CardsAgainstHumility.ListAsync().Result; dispatcher.BeginInvoke(() => { Games = games; Status = $"{(games.Count == 0 ? "No" : games.Count.ToString())} Games Found"; }); } catch (Exception ex) { dispatcher.BeginInvoke(() => { Status = "Connection Error"; }); } CardsAgainstHumility.Lobby_GameAdded += Lobby_GameAdded; CardsAgainstHumility.ConnectToLobby(); }); Status = "Refreshing"; thd.Start(); }
public CreateGameViewModel() : base() { Decks = new List <SelectableItem>(0); settings = new SettingsLoader(); LoadDecksStatus = "Refreshing Decks"; Thread thd = new Thread(async() => { List <string> deckNames = await CardsAgainstHumility.GetDecks(); dispatcher.BeginInvoke(() => { try { var preferredDecks = settings.GetPreferredDecks(deckNames); Decks = deckNames.Select(c => new SelectableItem() { IsSelected = preferredDecks.Contains(c), Text = c }).ToList(); LoadDecksStatus = $"{deckNames.Count} Decks Available"; } catch (Exception ex) { Console.WriteLine(ex.Message); } }); }); thd.Start(); }
internal async void StartGame() { List <string> decks = Decks.Where(c => c.IsSelected).Select(c => c.Text).ToList(); settings.SavePreferredDecks(decks); var gid = await CardsAgainstHumility.Add(CardsAgainstHumility.NewId(), GameName, decks, MaxPlayers, MaxScore); await CardsAgainstHumility.JoinGame(gid); navService.Navigate(new Uri("/GamePage.xaml", UriKind.Relative)); }
private void JoinGame(GameInstance gi) { try { CardsAgainstHumility.JoinGame(gi.Id).Wait(); StartActivity(typeof(GameActivity)); Finish(); } catch (Exception ex) { Console.WriteLine("An error occurred when trying to join {0}: {1}", gi.Name, ex.Message); } }
private async Task CreateGame() { startBtn.Enabled = false; try { int maxPlayers = 10; int pointsToWin = 5; if (!int.TryParse(maxPlayersTxt.Text, out maxPlayers)) { ShowAlert("Max Players", "Max Players must be an integer"); return; } if (!int.TryParse(pointsToWinTxt.Text, out pointsToWin)) { ShowAlert("Points to Win", "Points to win must be an integer"); return; } if ((maxPlayers >= 3) && (pointsToWin >= 5)) { var selectedDecks = decks.Where(c => c.IsSelected).Select(c => c.Text).ToList(); settings.SavePreferredDecks(selectedDecks); var gid = await CardsAgainstHumility.Add(CardsAgainstHumility.NewId(), gameNameTxt.Text, selectedDecks, maxPlayers, pointsToWin); CardsAgainstHumility.JoinGame(gid).Wait(); StartActivity(typeof(GameActivity)); Finish(); } else { if (maxPlayers < 3) { ShowAlert("Max Players", "Max Players must be at least 3"); } else { ShowAlert("Points to Win", "Points to Win must be at least 5"); } } } catch (Exception ex) { Log.WriteLine(LogPriority.Error, "Exception when Creating a game", $"Message: {ex.Message}{System.Environment.NewLine}StackTrace: {ex.StackTrace}"); throw; } finally { startBtn.Enabled = true; } }
private void UpdateReadyButton() { if (readyButton == null) { readyButton = FindViewById <Button>(Resource.Id.gv_ReadyButton); readyButton.SetTypeface(UIAssets.AppFont, TypefaceStyle.Normal); readyButton.Click += (sender, args) => { CardsAgainstHumility.ReadyForNextRound(); WinnerAlertShown = false; }; } readyButton.Visibility = (CardsAgainstHumility.ReadyForReview && !CardsAgainstHumility.IsReady) ? ViewStates.Visible : ViewStates.Invisible; }
internal void Confirm() { if (SelectedWhiteCard != null) { if (CardsAgainstHumility.IsCardCzar) { CardsAgainstHumility.SelectWinner(SelectedWhiteCard); } else { CardsAgainstHumility.SelectCard(SelectedWhiteCard); } } }
public MainPage() { InitializeComponent(); CardsAgainstHumility.InitDefaultValues(new SettingsLoader(), new NetServices.NetServices()); vm = new MainViewModel(); LayoutRoot.DataContext = vm; Loaded += delegate { ViewModelBase.navService = NavigationService; ViewModelBase.dispatcher = Dispatcher; }; }
protected override void OnDestroy() { base.OnDestroy(); // If isFinishing is false, the player isn't really leaving the game if (IsFinishing) { CardsAgainstHumility.DepartGame(); } CardsAgainstHumility.Game_SocketConnected -= OnSocketConnected; CardsAgainstHumility.Game_SocketConnectError -= OnSocketConnectError; CardsAgainstHumility.Game_SocketConnectTimeout -= OnSocketConnectTimeout; CardsAgainstHumility.Game_Update -= OnUpdateGame; CardsAgainstHumility.Game_Error -= OnGameError; CurrentQuestionView.Dispose(); CurrentQuestionView = null; }
public GamePage() { InitializeComponent(); _drawerLayout.InitializeDrawerLayout(); vm = new GameViewModel(); _drawerLayout.DrawerOpened += sender => { vm.SetDrawerLayoutOpen(true); }; _drawerLayout.DrawerClosed += sender => { vm.SetDrawerLayoutOpen(false); }; vm.CloseDrawer += (sender, args) => { _drawerLayout.CloseDrawer(); }; DataContext = vm; TouchPanel.EnabledGestures = GestureType.Flick; ManipulationCompleted += manipulationCompleted; Loaded += delegate { NavigationService.RemoveBackEntry(); }; Unloaded += delegate { CardsAgainstHumility.DepartGame(); }; }
protected override void OnCreate(Bundle bundle) { CardsAgainstHumility.InitDefaultValues(new SettingsLoader(this), new NetServices.NetServices()); dialogBuilder = new AlertDialog.Builder(this, 0); base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); UIAssets.Initialize(Assets); var tv = FindViewById <TextView>(Resource.Id.main_logo1); if (tv != null) { tv.SetTypeface(UIAssets.AppFont, TypefaceStyle.Normal); try { tv.StartAnimation(logo1Animation); } catch (Exception ex) { Console.Error.WriteLine("Error occurred while animating the logo: {0}", ex.Message); } } tv = FindViewById <TextView>(Resource.Id.main_logo2); if (tv != null) { tv.SetTypeface(UIAssets.AppFont, TypefaceStyle.Normal); try { tv.StartAnimation(logo2Animation); } catch (Exception ex) { Console.Error.WriteLine("Error occurred while animating the logo: {0}", ex.Message); } } tv = FindViewById <TextView>(Resource.Id.main_logo3); if (tv != null) { tv.SetTypeface(UIAssets.AppFont, TypefaceStyle.Normal); try { tv.StartAnimation(logo3Animation); } catch (Exception ex) { Console.Error.WriteLine("Error occurred while animating the logo: {0}", ex.Message); } } tv = FindViewById <TextView>(Resource.Id.main_logo4); if (tv != null) { tv.SetTypeface(UIAssets.AppFont, TypefaceStyle.Normal); try { tv.StartAnimation(logo4Animation); } catch (Exception ex) { Console.Error.WriteLine("Error occurred while animating the logo: {0}", ex.Message); } } tv = FindViewById <TextView>(Resource.Id.main_logo5); if (tv != null) { tv.SetTypeface(UIAssets.AppFont, TypefaceStyle.Normal); try { tv.StartAnimation(logo4Animation); } catch (Exception ex) { Console.Error.WriteLine("Error occurred while animating the logo: {0}", ex.Message); } } createButton = FindViewById <Button>(Resource.Id.main_btnCreateGame); joinButton = FindViewById <Button>(Resource.Id.main_btnJoinGame); settingsButton = FindViewById <Button>(Resource.Id.main_btnSettings); quitButton = FindViewById <Button>(Resource.Id.main_btnQuitGame); if (createButton != null) { createButton.Click += delegate { StartActivity(typeof(CreateGameActivity)); }; } else { Console.WriteLine("Unable to get Create Button"); } if (joinButton != null) { joinButton.Click += delegate { StartActivity(typeof(GameBrowserActivity)); }; } else { Console.WriteLine("Unable to get Join Button"); } if (settingsButton != null) { settingsButton.Click += delegate { StartActivity(typeof(SettingsActivity)); }; } else { Console.WriteLine("Unable to get Settings Button"); } if (quitButton != null) { quitButton.Click += delegate { Finish(); }; } else { Console.WriteLine("Unable to get Quit Button"); } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.CreateGameMenu); settings = new SettingsLoader(this); startBtn = FindViewById <Button>(Resource.Id.cg_btnStart); gameNameTxt = FindViewById <EditText>(Resource.Id.cg_txtGameName); maxPlayersTxt = FindViewById <EditText>(Resource.Id.cg_txtMaxPlayers); pointsToWinTxt = FindViewById <EditText>(Resource.Id.cg_txtPointsToWin); decksList = FindViewById <ListView>(Resource.Id.cg_deckList); decksListStatus = FindViewById <TextView>(Resource.Id.cg_deckListStatus); var gameNameLbl = FindViewById <TextView>(Resource.Id.cg_lblGameName); var maxPlayersLbl = FindViewById <TextView>(Resource.Id.cg_lblMaxPlayers); var pointsToWinLbl = FindViewById <TextView>(Resource.Id.cg_lblPointsToWin); if (UIAssets.AppFont != null) { startBtn.SetTypeface(UIAssets.AppFont, TypefaceStyle.Normal); gameNameTxt.SetTypeface(UIAssets.AppFont, TypefaceStyle.Normal); maxPlayersTxt.SetTypeface(UIAssets.AppFont, TypefaceStyle.Normal); pointsToWinTxt.SetTypeface(UIAssets.AppFont, TypefaceStyle.Normal); gameNameLbl.SetTypeface(UIAssets.AppFont, TypefaceStyle.Normal); maxPlayersLbl.SetTypeface(UIAssets.AppFont, TypefaceStyle.Normal); pointsToWinLbl.SetTypeface(UIAssets.AppFont, TypefaceStyle.Normal); decksListStatus.SetTypeface(UIAssets.AppFont, TypefaceStyle.Normal); } gameNameTxt.Text = $"{CardsAgainstHumility.PlayerName}'s Game"; maxPlayersTxt.Text = "10"; pointsToWinTxt.Text = "10"; startBtn.Enabled = false; startBtn.Click += async delegate { try { await CreateGame(); } catch (Exception ex) { ShowAlert("Unexpected Error", ex.Message); } }; var thd = new Thread(async() => { string error = null; List <string> deckTitles = null; try { deckTitles = await CardsAgainstHumility.GetDecks(); } catch (Exception ex) { Console.WriteLine("Error getting deck titles: {0}", ex.Message); error = "Connection Error"; } RunOnUiThread(() => { if (error == null) { var preferredDecks = settings.GetPreferredDecks(deckTitles); decks = deckTitles.Select(c => new SelectableItem() { IsSelected = preferredDecks.Contains(c), Text = c }).ToList(); decksListStatus.Text = $"{deckTitles.Count} Decks Available"; decksList.Adapter = new SelectionListArrayAdapter(this, decks); startBtn.Enabled = true; } else { decksListStatus.Text = error; } }); }); thd.Start(); }
internal void Ready() { CardsAgainstHumility.ReadyForNextRound(); WinnerModalShown = false; }
internal async void JoinGame(GameInstance game) { await CardsAgainstHumility.JoinGame(game.Id); navService.Navigate(new Uri("/GamePage.xaml", UriKind.Relative)); }
private void RefreshGamesList() { RunOnUiThread(() => { TextView txtStatus = FindViewById <TextView>(Resource.Id.gb_Status); if (txtStatus != null) { txtStatus.Text = "Refreshing"; } if (txtStatus != null) { txtStatus.SetTypeface(UIAssets.AppFont, TypefaceStyle.Normal); } ListView gameList = FindViewById <ListView>(Resource.Id.gb_List); if (gameList != null) { gameList.Adapter = new GameInstanceArrayAdapter(this, null, new GameInstance[] { }); } }); try { var games = CardsAgainstHumility.ListAsync().Result; RunOnUiThread(() => { ListView gameList = FindViewById <ListView>(Resource.Id.gb_List); TextView txtStatus = FindViewById <TextView>(Resource.Id.gb_Status); if (gameList != null) { gameList.Adapter = new GameInstanceArrayAdapter(this, JoinGame, games); } if (txtStatus != null) { txtStatus.SetTypeface(UIAssets.AppFont, TypefaceStyle.Normal); } if (txtStatus != null) { txtStatus.Text = $"{((games.Count > 0) ? games.Count.ToString() : "No")} Game{(games.Count == 1 ? "" : "s")} Found"; } CardsAgainstHumility.Lobby_SocketConnected += OnSocketConnected; CardsAgainstHumility.Lobby_SocketConnectError += OnSocketConnectError; CardsAgainstHumility.Lobby_SocketConnectTimeout += OnSocketConnectTimeout; CardsAgainstHumility.Lobby_Join += OnLobbyJoin; CardsAgainstHumility.Lobby_GameAdded += OnGameAdded; CardsAgainstHumility.ConnectToLobby(); }); } catch (Exception ex) { Console.WriteLine(ex.Message); RunOnUiThread(() => { TextView txtStatus = FindViewById <TextView>(Resource.Id.gb_Status); if (txtStatus != null) { txtStatus.Text = ("Connection Error"); } }); } }