public void InitMap()
        {
            using (var sr = new StreamReader("Map.txt"))
            {
                string line;
                Grid = new SquareGrid(15);
                int i = 0;
                while ((line = sr.ReadLine()) != null)
                {
                    var items = line.Split();
                    for (int j = 0; j < items.Length; j++)
                    {
                        var item     = items[j];
                        var freeCell = new FreeCell();
                        Grid.Rows[i][j] = freeCell;

                        if (item == "*")
                        {
                            freeCell.IsStart = true;
                        }
                        else if (item[item.Length - 1] == 'w')
                        {
                            freeCell.WordFactor = int.Parse(item.Trim('w'));
                        }
                        else
                        {
                            freeCell.Factor = int.Parse(item);
                        }
                    }
                    i++;
                }
            }
        }
Ejemplo n.º 2
0
        public void DrawGrid(SquareGrid grid)
        {
            var point = startPoint;
            var dx    = size.Width + gapSize;
            var dy    = size.Height + gapSize;

            gridGraphic.Clear(Color.White);

            var   font = SystemFonts.MessageBoxFont;
            Brush brush;

            foreach (var row in grid.Rows)
            {
                foreach (var cell in row)
                {
                    if (cell.IsStart)
                    {
                        brush = Brushes.OrangeRed;
                    }
                    else if (cell.WordFactor > 1)
                    {
                        brush = wordFactorBrushes[cell.WordFactor];
                    }
                    else
                    {
                        brush = factorBrushes[cell.Factor];
                    }

                    var rect = new Rectangle(point, size);
                    gridGraphic.FillRectangle(brush, rect);
                    if (cell.Letter != null)
                    {
                        gridGraphic.FillRectangle(Brushes.BlanchedAlmond, rect);
                        gridGraphic.DrawString(cell.Letter.ToString(), font, Brushes.Black, rect);
                    }
                    gridGraphic.DrawRectangle(cellBorderPen, rect);
                    point.X += dx;
                }
                point.X  = 0;
                point.Y += dy;
            }
            canvas.Image = gridBmp;
        }