Beispiel #1
0
        public static void Swap(ref cord a, ref cord b)
        {
            cord c = a;

            a = new cord(b);
            b = new cord(c);
        }
Beispiel #2
0
 public Display(cord p, int a, int b)
 {
     pos = new cord(p);
     arr = new char[a][];
     for (int i = 0; i < a; i++)
     {
         arr[i] = new char[b];
     }
 }
Beispiel #3
0
 void StopMove()
 {
     EngineStop();
     stats.speed = 0;
     stats.move  = false;
     target      = null;
     cords       = null;
     s           = 0;
 }
Beispiel #4
0
 public static Bot IsShipThere(cord c)
 {
     foreach (Bot m in bots)
     {
         if (m.pos == c)
         {
             return(m);
         }
     }
     return(null);
 }
Beispiel #5
0
 public void SetMove(cord c)
 {
     cords = new List <cord>();
     cords.Add(stats.position);
     cords.AddRange(Map.Line(stats.position, c).ToList());
     cords.Add(c);
     target = c;
     SpeedCalculate();
     stats.move = true;
     EngineStart();
 }
Beispiel #6
0
 public static void Step(cord c)
 {
     ShowMap();
     if (!pause)
     {
         Doing();
     }
     if (lining == true)
     {
         Drow(Line(target.pos, c));
     }
     lastCord = new cord(c);
 }
Beispiel #7
0
 public static void ShowMap()
 {
     foreach (Bot n in bots)
     {
         Console.ForegroundColor = n.logic.stats.color;
         cord z = n.pos;
         Console.SetCursorPosition(z.x, z.y);
         Console.Write(n.c);
         //foreach (Obj o in n.ToObj())
         //    map.Insert(o);
     }
     //foreach (string str in map.ToString())
     //    Console.Write(str);
     Console.ResetColor();
 }
Beispiel #8
0
 static void Press(ConsoleKeyInfo a, cord b)
 {
     if (a.Key == ConsoleKey.Spacebar)
     {
         Map.SetPause();
     }
     if (a.Key == ConsoleKey.N)
     {
         Map.Add(b);
     }
     if (a.Key == ConsoleKey.Enter)
     {
         Map.ShipMove(b);
     }
 }
Beispiel #9
0
 public static void ShipMove(cord c)
 {
     if (target == null)
     {
         Bot t = IsShipThere(c);
         if (t != null)
         {
             SetPause();
             ShipMove(t);
         }
     }
     else
     {
         lining = false;
         target.Move(c);
         target = null;
         UnsetPause();
     }
 }
Beispiel #10
0
        static void Main(string[] args)
        {
            Cursor.Position = new Point(0, 0);
            Console.SetCursorPosition(0, 0);
            ConsoleKeyInfo t     = new ConsoleKeyInfo();
            Stopwatch      watch = new Stopwatch();
            bool           exit  = false;

            while (!exit)
            {
                Console.Clear();
                watch.Start();
                Map.ShowMap();
                Console.SetCursorPosition(Cursor.Position.X / 16, Cursor.Position.Y / 37 + 1);
                cord c = new cord(Console.CursorLeft, Console.CursorTop);
                Map.Step(c);//подружить с событиями и делегатами
                Console.SetCursorPosition(Cursor.Position.X / 16, Cursor.Position.Y / 37);
                c = new cord(Console.CursorLeft, Console.CursorTop);
                if (Console.KeyAvailable)
                {
                    t = Console.ReadKey(true);
                    if (t.Key == ConsoleKey.Escape)
                    {
                        exit = true;
                    }
                    else
                    {
                        Press(t, c);
                    }
                }
                watch.Stop();
                Console.SetCursorPosition(Cursor.Position.X / 16 + 1, Cursor.Position.Y / 37); //Лишнее
                Console.Write(watch.Elapsed);
                Console.SetCursorPosition(Cursor.Position.X / 16, Cursor.Position.Y / 37);     //Лишнее
                if (watch.ElapsedMilliseconds < 200)
                {
                    Thread.Sleep((int)(200 - watch.ElapsedMilliseconds));
                }
                watch.Reset();
            }
        }
Beispiel #11
0
        public static cord[] Line(cord a, cord b)
        {
            if (a == b)
            {
                return(null);
            }
            int         dx       = Math.Abs(b.x - a.x);
            int         dy       = Math.Abs(b.y - a.y);
            bool        reversed = false;
            List <cord> cords    = new List <cord>();

            if (dx >= dy)
            {
                if (a.x > b.x)
                {
                    cord.Swap(ref a, ref b);
                }
                for (int i = a.x, j = a.y; i <= b.x; i++)
                {
                    cords.Add(new cord(i, j));
                    if (i != 0 && dy != 0 && j != b.y && i % (dx / dy) == 0)
                    {
                        if (a.y > b.y)
                        {
                            j--;
                        }
                        else
                        {
                            j++;
                        }
                        cords.Add(new cord(i, j));
                    }
                }
            }
            else
            {
                reversed = true;
                if (a.y > b.y)
                {
                    cord.Swap(ref a, ref b);
                }
                for (int i = a.y, j = a.x; i <= b.y; i++)
                {
                    cords.Add(new cord(j, i));
                    if (i != 0 && dx != 0 && j != b.x && i % (dy / dx) == 0)
                    {
                        if (a.x > b.x)
                        {
                            j--;
                        }
                        else
                        {
                            j++;
                        }
                        cords.Add(new cord(j, i));
                    }
                }
            }
            cords.RemoveAt(cords.Count - 1);
            cords.RemoveAt(0);
            if (reversed)
            {
                cords.Reverse();
            }
            return(cords.ToArray());
        }
Beispiel #12
0
 public Obj(char z, cord s, ConsoleColor clr = ConsoleColor.Black)
 {
     pos   = new cord(s);
     c     = z;
     color = clr;
 }
Beispiel #13
0
 public static void Add(cord c)
 {
     new Bot(c);
 }
Beispiel #14
0
 public Bot(cord z, char a = 'w') : this()
 {
     pos = z;
     c   = a;
     logic.stats.color = ConsoleColor.Blue;
 }
Beispiel #15
0
 public cord(cord a)
 {
     x = a.x;
     y = a.y;
 }
Beispiel #16
0
 public void SetMove(cord a)
 {
 }