public Type chkImgTurn(Player p) { if (p.GetType() == typeof(User)) { return typeof(User); } else { return typeof(SkyNet); } }
//during animation, the moving card image is set to an animation image //i.e the App.deckCard source public void txtCardVal(Int16 val, Player p) { if (!p.Stndng) { if (p.GetType() == typeof(SkyNet)) { srchTxtBlks("enCrd" + (en.TrnCnt), enTxtBlks).Text = val.ToString(); srchImg("enCrdImg" + (en.TrnCnt), enImgs).Source = App.deckCard; } else { srchTxtBlks("usrCrd" + (pl.TrnCnt), usrTxtBlks).Text = val.ToString(); srchImg("usrCrdImg" + (pl.TrnCnt), usrImgs).Source = App.deckCard; } } }
//this resets the players and starts a new round private async void newFrme() { await Task.Delay(500); pl.reset(); en.reset(); Player[] arr = new Player[2] { en, pl }; Frame.Navigate(typeof(InGame), arr); }
public void printHandCard(int trnCnt, int crdVal, Player p) { //print hand cards to table BitmapSource bmS = chkCardSign(crdVal); Type t = chkImgTurn(p); if (t == typeof(User)) { Image thisImg = srchImg("usrCrdImg" + trnCnt, usrImgs); srchTxtBlks("usrCrd" + (pl.TrnCnt), usrTxtBlks).Text = crdVal.ToString(); setImg(thisImg, bmS); } else { Image thisImg = srchImg("enCrdImg" + trnCnt, enImgs); srchTxtBlks("enCrd" + (en.TrnCnt), enTxtBlks).Text = crdVal.ToString(); setImg(thisImg, bmS); rmvEnHnd(crdVal.ToString()); } }
//a dynamic story board that uses tasks to auto complete themselves when the duration is complete private async Task animateCard(String imageNm, Player p) { Storyboard sb = new Storyboard(); DoubleAnimation da = new DoubleAnimation(); Storyboard.SetTargetProperty(da, "Opacity"); Storyboard.SetTarget(da, srchImg(imageNm, getImgArr(p))); srchImg(imageNm, getImgArr(p)).Source = new BitmapImage(new Uri(base.BaseUri, "/Resources/CardBack.png")); da.From = 0; da.To = 2; da.AutoReverse = true; da.EnableDependentAnimation = true; da.Duration = new Duration(new TimeSpan(0, 0, 0, 0, 50)); sb.Children.Add(da); sb.Begin(); await Task.Delay((int)da.Duration.TimeSpan.TotalMilliseconds); sb.Stop(); }
//display hand value on hand card public void showUsrCardValue(TextBlock tb, Player p, int placer) { tb.Text = p.Hand[placer].Val.ToString(); }
//converts a table position into a grid square position public int getCurrGridSq(int trnCnt, Player p) { /* 11 12 13 21 22 23 31 32 33 */ switch (trnCnt) { case 1: return 11; case 2: return 12; case 3: return 13; case 4: return 21; case 5: return 22; case 6: return 23; case 7: return 31; case 8: return 32; case 9: return 33; default: return 0; } }
//gets the appropraite array based on the Player type public Image[] getImgArr(Player p) { if (p.GetType() == typeof(User)) { return usrImgs; } else { return enImgs; } }
public async Task srchGrid(Player p) { /* 11 12 13 21 22 23 31 32 33 Basis of the card animation, this method tracks the position of the card as it moves through the grid it moves the card horizontally and vertically through the grid, animating the card after every grid shift i.e: if the card is moving left, starting at 33 and wants to get to position 11 as shown above, the card will animate at 33, then shift to 22, where it will animate again, and finally move to 11, where it will be given an image source and become a static image */ int currPos = 0; //the user card moves left from 33 if (p.GetType() == typeof(User)) { currPos = 33; } //the AI moves right from 31 else if (p.GetType() == typeof(SkyNet)) { currPos = 31; } //the final position the image needs to move toward int finalPos = getCurrGridSq(p.TrnCnt, p); if (finalPos != 0) { while (currPos != finalPos) { //animate card to current position if (p.GetType() == typeof(User)) { await animateCard("usrCrdImg" + getImgSq(currPos), p); } else if (p.GetType() == typeof(SkyNet)) { int y = getImgSq(currPos); await animateCard("enCrdImg" + getImgSq(currPos), p); } if (currPos % 10 != finalPos % 10) { //user needs a left shift if (p.GetType() == typeof(User)) { currPos--; } //AI needs a right shift else if (p.GetType() == typeof(SkyNet)) { currPos++; } } //both card types need to move up if ((int)currPos / 10 > (int)finalPos / 10) { currPos -= 10; } } //grab image source Image img; if (p.GetType() == typeof(User)) { img = srchImg("usrCrdImg" + getImgSq(finalPos), getImgArr(p)); } else { img = srchImg("enCrdImg" + getImgSq(finalPos), getImgArr(p)); } if (img != null) { //display card image img.Opacity = 2; //img.Source = App.deckCard; } } }
private void button_Click(object sender, RoutedEventArgs e) { //on click event sends user to an instance of the inGame page //an array of players is passed as a parameter Player[] arr = new Player[2] {en, pl}; this.Frame.Navigate(typeof(InGame), arr); }
//method that keeps track of the game loop public void rndWn(Player p, InGame ig) { //the game is reset once the amount of rounds won by the current player is above 2 if (this.rndsWn<2) { this.rndsWn++; } else { ResourceCandidate rc; rc = ResourceManager.Current.MainResourceMap.GetValue("Resources/newGm", ResourceContext.GetForCurrentView()); string newGm = rc.ValueAsString; this.rndsWn++; ig.status = newGm; this.gmsWn++; //HighScore h = new HighScore(this.gmsWn, p.gmsWn); //h.readScores(); //h.writeScores(); } }