Ejemplo n.º 1
0
        public ActionResult Solve()
        {
            Puzzel puzzel = Session["Puzzel"] as Puzzel;

            puzzel.puzzelSolutions = new SolvePuzzel().FindWords(puzzel.matrix);

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        private void OnShowHint()
        {
            Puzzel puzzleToAnimate = puzzleModel.GetCorrectlyOrderedPuzzle();

            if (puzzleToAnimate != null)
            {
                PuzzleHelper.MoveElementOnCanvas(Puzzles[puzzleToAnimate], puzzleToAnimate.Matrix.Row * puzzleModel.PuzzleSize.Width, puzzleToAnimate.Matrix.Column * puzzleModel.PuzzleSize.Height);
                puzzleModel.Move(puzzleToAnimate, new Point(puzzleToAnimate.Matrix.Column * puzzleModel.PuzzleSize.Width, puzzleToAnimate.Matrix.Row * puzzleModel.PuzzleSize.Height));
            }
        }
Ejemplo n.º 3
0
        internal void SelectPuzzle(Point point)
        {
            var PuzzleToMove = from Puzzle in puzzleModel.Puzzles
                               where (Puzzle.Location.X <= point.X && Puzzle.Location.X + Puzzle.Size.Width >= point.X &&
                                      Puzzle.Location.Y <= point.Y && Puzzle.Location.Y + Puzzle.Size.Height >= point.Y)
                               select Puzzle;

            if (PuzzleToMove.Count() >= 1)
            {
                _currentPuzzel = PuzzleToMove.FirstOrDefault();
            }
            else
            {
                _currentPuzzel = null;
            }
        }
Ejemplo n.º 4
0
        public FileResult Download()
        {
            Puzzel puzzel = Session["Puzzel"] as Puzzel;

            if (puzzel.puzzelSolutions == null || puzzel.puzzelSolutions.Count == 0)
            {
                puzzel.puzzelSolutions = new SolvePuzzel().FindWords(puzzel.matrix);
            }

            string solutionJson = JsonConvert.SerializeObject(puzzel.puzzelSolutions);

            string filename = "solution.json";

            var byteArray = Encoding.ASCII.GetBytes(solutionJson);

            return(File(byteArray, System.Net.Mime.MediaTypeNames.Text.Plain, filename));
        }
Ejemplo n.º 5
0
        public ActionResult Index()
        {
            Puzzel puzzel = null;

            puzzel = Session["Puzzel"] as Puzzel;

            if (puzzel == null)
            {
                puzzel = new Decypher().GetsWordPuzzel();
                Session.Add("Puzzel", puzzel);
            }

            ViewBag.Rows    = puzzel.matrix.GetLength(0);
            ViewBag.Columns = puzzel.matrix.GetLength(1);

            return(View(puzzel));
        }
Ejemplo n.º 6
0
        public Puzzel SetActivePuzzel(int Id, bool reset)
        {
            var t = GetTeam(Id);

            if (t == null)
            {
                return(null);
            }
            if (reset)
            {
                _teamRepo.SetActivePuzzel(Id, -1);
                return(null);
            }
            var    pl           = t.PuzzelsTeam.ToList();
            Puzzel ActivePuzzel = _puzzelRepo.GetPuzzel(pl.ElementAt(t.DiamantenVerzameld).PuzzelId);

            _teamRepo.SetActivePuzzel(Id, ActivePuzzel.Id);
            return(ActivePuzzel);
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> AddPuzzelToMarker([FromBody] Puzzel puzzel, [FromRoute] int LocatieId)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var locatie = await _context.locaties.Include(l => l.puzzels).SingleOrDefaultAsync(m => m.id == LocatieId);

            if (locatie != null)
            {
                locatie.puzzels.Add(puzzel);
                await _context.SaveChangesAsync();

                return(Created("puzzel", puzzel));
            }
            else
            {
                return(NotFound());
            }
        }
Ejemplo n.º 8
0
        public Puzzel GetsWordPuzzel()
        {
            try
            {
                LoadJsonFiles();

                LoadRulesPerRow();

                List <string> decypherRowList = new List <string>();

                foreach (var word in wordList)
                {
                    var temporalWord = word.cypherWord;
                    foreach (var rule in word.rulesPerWord)
                    {
                        if (temporalWord.Contains(rule.source))
                        {
                            temporalWord = temporalWord.Replace(rule.source, rule.replacement);
                            if (rule.isTermination)
                            {
                                break;
                            }
                        }
                    }

                    word.decypherWord = temporalWord;

                    char[] letterArray = new char[temporalWord.Length];

                    for (int i = 0; i < temporalWord.Length; i++)
                    {
                        letterArray[i] = temporalWord[i];
                    }

                    word.decypherRow = letterArray;
                    decypherRowList.Add(temporalWord);
                }

                char[,] matrix = new char[wordList.Count, wordList.First().decypherRow.Length];

                int rowNumber = 0;
                foreach (var row in wordList)
                {
                    int columnNumber = 0;
                    foreach (var letter in row.decypherRow)
                    {
                        matrix[rowNumber, columnNumber] = letter;
                        columnNumber++;
                    }
                    rowNumber++;
                }

                Puzzel puzzel = new Puzzel();
                puzzel.matrix      = matrix;
                puzzel.wordsToFind = wordsToFind;

                return(puzzel);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }