Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- namespace _2._4._1._3npc
- {
- class Program
- {
- static Random R;
- static void Main(string[] args)
- {
- R = new Random();
- NPCGenerator generator = new NPCGenerator();
- List<NPC> AllNPC = new List<NPC>();
- int NPCCount = R.Next(3, 10);
- for(int i=1; i<=NPCCount;i++)
- {
- NPC newNPC = generator.CreateNPC();
- AllNPC.Add(newNPC);
- }
- Console.CursorVisible = false;
- while (true)
- {
- Console.Clear();
- foreach(NPC n in AllNPC)
- {
- MoveNPC(n);
- RenderNPC(n);
- }
- Thread.Sleep(500);
- }
- }
- 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), 0, Console.WindowWidth);
- npc.Y = Clamp(npc.Y + R.Next(-1, 2), 0, 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;
- public NPC(char ch, int coord, ConsoleColor frgr)
- {
- Visual = ch;
- X = Y = coord;
- Foreground = frgr;
- Background = ConsoleColor.White;
- }
- }
- class NPCGenerator
- {
- Random r = new Random();
- public char[] CharSource = new char[] {'$', '@', '%', '^','&','*','~','{','#','!' };
- public ConsoleColor[] ColorSource = new ConsoleColor[] {ConsoleColor.DarkRed, ConsoleColor.DarkMagenta, ConsoleColor.Green, ConsoleColor.Red, ConsoleColor.Yellow, ConsoleColor.Gray, ConsoleColor.DarkYellow, ConsoleColor.DarkGreen, ConsoleColor.Blue, ConsoleColor.Magenta };
- public int[] CoordinatesSource = new int[] { 6, 8, 10, 12, 4, 15, 5, 17, 19, 21 };
- public NPC CreateNPC()
- {
- char NPCchar = CharSource[r.Next(0, 9)];
- ConsoleColor NPCColor = ColorSource[r.Next(0, 9)];
- int NPCCoordinates = CoordinatesSource[r.Next(0, 9)];
- NPC randomNPC = new NPC(NPCchar, NPCCoordinates, NPCColor);
- return randomNPC;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment