fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading.Tasks;
  4.  
  5. namespace App
  6. {
  7. public class World
  8. {
  9. public List<IActor> Actors { get; } = new List<IActor>();
  10.  
  11. private readonly int fieldH;
  12. private readonly int fieldW;
  13. private readonly Point _drawingPoint;
  14.  
  15. public World(int h, int w, Point drawingPoint)
  16. {
  17. fieldH = h;
  18. fieldW = w;
  19. _drawingPoint = drawingPoint;
  20. }
  21. public void DrawField()
  22. {
  23. char[] c = new char[fieldW];
  24. Array.Fill(c, '.');
  25.  
  26. for (int i = 0; i < fieldH; i++)
  27. {
  28. Console.SetCursorPosition(_drawingPoint.X, _drawingPoint.Y + i);
  29. Console.WriteLine(c);
  30. }
  31. foreach (var actor in Actors)
  32. {
  33. DrawActor(actor);
  34. }
  35. Console.ResetColor();
  36. Console.SetCursorPosition(0, _drawingPoint.Y + fieldH + 1);
  37. }
  38. public void Tick()
  39. {
  40. foreach (var actor in Actors)
  41. {
  42. actor.TickAction();
  43. }
  44. }
  45.  
  46. private void DrawActor(IActor actor)//Чтобы наш эктор в рамках поля рисовался
  47. {
  48. Console.SetCursorPosition((actor.PositionInsideField.X + _drawingPoint.X), (actor.PositionInsideField.Y + _drawingPoint.Y));
  49. Console.ForegroundColor = actor.Color;
  50. Console.Write(actor.Icon);
  51. }
  52. }
  53.  
  54. public struct Point
  55. {
  56. public int X, Y;
  57. public Point(int x, int y)
  58. {
  59. X = x;
  60. Y = y;
  61. }
  62. }
  63. public interface IActor
  64. {
  65. ConsoleColor Color { get; }
  66. char Icon { get; }
  67. Point PositionInsideField { get; }
  68. void TickAction();
  69. }
  70. public class ActorA : IActor
  71. {
  72. public ConsoleColor Color => ConsoleColor.Red;
  73.  
  74. public char Icon => '@';
  75.  
  76. private Point pos = new Point(2, 2);
  77. public Point PositionInsideField => pos;
  78.  
  79. private bool moveRight = false;
  80. public void TickAction()
  81. {
  82. if (moveRight)
  83. pos.X++;
  84. else
  85. pos.X--;
  86. if (pos.X > 10 || pos.X < 1)
  87. moveRight = !moveRight;
  88. }
  89. }
  90. public class ActorB : IActor
  91. {
  92. public ConsoleColor Color => ConsoleColor.Blue;
  93.  
  94. public char Icon => '*';
  95.  
  96. private Point pos = new Point(9, 9);
  97. public Point PositionInsideField => pos;
  98.  
  99. private bool moveUp = false;
  100. public void TickAction()
  101. {
  102. if (moveUp)
  103. pos.Y++;
  104. else
  105. pos.Y--;
  106. if (pos.Y > 10 || pos.Y < 1)
  107. moveUp = !moveUp;
  108. }
  109. }
  110. class Program
  111. {
  112. public static int ReadInt => int.Parse(Console.ReadLine());
  113. public static async Task Main()
  114. {
  115. World f = new World(20, 20, new Point(5, 5));
  116. f.Actors.Add(new ActorA());
  117. f.Actors.Add(new ActorB());
  118. while (true)
  119. {
  120. f.Tick();
  121. f.DrawField();
  122. await Task.Delay(50);
  123. }
  124. }
  125. }
  126. }
  127.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(113,34): warning CS0028: `App.Program.Main()' has the wrong signature to be an entry point
error CS5001: Program `prog.exe' does not contain a static `Main' method suitable for an entry point
Compilation failed: 1 error(s), 1 warnings
stdout
Standard output is empty