//Makes a call to update the score on the server public async void updateScore(int scoreTeam1, int scoreTeam2) { currentGame.team1.score = scoreTeam1; currentGame.team2.score = scoreTeam2; if (scoreTeam1 == 10 || scoreTeam2 == 10) { currentGame.isActive = false; } await GameCall.updateGame(currentGame); }
/** * Little performance update, if the list is equally in size (not the best method) do not update the list */ public async override void ViewWillAppear(bool animated) { base.ViewWillAppear(animated); var newGames = await GameCall.GetAllGames(); if (games == null) { setupDatasource(newGames); } else if (games.Count != newGames.Count) { setupDatasource(newGames); } games = newGames; }
//Saves the new game and makes the call to the server public async void saveAndCreateGame() { if (team1Player1 != null && team1Player2 != null && team2Player1 != null && team2Player2 != null) { //Save the new game and dismiss Team team1 = new Team(); team1.player1 = team1Player1; team1.player2 = team1Player2; Team team2 = new Team(); team2.player1 = team2Player1; team2.player2 = team2Player2; Game game = new Game(); game.team1 = team1; game.team2 = team2; //Get the current user and add it as the owner var plist = NSUserDefaults.StandardUserDefaults; var userId = (int)plist.IntForKey("userId"); User owner = await UserCall.getUserWithid(userId); if (owner != null) { game.owner = owner; Game createdGame = await GameCall.createGame(game); if (createdGame.id != 0 || createdGame.id != -1) { DismissViewController(true, null); } else { showAlertController("Error", "Unable to create the game"); } } } else { showAlertController("Warning", "Please select all four players"); } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.EditGame); //Get the game which is send from the other view jsonMyObject = Intent.GetStringExtra("game"); //Deserialize String to Game Game game = JsonConvert.DeserializeObject <Game>(jsonMyObject); //Set the score of the teams FindViewById <EditText>(Resource.Id.scoreTeam1).Text = game.team1.score + ""; FindViewById <EditText>(Resource.Id.scoreTeam2).Text = game.team2.score + ""; //Set clickhandler on save button Button saveEditGameBtn = FindViewById <Button>(Resource.Id.saveScoreBtn); saveEditGameBtn.Click += async(object sender, EventArgs e) => { try { //Parse the string score to int game.team1.score = int.Parse(FindViewById <EditText>(Resource.Id.scoreTeam1).Text); game.team2.score = int.Parse(FindViewById <EditText>(Resource.Id.scoreTeam2).Text); //Update the game with te new score await GameCall.updateGame(game); //Redirect to GameActivity with the new Game var activity = new Intent(this, typeof(GameActivity)); activity.PutExtra("game", JsonConvert.SerializeObject(game)); StartActivity(activity); } catch (Exception ex) { Toast.MakeText(this, ex.Message, ToastLength.Short).Show(); } }; }
protected async override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // get all the games games = new List <Game>(); games = await GameCall.GetAllGames(); ListView listViewGames = FindViewById <ListView>(Resource.Id.games); // Assign adapter to ListView listViewGames.Adapter = new GameAdapter(this, games); listViewGames.ItemClick += listView_ItemClick; //Get all the buttons Button gamesBtn = FindViewById <Button>(Resource.Id.button1); Button leaderboardBtn = FindViewById <Button>(Resource.Id.button2); Button profileBtn = FindViewById <Button>(Resource.Id.button3); Button newGameBtn = FindViewById <Button>(Resource.Id.newGameBtn); //Set clickhandler to button gamesBtn.SetBackgroundResource(Resource.Color.green); gamesBtn.Click += (object sender, EventArgs e) => { //Select the games tab //Set the colors leaderboardBtn.SetBackgroundResource(Resource.Color.white); gamesBtn.SetBackgroundResource(Resource.Color.green); profileBtn.SetBackgroundResource(Resource.Color.white); listViewGames.Visibility = ViewStates.Visible; }; //Set clickhandler to button leaderboardBtn.Click += (object sender, EventArgs e) => { //Select the leaderboard tab //Set the colors leaderboardBtn.SetBackgroundResource(Resource.Color.green); gamesBtn.SetBackgroundResource(Resource.Color.white); profileBtn.SetBackgroundResource(Resource.Color.white); listViewGames.Visibility = ViewStates.Invisible; }; //Set clickhandler to button profileBtn.Click += (object sender, EventArgs e) => { //Select the profile tab //Set the colors profileBtn.SetBackgroundResource(Resource.Color.green); gamesBtn.SetBackgroundResource(Resource.Color.white); leaderboardBtn.SetBackgroundResource(Resource.Color.white); listViewGames.Visibility = ViewStates.Invisible; }; //Set clickhandler to button newGameBtn.Click += (object sender, EventArgs e) => { //Open the new game activity var activity = new Intent(this, typeof(NewGameActivity)); StartActivity(activity); }; LayoutInflater li = LayoutInflater.From(this); View promptsView = li.Inflate(Resource.Layout.dialog, null); //Create a Dialog to create a new user AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); // set prompts.xml to alertdialog builder alertDialogBuilder.SetView(promptsView); alertDialogBuilder.SetTitle("Username"); //Get the view items for the dialog userInput = (EditText)promptsView.FindViewById(Resource.Id.dialogText); imageView = (ImageView)promptsView.FindViewById(Resource.Id.imageView); imageBtn = (Button)promptsView.FindViewById(Resource.Id.imageBtn); //Add clickhandler to open the gallery imageBtn.Click += delegate { Intent = new Intent(); Intent.SetType("image/*"); Intent.SetAction(Intent.ActionGetContent); StartActivityForResult(Intent.CreateChooser(Intent, "Select Picture"), 1000); }; // set dialog message alertDialogBuilder .SetCancelable(false) .SetPositiveButton("OK", HandleTouchUpInside); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.Create(); // show it alertDialog.Show(); }
protected override async void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.NewGame); // Get all the users from the server users = await UserCall.getUsers(); //Set click to imageView to set user ImageView newTeam1Player1Image = FindViewById <ImageView>(Resource.Id.newTeam1Player1Image); newTeam1Player1Image.SetImageResource(Resource.Mipmap.noImage); newTeam1Player1Image.Click += (object sender, EventArgs e) => { clicked = 1; createAlert(); }; //Set click to imageView to set user ImageView newTeam1Player2Image = FindViewById <ImageView>(Resource.Id.newTeam1Player2Image); newTeam1Player2Image.SetImageResource(Resource.Mipmap.noImage); newTeam1Player2Image.Click += (object sender, EventArgs e) => { clicked = 2; createAlert(); }; //Set click to imageView to set user ImageView newTeam2Player1Image = FindViewById <ImageView>(Resource.Id.newTeam2Player1Image); newTeam2Player1Image.SetImageResource(Resource.Mipmap.noImage); newTeam2Player1Image.Click += (object sender, EventArgs e) => { clicked = 3; createAlert(); }; //Set click to imageView to set user ImageView newTeam2Player2Image = FindViewById <ImageView>(Resource.Id.newTeam2Player2Image); newTeam2Player2Image.SetImageResource(Resource.Mipmap.noImage); newTeam2Player2Image.Click += (object sender, EventArgs e) => { clicked = 4; createAlert(); }; //Create a new game game = new Game(); game.team1 = new Team(); game.team2 = new Team(); Button createGame = FindViewById <Button>(Resource.Id.createGameBtn); createGame.Click += async(object sender, EventArgs e) => { if (game.team1.player1 != null && game.team2.player1 != null) { //Create a new game await GameCall.createGame(game); //Open main activity var activity = new Intent(this, typeof(MainActivity)); StartActivity(activity); } }; }