Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. using System;
  2.  
  3. namespace DVDScreensaver
  4. {
  5. class Program
  6. {
  7. static void Main()
  8. {
  9. Console.Title = "lmoa";
  10. Screensaver.Start(120,30,new Screensaver.Pos(5,5));
  11. }
  12. }
  13.  
  14. public class Screensaver
  15. {
  16. public static void Start(int maxX, int maxY, Pos startPos)
  17. {
  18. maxY = maxY > Console.LargestWindowHeight ? Console.LargestWindowHeight : maxY;
  19. maxX = maxX > Console.LargestWindowWidth ? Console.LargestWindowWidth : maxX;
  20. Console.WindowWidth = maxX;
  21. Console.WindowHeight = maxY;
  22. Console.BufferWidth = maxX;
  23. Console.BufferHeight = maxY;
  24. io.writeAt(50, 13, "Press enter to start");
  25. Console.ReadLine();
  26.  
  27. var modifierX = 1;
  28. var modifierY = 1;
  29. var currentPos = startPos;
  30. while (true)
  31. {
  32. Console.Clear();
  33. if (currentPos[0] == maxX -1 || currentPos[0] == 0) modifierX *= -1;
  34. if (currentPos[1] == maxY -1 || currentPos[1] == 0) modifierY *= -1;
  35. io.writeAt(currentPos[0] + modifierX, currentPos[1] + modifierY,"X");
  36. currentPos[0] += modifierX;
  37. currentPos[1] += modifierY;
  38. System.Threading.Thread.Sleep(100);
  39. }
  40.  
  41. }
  42.  
  43. public class io
  44. {
  45. public static void writeAt(int x, int y, string v)
  46. {
  47. Console.CursorLeft = x;
  48. Console.CursorTop = y;
  49. Console.Write(v);
  50. }
  51. }
  52.  
  53. public class Pos
  54. {
  55. private int PosX;
  56. private int PosY;
  57.  
  58. public Pos(int x, int y)
  59. {
  60. PosX = x;
  61. PosY = y;
  62. }
  63. public int this[int index]
  64. {
  65. get
  66. {
  67. if (index == 0) return PosX;
  68. if (index == 1) return PosY;
  69. throw new Exception("whooops");
  70. }
  71. set {
  72. if (index == 0) PosX = value;
  73. if (index == 1) PosY = value;
  74. }
  75. }
  76. }
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement