Advertisement
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;
- namespace lesson7
- {
- class Program
- {
- public static Random r;
- static void Main(string[] args)
- {
- Console.CursorVisible = false;
- r = new Random();
- NPC npc = new NPC('%');
- npc.Move();
- NPC[] npcs = new NPC[9/*r.Next(0, 100)*/];
- for (int i = 0; i < npcs.Length; i++)
- {
- npcs[i] = new NPC((char)r.Next(97, 119), r.Next(0, 20), r.Next(0, 20), (ConsoleColor)r.Next(0, 15));
- }
- Cursor cursorYellow = new Cursor(npcs);
- Cursor cursorRed = new Cursor(npcs);
- while (true)
- {
- Console.Clear();
- foreach (NPC n in npcs)
- {
- if (n.isLive())
- {
- n.Move();
- Console.SetCursorPosition(n.X, n.Y);
- Console.ForegroundColor = n.ForegroundColor;
- if (cursorYellow.Current() == n && cursorRed.Current() == n)
- {
- Console.BackgroundColor = ConsoleColor.Yellow;
- }
- else if(cursorRed.Current() == n && cursorYellow.Current() == n)
- {
- Console.BackgroundColor = ConsoleColor.Yellow;
- }
- else if(cursorYellow.Current() == n)
- {
- Console.BackgroundColor = ConsoleColor.Yellow;
- }
- else if(cursorRed.Current() == n)
- {
- Console.BackgroundColor = ConsoleColor.Red;
- }
- Console.Write(n.Visual);
- foreach (NPC n2 in npcs)
- {
- if (n2 != n && n2.isLive())
- {
- if (n2.X == n.X && n.Y == n2.Y)
- {
- n2.Collision();
- }
- }
- }
- }
- Console.ForegroundColor = ConsoleColor.White;
- Console.BackgroundColor = ConsoleColor.Black;
- }
- ConsoleKeyInfo key = Console.ReadKey();
- if (key.Key == ConsoleKey.Tab)
- {
- cursorYellow.MoveNext();
- }
- else if(key.Key == ConsoleKey.Enter)
- {
- cursorRed.MoveNext();
- }
- }
- }
- public static int Clamp(int value, int min, int max)
- {
- return value < min ? min : (value > max) ? max : value;
- }
- }
- /*
- * 2 метода: isLive, Collision
- * 1 поле: колличество жизней
- * Метод Collision отнимает N жизней, и ставит текущим символов, колличество жизни
- */
- class NPC
- {
- public char Visual;
- public ConsoleColor ForegroundColor;
- public int X, Y;
- public int HP = 100, MaxHP = 100;
- public bool isLive()
- {
- return HP > 0;
- }
- public void Collision()
- {
- HP -= 10;
- HP = Program.Clamp(HP, 0, 100);
- Visual = (HP / (MaxHP / 9)).ToString()[0];
- }
- public NPC(char visual, int x = 5, int y = 5, ConsoleColor fc = ConsoleColor.White)
- {
- Visual = visual;
- X = x;
- Y = y;
- ForegroundColor = fc;
- }
- public void Move()
- {
- X = Program.Clamp(X + Program.r.Next(-1, 2), 0, Console.WindowWidth);
- Y = Program.Clamp(Y + Program.r.Next(-1, 2), 0, Console.WindowHeight);
- }
- /*public void Toggle()
- {
- ConsoleColor K = BackgroundColor;
- BackgroundColor = ForegroundColor;
- ForegroundColor = K;
- }*/
- }
- }
- /*
- * Инкапсуляция
- * Полиморфизм
- * Наследование
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement