protected override async void OnNavigatedTo(NavigationEventArgs e) { //arrays containing various controls created at design time //helps to greatly improve efficiency when searching for control values usrImgs = new Image[9] { usrCrdImg1, usrCrdImg2, usrCrdImg3, usrCrdImg4, usrCrdImg5, usrCrdImg6, usrCrdImg7, usrCrdImg8, usrCrdImg9 }; enImgs = new Image[9] { enCrdImg1, enCrdImg2, enCrdImg3, enCrdImg4, enCrdImg5, enCrdImg6, enCrdImg7, enCrdImg8, enCrdImg9 }; enTxtBlks = new TextBlock[9] { enCrd1, enCrd2, enCrd3, enCrd4, enCrd5, enCrd6, enCrd7, enCrd8, enCrd9 }; usrTxtBlks = new TextBlock[9] { usrCrd1, usrCrd2, usrCrd3, usrCrd4, usrCrd5, usrCrd6, usrCrd7, usrCrd8, usrCrd9 }; enHndImgs = new Image[4] { enHnd1, enHnd2, enHnd3, enHnd4 }; enTbHnds = new TextBlock[4] { tbEnHnd1, tbEnHnd2, tbEnHnd3, tbEnHnd4 }; //boolean values control access to buttons in game endTurnTapped = false; standTapped = false; usedCard = false; //take in a parameter of the two player objects created in the previous page. //I chose to take parameters to display my knowledge of multiple ways to pass data between pages Player[] arr = e.Parameter as Player[]; if (arr != null) { //setting the players en = (SkyNet)arr[0]; pl = (User)arr[1]; usrScrSwch(); enScrSwch(); //display name of object on screen enBlk.Text = en.Name; usrBlk.Text = pl.Name; //make hands for the user and en popHndCrds(); //initialize the hand images initHands(); //create an actual deck of cards mkDeck(); //initially gives user a card pl.deckCall(false, usrScr, this, deck); //animates the user's deck card on screen await srchGrid(pl); } }
//tap event to end turn private async void button_Tapped(object sender, TappedRoutedEventArgs e) { //if its user's turn and end turn hasnt already been tapped this turn if (!endTurnTapped && !(pl.Stndng)) { //lock access to button endTurnTapped = true; //stop user's round if true if (pl.autoBust(this)) { //show end round message if both parties are done if (chkScrs()) { await showMsg(); newFrme(); } //otherwise stand and wait for opponent to complete their move else { await stand(); } } else { //otherwise just end the turn await endTurn(); //once AI is finished their turn, give user another card pl.deckCall(false, usrScr, this, deck); } //unlock access to button endTurnTapped = false; usedCard = false; } }