Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Collections.Specialized;
- using System.Text;
- using System.Threading.Tasks;
- using System.Net;
- using System.Threading;
- //В следующем коде, сделайте добавление NPC перед началом цикла отрисовки.
- //NPC должны добавляться в массив в случайном количестве со случайными данными.
- namespace IMJunior
- {
- class Program
- {
- static Random R;
- static void Main ( string [] args )
- {
- R = new Random ();
- Console.CursorVisible = false;
- NPC [] NPCs;
- while ( true )
- {
- Console.Clear ();
- NPCs = new NPC [R.Next (1,6)];
- for ( int i =0 ; i < NPCs.Length; i++ )
- {
- NPCs [i] = new NPC ();
- NPCs[i].Visual = '#';
- NPCs [i].Foreground = RandomColor ();
- NPCs [i].Background = RandomColor ();
- NPCs [i].X = NPCs [i].Y = R.Next(1,11);
- MoveNPC ( NPCs [i] );
- RenderNPC ( NPCs [i] );
- }
- Thread.Sleep ( 500 );
- }
- }
- static ConsoleColor RandomColor ()
- {
- Array consoleColor = Enum.GetValues ( typeof ( ConsoleColor ) );
- return ( ConsoleColor ) R.Next ( consoleColor.Length);
- }
- static void RenderNPC ( NPC npc )
- {
- Console.SetCursorPosition ( npc.X, npc.Y );
- Console.ForegroundColor = npc.Foreground;
- Console.BackgroundColor = npc.Background;
- Console.WriteLine ( npc.Visual );
- }
- static void MoveNPC ( NPC npc )
- {
- npc.X = Clamp ( npc.X + R.Next ( -1, 2 ), 1, Console.WindowWidth );
- npc.Y = Clamp ( npc.Y + R.Next ( -1, 2 ), 1, Console.WindowHeight );
- }
- static int Clamp ( int value, int min, int max )
- {
- return ( value < min ) ? min : ( value > max ) ? max : value;
- }
- }
- class NPC
- {
- public char Visual;
- public int X, Y;
- public ConsoleColor Foreground, Background;
- }
- }
Add Comment
Please, Sign In to add comment