Beispiel #1
0
 public void UnRenderObject()
 {
     if (_renderedConsole != null)
     {
         _renderedConsole.Clear();
         _renderedConsole = null;
     }
 }
 public override void ProcessKeyboard(SadConsole.Console console, Keyboard info, out bool handled)
 {
     if (info.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.Space))
     {
         console.DefaultBackground = Color.White.GetRandomColor(SadConsole.Global.Random);
         console.Clear();
     }
     handled = false;
 }
Beispiel #3
0
 public void Render()
 {
     Console.Clear();
     if (lines.Count == 0 || curDisplayedLines == 0)
     {
         return;
     }
     if (DateTime.Now - lines[lines.Count - curDisplayedLines].WriteTime > msgTime)
     {
         curDisplayedLines--;
     }
     for (int i = 0; i < curDisplayedLines; i++)
     {
         Program.Window.PrintMessage(i, lines[lines.Count - (curDisplayedLines - i)].Text, GUI.MapWidth - 1, lines[lines.Count - 1 - i].Color);
     }
 }
        private Polynomino()
        {
            SadConsole.Game.Create(width, height);
            SadConsole.Game.OnInitialize = () => {
                PolynominoBuilder polyBuilder = new PolynominoBuilder();
                polynominoes = polyBuilder.Build(10);

                console                  = new Console(width, height);
                console.IsFocused        = true;
                console.Cursor.IsEnabled = false;

                SadConsole.Global.CurrentScreen = console;

                start = DateTime.UtcNow.Subtract(TimeSpan.FromMilliseconds(millisecondDelay));
            };

            SadConsole.Game.OnUpdate = (gameTime) => {
                if (start.AddMilliseconds(millisecondDelay) < DateTime.UtcNow)
                {
                    currentPolyIndex++;
                    if (currentPolyIndex >= polynominoes[currentRank].Count)
                    {
                        currentRank++;
                        if (currentRank > polynominoes.Count)
                        {
                            currentRank = 1;
                            console.Clear();
                            workingX = 1;
                            workingY = 1;
                        }
                        currentPolyIndex = 0;
                    }

                    foreground = Color.White.GetRandomColor(rng);

                    string   polyString = polynominoes[currentRank][currentPolyIndex];
                    string[] outputs    = polyString.Split('\n');

                    // figure out if new row start is needed
                    int spaceLeft     = width - 2 - workingX;
                    int outputsLength = outputs.Max(s => s.Length);
                    if (spaceLeft < outputsLength)
                    {
                        workingX = 1;
                        workingY = maxY + 1;
                    }

                    // See if a new wipe needs to happen
                    if (workingY + outputs.Length >= height - 1)
                    {
                        console.Clear();
                        workingX = 1;
                        workingY = 1;
                        maxY     = 1;
                    }

                    maxY = Math.Max(maxY, workingY + outputs.Length);

                    int y = workingY;
                    foreach (string line in outputs)
                    {
                        console.Print(workingX, y, line, foreground);
                        y++;
                    }
                    workingX += outputsLength + 1;

                    start = DateTime.UtcNow;
                }
            };

            SadConsole.Game.Instance.Run();
            SadConsole.Game.Instance.Dispose();
        }