public MainPage()
        {
            this.InitializeComponent();

            ResourceCandidate rc = 
                ResourceManager.Current.MainResourceMap.GetValue("Resources/txtDiff/Text",
                ResourceContext.GetForCurrentView());
            string foreground = rc  .ValueAsString;
            try
            {
                //try to set the user name from local settings
                ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;
                if (localSettings.Values["usrName"] != null)
                {
                    App.usrName = (String)localSettings.Values["usrName"];
                }
                //if not saved, user name defaults to User Name
                else
                {
                    App.usrName = "User Name";
                    localSettings.Values["usrName"] = App.usrName;
                }
                //same as above, but with difficulty setting
                if (localSettings.Values["difficulty"] != null)
                {
                    App.gmDifficulty = (int)localSettings.Values["difficulty"];
                }
                //if not saved, user name defaults to User Name
                else
                {
                    App.gmDifficulty = 4;
                    localSettings.Values["difficulty"] = App.gmDifficulty;
                }
            }
            catch (Exception settingNotFound)
            {
                //user name defaults to "User Name"
                string errMsg = settingNotFound.Message;
                App.usrName = "User Name";
                App.gmDifficulty = 4;
            }
            //loading the sources of the card images into memory
            App.posCard = new BitmapImage(new Uri(base.BaseUri, "/Resources/CardPos.png"));
            App.negCard = new BitmapImage(new Uri(base.BaseUri, "/Resources/CardNeg.png"));
            App.deckCard = new BitmapImage(new Uri(base.BaseUri, "/Resources/DeckCard.png"));

            //populate the card pool
            Card[] pool = createCardPool();

            //create new AI and user objects
            en = new SkyNet(pool, "AI");
            pl = new User(pool, App.usrName);
        }
Example #2
0
        public async Task mkMove(User u, TextBlock enScr, InGame iG, Queue<Card> deck)
        {

            //not the user's turn right now
            u.IsTrn = false;
            u.GotDk = false;
            
            if (TrnCnt < 9 && Stndng == false && IsBust==false)
            {
                await deckDeal(iG, deck);
                ScrTypePair currMv = decideMove(this.CurrScr);
                //refactor this, logic seems off
                if (currMv.CrdType != 0&&currMv.Score>App.gmDifficulty)
                {
                    //move is good, make move, then ponder future later
                    await handDeal(currMv.CrdType - 1, iG);
                    //simulate how the next turn could go
                    ScrTypePair futMv = decideMove(this.CurrScr);
                    //enemy will stand if its score is winning, and is as close to 20 as the difficulty allows
                    //will adjust and play more aggressively if for example the user is on 19, and the enemy is on 18
                    //enemy will play to win and try its hardest to get a higher score than the user
                    if (futMv.Score < App.gmDifficulty&&futMv.CrdType==0&&u.CurrScr<=this.CurrScr)
                    {
                        //if the future dosnt look good for the AI, it will stick
                        this.Stndng = true;
                    }
                }
                //if score is above 20, AI has bust
                if(this.CurrScr>20)
                {
                    this.IsBust = true;
                }
                //AI will stand if it evaluates to true
                else if((currMv.Score < App.gmDifficulty || (this.CurrScr > u.CurrScr&&u.Stndng&&u.IsBust==false)) || this.CurrScr == 20)
                {
                    this.Stndng = true;
                }
            }
            enScr.Text = this.CurrScr.ToString();
            u.IsTrn = true;
        }
        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);
            }
        }