public static void Swap(ref cord a, ref cord b) { cord c = a; a = new cord(b); b = new cord(c); }
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]; } }
void StopMove() { EngineStop(); stats.speed = 0; stats.move = false; target = null; cords = null; s = 0; }
public static Bot IsShipThere(cord c) { foreach (Bot m in bots) { if (m.pos == c) { return(m); } } return(null); }
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(); }
public static void Step(cord c) { ShowMap(); if (!pause) { Doing(); } if (lining == true) { Drow(Line(target.pos, c)); } lastCord = new cord(c); }
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(); }
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); } }
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(); } }
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(); } }
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()); }
public Obj(char z, cord s, ConsoleColor clr = ConsoleColor.Black) { pos = new cord(s); c = z; color = clr; }
public static void Add(cord c) { new Bot(c); }
public Bot(cord z, char a = 'w') : this() { pos = z; c = a; logic.stats.color = ConsoleColor.Blue; }
public cord(cord a) { x = a.x; y = a.y; }
public void SetMove(cord a) { }