private void StopRecordVisualMemory() { Recording = false; SendVisualMemoryToProcess(); FrameBuffer.Clear(); }
private Result Run(ref FrameBuffer fb) { Snake s = new Snake( (byte)(_random.Next() % FrameBuffer.Width), (byte)(_random.Next() % FrameBuffer.Height), (Snake.Direction)(_random.Next() % 4)); MakeFood(s, out byte foodX, out byte foodY); long gameTime = Environment.TickCount64; while (true) { fb.Clear(); if (!s.Update()) { s.Draw(ref fb); return(Result.Loss); } s.Draw(ref fb); if (Console.KeyAvailable) { ConsoleKeyInfo ki = Console.ReadKey(intercept: true); switch (ki.Key) { case ConsoleKey.UpArrow: s.Course = Snake.Direction.Up; break; case ConsoleKey.DownArrow: s.Course = Snake.Direction.Down; break; case ConsoleKey.LeftArrow: s.Course = Snake.Direction.Left; break; case ConsoleKey.RightArrow: s.Course = Snake.Direction.Right; break; } } if (s.HitTest(foodX, foodY)) { if (s.Extend()) { MakeFood(s, out foodX, out foodY); } else { return(Result.Win); } } fb.SetPixel(foodX, foodY, '*'); fb.Render(); gameTime += 100; long delay = gameTime - Environment.TickCount64; if (delay >= 0) { Thread.Sleep((int)delay); } else { gameTime = Environment.TickCount64; } } }
public override void ProcessReceivedCharacter(char c) { if (!inCmd) { switch (c) { case CONTROL_E: SendString("CRTerm"); break; case '\x09': int x = FrameBuffer.X % 8; x += 8 - x; FrameBuffer.X = x; break; case '\x0C': FrameBuffer.Clear(); FrameBuffer.Locate(0, 0); break; case ESCAPE: inCmd = true; inOperand = 0; operands.Clear(); operands.Add(0); break; default: base.ProcessReceivedCharacter(c); break; } } else { if (inCmd && c >= '0' && c <= '9') { operands[inOperand] *= 10; operands[inOperand] += (int)(c - '0'); } else { switch (c) { case '[': inOperand = 0; break; case ';': inOperand += 1; operands.Add(0); break; case 'A': inCmd = false; for (int i = 0; i < Math.Max(operands[0], 1); i++) { FrameBuffer.Y -= 1; } break; case 'B': inCmd = false; for (int i = 0; i < Math.Max(operands[0], 1); i++) { FrameBuffer.Y += 1; } break; case 'C': for (int i = 0; i < Math.Max(operands[0], 1); i++) { FrameBuffer.X += 1; } inCmd = false; break; case 'D': inCmd = false; for (int i = 0; i < Math.Max(operands[0], 1); i++) { FrameBuffer.X -= 1; } break; case 'c': FrameBuffer.Clear(); FrameBuffer.Locate(0, 0); inCmd = false; break; case 'H': inCmd = false; if (operands.Count > 0) { FrameBuffer.Y = Math.Max(operands[0] - 1, 0); } else { FrameBuffer.Y = 0; } if (operands.Count > 1) { FrameBuffer.X = Math.Max(operands[1] - 1, 0); } else { FrameBuffer.X = 0; } break; case 'J': inCmd = false; if (operands[0] == 1) { FrameBuffer.ClearTopToCursor(); } else if (operands[0] == 2) { FrameBuffer.Clear(); } else { FrameBuffer.ClearCursorToEnd(); } break; case 'n': if (operands[0] == 6) { SendString(ESCAPE + "[" + (FrameBuffer.Y + 1).ToString() + ";" + (FrameBuffer.X + 1).ToString() + "R"); } break; default: inCmd = false; break; } } } }
public void ClearBuffer() { FrameBuffer.Clear(); }