kisame1313

Untitled

Jul 24th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.81 KB | None | 0 0
  1. using System;
  2.  
  3. class Program
  4. {
  5.     static void Main ( string [] args )
  6.     {
  7.  
  8.         NPC [] first = { new NPC(), new NPC (), new NPC (), new NPC () };
  9.         Console.CursorVisible = false;
  10.  
  11.         while ( true )
  12.         {
  13.             foreach ( NPC npc in first)
  14.             {
  15.                 RandomMove ( npc );
  16.                 Draw ( npc );
  17.             }
  18.         }
  19.     }
  20.  
  21.     static void Draw ( NPC npc )
  22.     {
  23.         Console.SetCursorPosition (npc.x,npc.y);
  24.         Console.Write ( '#' );
  25.     }
  26.  
  27.     static void RandomMove ( NPC npc )
  28.     {
  29.         Random r = new Random ();
  30.         npc.x += r.Next ( -2, 2 );
  31.         npc.y += r.Next ( -2, 2 );
  32.         if ( npc.x < 0 )
  33.         { npc.x = 0; }
  34.         if ( npc.x > Console.BufferWidth )
  35.         { npc.x = Console.BufferWidth-1; }
  36.  
  37.         if ( npc.y < 0 )
  38.         { npc.y = 0; }
  39.         if ( npc.y > Console.BufferHeight )
  40.         { npc.y = Console.BufferHeight-1; }
  41.     }
  42.  
  43.     class NPC
  44.     {
  45.         public int x=0,y=0;
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment