Example #1
0
		public void SavePuzzle (LetterGrid letterGrid) {
			var documentsPath = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
			var filePath = Path.Combine (documentsPath, "XamWordsSave.xml");

			using (Stream writer = new FileStream (filePath, FileMode.Create)) {
				XmlSerializer serializer = new XmlSerializer(typeof(LetterGrid));
				serializer.Serialize (writer, letterGrid);
			}
		}
Example #2
0
		public override void Init (object initData) 
		{
			Puzzle = initData as Puzzle;
			if (Puzzle == null) { //Restore saved grid
				LetterGrid = _storageService.LoadPuzzle ();
				if (LetterGrid == null) {// Load failed, return random instead
					Random rnd = new Random ();
					int rndPuzzle = rnd.Next (_databaseService.GetPuzzles ().Count);
					Puzzle = _databaseService.GetPuzzles () [rndPuzzle];
					LetterGrid = new LetterGrid (_databaseService.GetWords (Puzzle));
				} else {
					Puzzle = _databaseService.GetPuzzle (LetterGrid.PuzzleName);
				}
			} else {
				LetterGrid = new LetterGrid (_databaseService.GetWords (Puzzle));
			}
			Words = new ObservableCollection<Word> (LetterGrid.AssembledWords);
			LetterGrid.PuzzleName = Puzzle.Name;
			PuzzleName = Puzzle.Name.ToUpper ();
			SelectedLetters = "";

			List<Word> Wordlist = (from w in Words
				orderby w.Text
				orderby w.Text.Replace(" ", String.Empty).Length
				select w).ToList();

			Word GroupWord = new Word { Found = true };
			int columnLength = 16;

			int curRow = 0;
			int curColumn = 0;

			int curLength = 0;
			foreach (Word word in Wordlist)
			{
				if (word.Text.Replace(" ", String.Empty).Length > curLength)
				{
					if (curRow >= columnLength - 3)
					{
						curColumn++;
						curRow = 0;
					}
					else if (curRow > 0)
					{
						Label newBlank = new Label ();
						newBlank.Text = " ";
						newBlank.FontSize = 18;
						newBlank.VerticalOptions = LayoutOptions.Center;
						newBlank.FontAttributes = FontAttributes.Bold;
						CurrentPage.FindByName<Grid> ("Wordgrid").Children.Add (newBlank, curColumn, curRow);
						curRow++;
					}
					curLength = word.Text.Replace(" ", String.Empty).Length;

					Label newGroup = new Label ();
					newGroup.Text = curLength.ToString() + " LETTERS:";
					newGroup.FontSize = 14;
					newGroup.VerticalOptions = LayoutOptions.Center;
					newGroup.FontAttributes = FontAttributes.Bold;
					newGroup.SetBinding (Label.TextColorProperty, new Binding("Found", BindingMode.Default, new BooleanStyleConverter(), CurrentPage.FindByName<ResourceDictionary>("BackgroundColors") ));
					newGroup.BindingContext = GroupWord;
					CurrentPage.FindByName<Grid> ("Wordgrid").Children.Add (newGroup, curColumn, curRow);
					curRow++;
				}
				else if (curRow >= columnLength)
				{
					curColumn++;
					curRow = 0;
				}

				Label newWord = new Label ();
				newWord.Text = word.Text;
				newWord.FontSize = 18;
				newWord.VerticalOptions = LayoutOptions.Center;
				newWord.FontAttributes = FontAttributes.Bold;
				newWord.SetBinding (Label.TextColorProperty, new Binding("Found", BindingMode.Default, new BooleanStyleConverter(), CurrentPage.FindByName<ResourceDictionary>("BackgroundColors") ));
				newWord.BindingContext = word;
				CurrentPage.FindByName<Grid> ("Wordgrid").Children.Add (newWord, curColumn, curRow);

				curRow++;
			}

			foreach (Letter l in LetterGrid.Letters) {
				Label newLetter = new Label ();
				newLetter.FontSize = 18;
				newLetter.FontAttributes = FontAttributes.Bold;
				newLetter.VerticalOptions = LayoutOptions.Center;
				newLetter.HorizontalOptions = LayoutOptions.Center;
				newLetter.Text = l.Text;
				newLetter.SetBinding (Label.TextColorProperty, new Binding("Found", BindingMode.Default, new BooleanStyleConverter(), CurrentPage.FindByName<ResourceDictionary>("BackgroundColors") ));
				newLetter.BindingContext = l;
				CurrentPage.FindByName<Grid> ("Lettergrid").Children.Add (newLetter, l.x, l.y);
			}

			Highlight1 = new LetterHighlight();
			Highlight2 = new LetterHighlight();
			Highlight3 = new LetterHighlight();
			Highlight4 = new LetterHighlight();
			Highlight5 = new LetterHighlight();
			Highlight6 = new LetterHighlight();
			Highlight7 = new LetterHighlight();
			Highlight8 = new LetterHighlight();
			Highlight9 = new LetterHighlight();
			Highlight10 = new LetterHighlight();
			Highlight11 = new LetterHighlight();
			Highlight12 = new LetterHighlight();

			Highlights.Add (Highlight1);
			Highlights.Add (Highlight2);
			Highlights.Add (Highlight3);
			Highlights.Add (Highlight4);
			Highlights.Add (Highlight5);
			Highlights.Add (Highlight6);
			Highlights.Add (Highlight7);
			Highlights.Add (Highlight8);
			Highlights.Add (Highlight9);
			Highlights.Add (Highlight10);
			Highlights.Add (Highlight11);
			Highlights.Add (Highlight12);
		}