Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.61 KB | None | 0 0
  1.         private static void snakeLoop(object state)
  2.         {
  3.             int position = 0;
  4.  
  5.             while (true)
  6.             {
  7.                 for (int i = 0; i < 8; i++)
  8.                 {
  9.                     Console.SetCursorPosition(9, 10+i);
  10.                     Console.Write("=");
  11.                     Console.SetCursorPosition(15, 10+i);
  12.                     Console.Write("=");
  13.                 }
  14.                 for (int i = 0; i < 6; i++)
  15.                 {
  16.                     Console.SetCursorPosition(9 + i, 9);
  17.                     Console.Write("=");
  18.                     Console.SetCursorPosition(9+i, 17);
  19.                     Console.Write("=");
  20.                 }
  21.  
  22.                 System.Threading.Thread.Sleep(300);
  23.                 Console.Clear();
  24.                 for (int i = 0; i < 4; i++)
  25.                 {
  26.                     int[] pos = snakeNewPos(position + i);
  27.                     Console.SetCursorPosition(10 + pos[0], 10 + pos[1]);
  28.                     Console.Write("#");
  29.                 }
  30.                 position = (position + 1) % 35;
  31.             }
  32.         }
  33.  
  34.         private static int [] snakeNewPos(int i)
  35.         {
  36.             int[] result = new int[]{0,0};
  37.  
  38.             // X
  39.             result[0] = i / 7;
  40.  
  41.             // Y
  42.             if (result[0] % 2  == 0)
  43.             {
  44.                 result[1] = i % 7;
  45.             }
  46.             else
  47.             {
  48.                 result[1] = 6 - (i % 7);
  49.             }
  50.  
  51.             System.Diagnostics.Debug.WriteLine(string.Format("{2}) x={0}; y={1}", result[0], result[1], i));
  52.  
  53.             return result;
  54.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement