Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Program
- {
- static void Main ( string [] args )
- {
- NPC [] first = { new NPC(), new NPC (), new NPC (), new NPC () };
- Console.CursorVisible = false;
- while ( true )
- {
- foreach ( NPC npc in first)
- {
- RandomMove ( npc );
- Draw ( npc );
- }
- }
- }
- static void Draw ( NPC npc )
- {
- Console.SetCursorPosition (npc.x,npc.y);
- Console.Write ( '#' );
- }
- static void RandomMove ( NPC npc )
- {
- Random r = new Random ();
- npc.x += r.Next ( -2, 2 );
- npc.y += r.Next ( -2, 2 );
- if ( npc.x < 0 )
- { npc.x = 0; }
- if ( npc.x > Console.BufferWidth )
- { npc.x = Console.BufferWidth-1; }
- if ( npc.y < 0 )
- { npc.y = 0; }
- if ( npc.y > Console.BufferHeight )
- { npc.y = Console.BufferHeight-1; }
- }
- class NPC
- {
- public int x=0,y=0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment