Example #1
0
        /*
         * Animate the next path. NOTE: This method should not be run in a synchronous event handler; it is
         * meant to be called within a concurrent thread.
         */
        private void VisualizePath()
        {
            // If there are no more paths to display
            if (NextPathIdx == AllPaths.Count)
            {
                PopupDialog popup = new PopupDialog(
                    "No more words!",
                    "You have entered all the words we've found on the grid.",
                    this.Location,
                    false);
                popup.ShowDialog();
                return;
            }

            WordamentPath nextPath = AllPaths[NextPathIdx++];

            WordLabel.Invoke(new EventHandler(delegate { WordLabel.Text = nextPath.Word; }));
            ScoreLabel.Invoke(new EventHandler(delegate { ScoreLabel.Text = nextPath.TotalScore.ToString(); }));
            CounterLabel.Invoke(new EventHandler(delegate { CounterLabel.Text = $"{NextPathIdx}/{AllPaths.Count}"; }));

            if (nextPath.Locations.Count == 1)
            {
                // If the path is one tile long, just put a stop image on it
                GridCell   startingPt = nextPath.Locations[0];
                PictureBox pic        = TilePics[startingPt];
                pic.Invoke(new EventHandler(delegate { pic.Image = TileImageTable.GetImage(ImageType.Stop); }));
            }
            else
            {
                // Select the starting tile image
                GridCell   startingPt = nextPath.Locations[0];
                PictureBox startPic   = TilePics[startingPt];
                startPic.Invoke(new EventHandler(delegate { startPic.Image = GetStartImage(startingPt, nextPath.Locations[1]); }));

                Thread.Sleep(ANIMATION_DELAY_MS);

                // Select each of the inner tile images
                for (int i = 1; i < nextPath.Locations.Count - 1; i++)
                {
                    GridCell   currentPt = nextPath.Locations[i];
                    PictureBox pic       = TilePics[currentPt];
                    pic.Invoke(new EventHandler(delegate { pic.Image = GetPathImage(currentPt, nextPath.Locations[i + 1]); }));
                    Thread.Sleep(ANIMATION_DELAY_MS);
                }

                // Put a stop image on the final tile
                GridCell   lastPt  = nextPath.Locations[nextPath.Locations.Count - 1];
                PictureBox lastPic = TilePics[lastPt];
                lastPic.Invoke(new EventHandler(delegate { lastPic.Image = TileImageTable.GetImage(ImageType.Stop); }));
            }
        }
Example #2
0
        /*
         * Returns the image for the current tile on the current path (use GetStartingImage if the tile is the
         * first one on a path).
         */
        private Image GetPathImage(GridCell currentPt, GridCell nextPt)
        {
            int rowDiff    = nextPt.Row - currentPt.Row;
            int columnDiff = nextPt.Column - currentPt.Column;

            if (rowDiff > 0)
            {
                if (columnDiff > 0)
                {
                    return(TileImageTable.GetImage(ImageType.Southeast));
                }
                else if (columnDiff < 0)
                {
                    return(TileImageTable.GetImage(ImageType.Southwest));
                }
                else
                {
                    return(TileImageTable.GetImage(ImageType.South));
                }
            }
            else if (rowDiff < 0)
            {
                if (columnDiff > 0)
                {
                    return(TileImageTable.GetImage(ImageType.Northeast));
                }
                else if (columnDiff < 0)
                {
                    return(TileImageTable.GetImage(ImageType.Northwest));
                }
                else
                {
                    return(TileImageTable.GetImage(ImageType.North));
                }
            }
            else
            {
                if (columnDiff > 0)
                {
                    return(TileImageTable.GetImage(ImageType.East));
                }
                else
                {
                    return(TileImageTable.GetImage(ImageType.West));
                }
            }
        }
Example #3
0
 /*
  * Replaces all tile images in the previously displayed path with the "not in path" image.
  * NOTE: This method should not be run in a synchronous event handler; it is meant to be called
  * within a concurrent thread.
  */
 private void EraseLastPath()
 {
     if (NextPathIdx == 0)             // if the first path has yet to be displayed, we must set every tile's image
     {
         foreach (PictureBox pic in TilePics)
         {
             pic.Invoke(new EventHandler(delegate { pic.Image = TileImageTable.GetImage(ImageType.NotInPath); }));
         }
     }
     else
     {
         foreach (GridCell position in AllPaths[NextPathIdx - 1].Locations)
         {
             PictureBox pic = TilePics[position];
             pic.Invoke(new EventHandler(delegate { pic.Image = TileImageTable.GetImage(ImageType.NotInPath); }));
         }
     }
 }
Example #4
0
        public ShowPathsForm(List <WordamentPath> allPaths, int roundNum)
        {
            InitializeComponent();

            AllPaths    = allPaths;
            NextPathIdx = 0;

            TilePics = Grid <PictureBox> .Unflatten(new PictureBox[]
            {
                pictureBox2, pictureBox3, pictureBox4, pictureBox5,
                pictureBox9, pictureBox8, pictureBox7, pictureBox6,
                pictureBox13, pictureBox12, pictureBox11, pictureBox10,
                pictureBox17, pictureBox16, pictureBox15, pictureBox14
            },
                                                    SetupGridForm.GridRows,
                                                    SetupGridForm.GridColumns
                                                    );

            this.Text         = string.Format("Paths - Round {0}", roundNum);
            pictureBox1.Image = TileImageTable.GetImage(ImageType.Background);
        }
Example #5
0
        static void Main(string[] args)
        {
            // Load the set of images used to represent tiles
            if (!TileImageTable.LoadImages())
            {
                return;
            }

            // Load the tile scores from a file
            if (!TileScoreTable.BuildFromFile(tileScoresFilename))
            {
                return;
            }

            // Load the dictionary from a file
            if (!BuildDictionaryFromFile(dictFilename))
            {
                return;
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new StartForm());
        }