protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Main); //sets the content view to the layout Button btnPlay = FindViewById <Button>(Resource.Id.btnPlay); //connects the elements from the layout Button btnScores = FindViewById <Button>(Resource.Id.BtnScores); Button btnExit = FindViewById <Button>(Resource.Id.btnExit); var db = new SQLiteConnection(dbPath2); //opens a connection to SQLLite db.CreateTable <WordsListDatabase>(); // creates my table with empty fields var table = db.Table <WordsListDatabase>(); //connects to the table in the database if (table.Count() != 0) //do nothing if table already has words init { Toast.MakeText(this, "WORDS DATABASE EXISTS", ToastLength.Short).Show(); //toast message to check if database exists. } else if (table.Count() == 0) //add the records if the table is empty { Toast.MakeText(this, "WORDS DATABASE CREATED", ToastLength.Long).Show(); //toast message when table gets created WordsListDatabase word0 = new WordsListDatabase("FERMENT"); //creates an emtry in the table WordsListDatabase word1 = new WordsListDatabase("DISTINCTIVE"); WordsListDatabase word2 = new WordsListDatabase("POTATOES"); WordsListDatabase word3 = new WordsListDatabase("SMOKY"); WordsListDatabase word4 = new WordsListDatabase("FRUITY"); WordsListDatabase word5 = new WordsListDatabase("GRAVY"); WordsListDatabase word6 = new WordsListDatabase("MATURED"); WordsListDatabase word7 = new WordsListDatabase("SWEET"); WordsListDatabase word8 = new WordsListDatabase("SAUSAGE"); WordsListDatabase word9 = new WordsListDatabase("NUTRITIOUS"); WordsListDatabase word10 = new WordsListDatabase("CABBAGE"); WordsListDatabase word11 = new WordsListDatabase("AEDJVLDS"); WordsListDatabase word12 = new WordsListDatabase("JOKES"); WordsListDatabase word13 = new WordsListDatabase("REPUTATION"); WordsListDatabase word14 = new WordsListDatabase("SERVED"); WordsListDatabase word15 = new WordsListDatabase("POISON"); WordsListDatabase word16 = new WordsListDatabase("WHISKEY"); WordsListDatabase word17 = new WordsListDatabase("RAW"); WordsListDatabase word18 = new WordsListDatabase("POISON"); WordsListDatabase word19 = new WordsListDatabase("CRUST"); WordsListDatabase word20 = new WordsListDatabase("TRUST"); WordsListDatabase word21 = new WordsListDatabase("CULINARY"); WordsListDatabase word22 = new WordsListDatabase("FRIED"); WordsListDatabase word23 = new WordsListDatabase("CHEESE"); WordsListDatabase word24 = new WordsListDatabase("MIXED"); db.Insert(word0); db.Insert(word1); db.Insert(word2); db.Insert(word3); db.Insert(word4); //inserts the emtry into the table db.Insert(word5); db.Insert(word6); db.Insert(word7); db.Insert(word8); db.Insert(word9); db.Insert(word10); db.Insert(word11); db.Insert(word12); db.Insert(word13); db.Insert(word14); db.Insert(word15); db.Insert(word16); db.Insert(word17); db.Insert(word18); db.Insert(word19); db.Insert(word20); db.Insert(word21); db.Insert(word22); db.Insert(word23); db.Insert(word24); } btnPlay.Click += delegate { StartActivity(typeof(PlayerActivity)); var db2 = new SQLiteConnection(dbPath); //connection for the sqllite database db2.CreateTable <PlayerDatabase>(); //creates table from the class file }; btnScores.Click += delegate { StartActivity(typeof(ScoresActivity)); //starts defined activity var db2 = new SQLiteConnection(dbPath); //connection for the sqllite database db2.CreateTable <PlayerDatabase>(); //creates table from the class file }; btnExit.Click += delegate { Android.App.AlertDialog.Builder dialog = new Android.App.AlertDialog.Builder(this, Android.App.AlertDialog.ThemeHoloDark); Android.App.AlertDialog alert = dialog.Create(); alert.SetCancelable(false); alert.SetTitle("EXIT GAME"); alert.SetMessage("Are You Sure?"); alert.SetButton("YES", (c, ev) => { Process.KillProcess(Process.MyPid()); }); alert.SetButton2("NO", (c, ev) => { alert.Cancel(); }); alert.Show(); }; }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.Game); var db = new SQLiteConnection(dbPath); //adds connection to the database var table = db.Table <PlayerDatabase>(); //gets the table from the database var db2 = new SQLiteConnection(dbPath2); var table2 = db2.Table <WordsListDatabase>(); TextView txtWord = FindViewById <TextView>(Resource.Id.txtWord); TextView txtWelcome = FindViewById <TextView>(Resource.Id.txtWelcome); TextView txtScore = FindViewById <TextView>(Resource.Id.txtScore); Button btnMainMenu = FindViewById <Button>(Resource.Id.btnMainMenu); Button btnReset = FindViewById <Button>(Resource.Id.btnReset); ImageView images = FindViewById <ImageView>(Resource.Id.ivHang); Button A = FindViewById <Button>(Resource.Id.bA); Button B = FindViewById <Button>(Resource.Id.bB); Button C = FindViewById <Button>(Resource.Id.bC); Button D = FindViewById <Button>(Resource.Id.bD); Button E = FindViewById <Button>(Resource.Id.bE); Button F = FindViewById <Button>(Resource.Id.bF); Button G = FindViewById <Button>(Resource.Id.bG); Button H = FindViewById <Button>(Resource.Id.bH); Button I = FindViewById <Button>(Resource.Id.bI); Button J = FindViewById <Button>(Resource.Id.bJ); Button K = FindViewById <Button>(Resource.Id.bK); Button L = FindViewById <Button>(Resource.Id.bL); Button M = FindViewById <Button>(Resource.Id.bM); Button N = FindViewById <Button>(Resource.Id.bN); Button O = FindViewById <Button>(Resource.Id.bO); Button P = FindViewById <Button>(Resource.Id.bP); Button Q = FindViewById <Button>(Resource.Id.bQ); Button R = FindViewById <Button>(Resource.Id.bR); Button S = FindViewById <Button>(Resource.Id.bS); Button T = FindViewById <Button>(Resource.Id.bT); Button U = FindViewById <Button>(Resource.Id.bU); Button V = FindViewById <Button>(Resource.Id.bV); Button W = FindViewById <Button>(Resource.Id.bW); Button X = FindViewById <Button>(Resource.Id.bX); Button Y = FindViewById <Button>(Resource.Id.bY); Button Z = FindViewById <Button>(Resource.Id.bZ); Random ran = new Random(); AlertDialog.Builder dialog = new AlertDialog.Builder(this, AlertDialog.ThemeHoloDark); AlertDialog alert = dialog.Create(); alert.SetCancelable(false); alert.SetTitle("GAME OVER"); alert.SetMessage("Would You Like to Play Again?"); PlayerDatabase Player = table.Last(); txtWelcome.Text = "PLAYER:" + Player.PlayerName; txtScore.Text = "SCORE:" + Player.Scores; WordsListDatabase Word = table2.ElementAt(ran.Next(1, 25)); //randomly picks a word from the table string wordHolder = Word.Words; //stores the word var array1 = new char[1]; //creates an array Array.Resize <char>(ref array1, wordHolder.Length); //resizes the array to the size of the word array1 = array1.Select(i => '-').ToArray(); //replaces the letters with '-' txtWord.Text = new string(array1); //shows the array in textview string temp = new string(array1); var buttonList = new List <Button> { A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z }; void Winner() { if (temp.IndexOf('-') == -1) //checks if the string has any blank letters { alert.SetTitle("CONGRATULATIONS"); alert.SetMessage("Play Again?"); alert.SetButton("YES", (c, ev) => { Player.Scores += 100; db.Update(Player); StartActivity(typeof(MainGame)); Finish(); }); alert.SetButton2("NO", (c, ev) => { StartActivity(typeof(MainActivity)); Finish(); }); alert.Show(); } } for (var i = 0; i < buttonList.Count; i++) //cycles through all the buttons to find out which one is pressed { var button = buttonList[i]; button.Tag = i; //stores buttons value from its tag button.Click += (sender, e) => { button.Enabled = false; //disables that button buttonPressed = Convert.ToChar(button.Text); for (int l = 0; l < wordHolder.Length; l++) //checks for the length of the random word { if (wordHolder[l] == buttonPressed) { //Update the correctly guessed letters, (using value of i to determine which letter to make visible.) int indexNum = wordHolder.IndexOf(buttonPressed, l); StringBuilder sb = new StringBuilder(temp); //builds the string when the buttonPressed is correct sb[indexNum] = buttonPressed; temp = sb.ToString(); } } txtWord.Text = temp; if (wordHolder.Contains(buttonPressed)) { } //checks for false buttons pressed else //if wrong button is pressed than chances of loosing goes up { chances++; switch (chances) { case 0: // number of tries and consequences before player looses images.SetImageResource(Resource.Drawable.Hang0); break; case 1: images.SetImageResource(Resource.Drawable.Hang1); break; case 2: images.SetImageResource(Resource.Drawable.Hang2); break; case 3: images.SetImageResource(Resource.Drawable.Hang3); break; case 4: images.SetImageResource(Resource.Drawable.Hang4); break; case 5: images.SetImageResource(Resource.Drawable.Hang5); break; case 6: images.SetImageResource(Resource.Drawable.Hang6); Toast.MakeText(this, "LAST CHANCE!", ToastLength.Short).Show(); break; case 7: //player looses if they cant guess on the last try images.SetImageResource(Resource.Drawable.Hang7); alert.SetButton("YES", (c, ev) => { StartActivity(typeof(MainGame)); Finish(); }); alert.SetButton2("MAIN MENU", (c, ev) => { StartActivity(typeof(MainActivity)); Finish(); }); alert.Show(); break; } } Winner(); }; } btnReset.Click += delegate { alert.SetTitle("RESET GAME"); alert.SetMessage("Are You Sure?"); alert.SetButton("YES", (c, ev) => { StartActivity(typeof(MainGame)); Finish(); }); alert.SetButton2("NO", (c, ev) => { alert.Cancel(); }); alert.Show(); }; btnMainMenu.Click += delegate { alert.SetTitle("MAIN MENU"); alert.SetMessage("Are You Sure?"); alert.SetButton("YES", (c, ev) => { StartActivity(typeof(MainActivity)); Finish(); }); alert.SetButton2("NO", (c, ev) => { alert.Cancel(); }); alert.Show(); }; }