Пример #1
0
        public void Render(Surface sfc)
        {
            var equal = _pfields.Rank == _fields.Rank &&
                        Enumerable.Range(0, _pfields.Rank).All(dim => _pfields.GetLength(dim) == _fields.GetLength(dim)) &&
                        _pfields.Cast<bool>().SequenceEqual(_fields.Cast<bool>());

            if (!Won && equal)
            {
                bWon = true;
                return;
            }

            var digitHeight = f.SizeText("10").Height;
            var digitWidth = f.SizeText("10").Width;

            sfc.Fill(Color.Black);
            _fwidth = ((sfc.Width - homeArea) / size);
            _fheight = ((sfc.Height - homeArea) / size);
            for (int i = 0; i < size && !Won; i++)
            {
                var col = (i % 5 == 0) ? Color.OrangeRed : Color.White;
                var x = (short)(homeArea + (i * _fwidth));
                var y = (short)(homeArea + (i * _fheight));
                var lh = new Line(x, 0, x, (short)sfc.Height);
                var lv = new Line(0, y, (short)sfc.Width, y);
                lh.Draw(sfc, col, true);
                lv.Draw(sfc, col, true);
            }

            var colcounts = new Dictionary<int, List<int>>();
            var rowcounts = new Dictionary<int, List<int>>();
            for (int col = 0; col < size; col++)
            {
                colcounts[col] = new List<int>();
                bool counting = false;
                int count = 0;
                for (int row = 0; row < size; row++)
                {
                    if (!counting && _fields[col, row]) counting = true;
                    if (counting && !_fields[col, row])
                    {
                        counting = false;
                        colcounts[col].Add(count);
                        count = 0;
                    }
                    if (counting && _fields[col, row]) count++;
                }
                if (counting) colcounts[col].Add(count);
            }

            for (int row = 0; row < size; row++)
            {
                rowcounts[row] = new List<int>();
                bool counting = false;
                int count = 0;
                for (int col = 0; col < size; col++)
                {
                    if (!counting && _fields[col, row]) counting = true;
                    if (counting && !_fields[col, row])
                    {
                        counting = false;
                        rowcounts[row].Add(count);
                        count = 0;
                    }
                    if (counting && _fields[col, row]) count++;
                }
                if (counting) rowcounts[row].Add(count);
            }

            for (int col = 0; col < size && !Won; col++)
            {
                var colc = colcounts[col];
                for (int colcIdx = 0; colcIdx < colc.Count; colcIdx++)
                {
                    var colcSfc = f.Render(String.Format("{0}", colc[colcIdx]), Color.White, true);
                    sfc.Blit(colcSfc, new Rectangle(homeArea + col * _fwidth + 10, colcIdx * (digitHeight) + 3, digitWidth, digitHeight));
                }
            }

            for (int row = 0; row < size && !Won; row++)
            {
                var rowc = rowcounts[row];
                for (int rowcIdx = 0; rowcIdx < rowc.Count; rowcIdx++)
                {
                    var rowcSfc = f.Render(String.Format("{0}", rowc[rowcIdx]), Color.White, true);
                    sfc.Blit(rowcSfc, new Rectangle(rowcIdx * (digitWidth) + 3, homeArea + row * _fheight + 3, digitWidth, digitHeight));
                }
            }

            for (int r = 0; r < size; r++)
                for (int c = 0; c < size; c++)
                {
                    var x1 = c * _fwidth;
                    var y1 = r * _fheight;
                    if (_ufields[c, r] && !Won)
                    {
                        Line r1 = new Line((short)(x1 + homeArea), (short)(y1 + homeArea), (short)(x1 + _fwidth + homeArea), (short)(y1 + _fheight + homeArea));
                        Line r2 = new Line((short)(x1 + homeArea), (short)(y1 + _fheight + homeArea), (short)(x1 + _fwidth + homeArea), (short)(y1 + homeArea));
                        r1.Draw(sfc, Color.Tomato, true);
                        r2.Draw(sfc, Color.Tomato, true);
                    }
                    else
                    {
                        var col = (_pfields[c, r]) ? ((_fields[c, r]) ? Color.Green : Color.Yellow) : Color.Black;
                        var x = (short)((homeArea + x1) + 1);
                        var y = (short)((homeArea + y1) + 1);

                        Box b = new Box(x, y, (short)((x + _fwidth - 2)), (short)(y + _fheight - 2));
                        b.Draw(sfc, col, true, true);
                    }
                }
        }