Esempio n. 1
0
            public SandPileFromStrings(string stringIn)
            {
                StringIn = stringIn;
                SandPile = null;
                IsValid  = false;
                // This has the effect of working for any combination of CR and LF but will ignore any blank lines
                var spRows = stringIn.Split('\r', '\n').
                             Where(r => !string.IsNullOrEmpty(r.Trim())).
                             Select(r => r.Trim()).
                             ToArray();

                // Make sure all rows are of same length
                if (spRows.
                    GroupBy(r => r.Length).
                    ToList().Count() != 1)
                {
                    Message = "Different numbers of columns in rows";
                    return;
                }
                if (spRows.
                    Where(r => !OnlyDigits(r)).Count() != 0)
                {
                    Message = "Value other than digit in data";
                }
                var rowColArr = spRows.
                                Select(r => r.Select(c => Convert.ToInt32(c.ToString())).ToArray()).
                                ToArray();

                SandPile = new SandPile(rowColArr, rowColArr[0].Count(), rowColArr.Count());
                IsValid  = true;
            }
Esempio n. 2
0
        public static void PutSandPileInRichTextBox(RichTextBox richTextBox, SandPile sandPile)
        {
            richTextBox.Text = sandPile.RawDump();
            var zeroTo3 = new Regex("^[0-3]$");

            for (int i = 0; i < richTextBox.Text.Length; i++)
            {
                var thisChar = richTextBox.Text.Substring(i, 1);
                richTextBox.Select(i, 1);
                if (!zeroTo3.IsMatch(thisChar))
                {
                    richTextBox.SelectionColor = Color.Red;
                }
                else
                {
                    switch (thisChar)
                    {
                    case "0": richTextBox.SelectionColor = Color.Gray; break;

                    case "1": richTextBox.SelectionColor = Color.Green; break;

                    case "2": richTextBox.SelectionColor = Color.Blue; break;

                    case "3": richTextBox.SelectionColor = Color.DarkViolet; break;

                    default: throw new Exception($"Unknown character: {thisChar}");
                    }
                }
            }
            richTextBox.Select(0, 0);
        }
Esempio n. 3
0
 public static void doShow(SandPileC.SandPile sandPile)
 {
     using (var shwPile = new frmShowSandPile())
     {
         shwPile.frmSandPile = sandPile;
         shwPile.ShowMySandPile();
         shwPile.ShowInTaskbar = false;
         shwPile.ShowDialog();
     }
 }