Esempio n. 1
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.HighScores);
            var db = new SQLiteConnection(dbPath);

            var table = db.Table <HighScore>();

            TextView txtHighscores = FindViewById <TextView>(Resource.Id.txtHighscores);

            //loading in the scores from database
            foreach (var item in table)
            {
                HighScore score = new HighScore(item.scoreID, item.Score);                                 //FIXME      does not order the highscores
                txtHighscores.Text += score + "\n ";
            }

            Button btnMenu = FindViewById <Button>(Resource.Id.btnBackToMenu);


            btnMenu.Click += BtnMenu_Click;
        }
Esempio n. 2
0
        protected void myKeyPress(object sender, EventArgs e)      //checks to see if the key pressed is in the word,then the right outcome is shown (changing colour of text, adding letters to placeholder array)
        {
            Button[] buttonArray = { KeyA, KeyB, KeyC, KeyD, KeyE, KeyF, KeyG, KeyH, KeyI, KeyJ, KeyK, KeyL, KeyM, KeyN, KeyO, KeyP, KeyQ, KeyR, KeyS, KeyT, KeyU, KeyV, KeyW, KeyX, KeyY, KeyZ };
            CheckCount = 0;
            letterInt  = 0;
            char[] letterArray = currentWORD.ToCharArray();

            Button button = sender as Button;
            var    db     = new SQLiteConnection(dbPath);

            foreach (var letter in letterArray)
            {                                                                                     //goes through each letter in the current work to check the letter guessed against letters from the word
                if (button.Text == letter.ToString() && cycleStage != 5)
                {
                    placeholderArray[letterInt] = button.Text;
                    //button.Enabled = false;
                    button.SetTextColor(Color.Green);
                }
                else if (button.Text != letter.ToString() && cycleStage != 5)
                {
                    chances++;
                    CheckCount++;
                }

                if (cycleStage == 5)
                {
                    Toast.MakeText(this, "Game over", ToastLength.Long).Show();
                }
                else if (CheckCount == letterArray.Length)
                {
                    cycleStage++;
                    hangMan.SetImageResource(gameCycle[cycleStage]);
                    //button.Enabled = false;
                    button.SetTextColor(Color.Red);
                    hangMan.SetImageResource(gameCycle[cycleStage]);
                }

                letterInt = letterInt + 1;
            }

            if (string.Concat(placeholderArray) == currentWORD)         //if the word is guessed, alert shown, score increased, new word
            {
                score         = score + 100;
                txtScore.Text = "Score: " + score;

                Android.App.AlertDialog.Builder alertDialog = new Android.App.AlertDialog.Builder(this);

                alertDialog.SetMessage("You guessed the word!");
                alertDialog.SetNeutralButton("Next Word!", delegate
                {
                    cycleStage  = 0;
                    chances     = 0;
                    Random rnd  = new Random();
                    currentWORD = db.Get <HangmanWords>(rnd.Next(1, 43)).ToString();                       //sets a new word if the guess the word
                    wordLength  = currentWORD.Length;
                    CheckCount  = 0;
                    letterInt   = 0;

                    Array.Resize(ref placeholderArray, wordLength);

                    for (int i = 0; i < placeholderArray.Length; i++)
                    {
                        placeholderArray[i] = "_ ";
                    }
                    hangMan.SetImageResource(gameCycle[cycleStage]);

                    placeholders = string.Concat(placeholderArray);
                    txtWORD.Text = placeholders;
                    foreach (var b in buttonArray)
                    {
                        b.SetTextColor(Color.Black);
                        b.Enabled = true;
                    }
                    alertDialog.Dispose();
                });
                alertDialog.Show();
            }
            placeholders = string.Concat(placeholderArray);
            txtWORD.Text = placeholders;

            if (cycleStage == 5)
            {
                //creating an alert to get the users name to save with their score
                LayoutInflater layoutInflaterAndroid = LayoutInflater.From(this);
                View           mView = layoutInflaterAndroid.Inflate(Resource.Layout.user_input_dialog_box, null);
                Android.Support.V7.App.AlertDialog.Builder alertDialogbuilder = new Android.Support.V7.App.AlertDialog.Builder(this);
                alertDialogbuilder.SetView(mView);
                alertDialogbuilder.SetTitle("Gameover");
                alertDialogbuilder.SetMessage("You ran out of attempts!");

                var userContent = mView.FindViewById <EditText>(Resource.Id.editText1);
                alertDialogbuilder.SetCancelable(false)
                .SetPositiveButton("Save", delegate
                {
                    name = userContent.Text;

                    //saving the score
                    HighScore HScore = new HighScore(name, score);
                    db.Insert(HScore);

                    score = 0;
                    StartActivity(typeof(MainActivity));
                    Finish();
                    alertDialogbuilder.Dispose();
                });
                alertDialogbuilder.Show();
            }
        }