using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using Microsoft.Phone.Controls; using System.IO; using System.IO.IsolatedStorage; using System.Runtime.Serialization; //using Polenter.Serialization; namespace arvamine { public partial class MainPage : PhoneApplicationPage { // Constructor public MainPage() { InitializeComponent(); } List Estlist = new List(); List Englist = new List(); Dictionary HighScoreList = new Dictionary(); public void createArray() { Estlist.Add("mu"); Estlist.Add("isamaa"); Estlist.Add("õnn"); Estlist.Add("ja"); Estlist.Add("rõõm"); Estlist.Add("kui"); Estlist.Add("kaunis"); Estlist.Add("oled"); Estlist.Add("sa"); Estlist.Add("ei"); Estlist.Add("leidma"); Estlist.Add("mina"); Estlist.Add("iial"); Estlist.Add("teadma"); Estlist.Add("see"); Estlist.Add("suur"); Estlist.Add("lai"); Estlist.Add("maa"); Estlist.Add("peal"); Estlist.Add("mis"); Estlist.Add("nii"); Estlist.Add("armas"); Estlist.Add("olema"); Estlist.Add("ka"); Englist.Add("my"); Englist.Add("fatherland"); Englist.Add("happiness"); Englist.Add("and"); Englist.Add("joy"); Englist.Add("how"); Englist.Add("beautiful"); Englist.Add("are"); Englist.Add("you"); Englist.Add("no"); Englist.Add("find"); Englist.Add("me"); Englist.Add("ever"); Englist.Add("know"); Englist.Add("this"); Englist.Add("big"); Englist.Add("wide"); Englist.Add("earth"); Englist.Add("on"); Englist.Add("what"); Englist.Add("so"); Englist.Add("lovely"); Englist.Add("would"); Englist.Add("also"); } int RightCount = 0; int WrongCount = 0; string Ans = ""; public void generator() { if (Estlist.Count > 5) { Random random = new Random(); int randomQ = random.Next(0, Estlist.Count); int randomRightAnsBox = random.Next(0, 3); Ans = Englist[randomQ]; int randomA1 = random.Next(0, Estlist.Count); int randomA2 = random.Next(0, Estlist.Count); while (randomA1 == randomQ) { randomA1 = random.Next(0, Estlist.Count); } while (randomA2 == randomQ || randomA2 == randomA1) { randomA2 = random.Next(0, Estlist.Count); } if (randomRightAnsBox == 0) { ans1.Content = Englist[randomQ]; ans2.Content = Englist[randomA1]; ans3.Content = Englist[randomA2]; } else if (randomRightAnsBox == 1) { ans1.Content = Englist[randomA1]; ans2.Content = Englist[randomQ]; ans3.Content = Englist[randomA2]; } else { ans1.Content = Englist[randomA1]; ans2.Content = Englist[randomA2]; ans3.Content = Englist[randomQ]; } Qtext.Text = Estlist[randomQ]; } else { } } private void Start_Click(object sender, RoutedEventArgs e) { createArray(); generator(); } private void ans1_Click(object sender, RoutedEventArgs e) { Button self = sender as Button; if (self.Content.ToString() == Ans) { RightCount = RightCount + 1; Right.Text = RightCount.ToString(); } else { WrongCount = WrongCount + 1; if (WrongCount == 1) { Wrong.Text = "♥ ♥"; } else if (WrongCount == 2) { Wrong.Text = "♥"; } else if (WrongCount > 2) { End(); } } generator(); } private void ans2_Click(object sender, RoutedEventArgs e) { var self = sender as Button; if (self.Content.ToString() == Ans) { RightCount = RightCount + 1; Right.Text = RightCount.ToString(); } else { WrongCount = WrongCount + 1; if (WrongCount == 1) { Wrong.Text = "♥ ♥"; } else if (WrongCount == 2) { Wrong.Text = "♥"; } else if (WrongCount > 2) { End(); } } generator(); } private void ans3_Click(object sender, RoutedEventArgs e) { var self = sender as Button; if (self.Content.ToString() == Ans) { RightCount = RightCount + 1; Right.Text = RightCount.ToString(); } else { WrongCount = WrongCount + 1; if (WrongCount == 1) { Wrong.Text = "♥ ♥"; } else if (WrongCount == 2) { Wrong.Text = "♥"; } else if (WrongCount > 2) { End(); } } generator(); } private void End() { if (MessageBox.Show("Save to highscores?", "Final score: " + RightCount, MessageBoxButton.OKCancel) == MessageBoxResult.OK) { try { using (IsolatedStorageFile savegameStorage = IsolatedStorageFile.GetUserStoreForApplication()) { if (savegameStorage.FileExists("highscores")) { using (IsolatedStorageFileStream fs = savegameStorage.OpenFile("highscores", System.IO.FileMode.Open)) { if (fs != null) { //BinaryFormatter bformatter = new BinaryFormatter(); //bformatter.Serialize(stream, mp); //var serializer = new SharpSerializer(true); //HighScoreList = serializer.Deserialize(fs); } } } } using (var store = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication()) using (var stream = new IsolatedStorageFileStream("highscores", FileMode.Create, FileAccess.Write, store)) { if(store != null){ //var serializer = new SharpSerializer(true); //serializer.Serialize(Highscores, stream); } } } catch (Exception) { MessageBox.Show("Couldn't save the file."); } } using (var store = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication()) using (var stream = new IsolatedStorageFileStream("highscores", FileMode.Open, FileAccess.ReadWrite, store)) { StreamReader stmReader = new StreamReader(stream); Highscores.Text = stmReader.ReadToEnd(); stmReader.Close(); } Wrong.Text = "♥ ♥ ♥"; RightCount = 0; WrongCount = 0; generator(); } } }