public void genPlayer() { int x, y; do { x = StaticRandom.Next(1, map.Height - 1); y = StaticRandom.Next(1, map.Width - 1); } while (!map.isFree(x, y)); pl = new Player(x, y); map[x, y] = Player.cursor[0]; }
private Orientation ChooseOrientation(int height, int width) { if (width < height) { return(Orientation.HOR); } else if (width > height) { return(Orientation.VER); } else { return(StaticRandom.Next(2) == 0 ? Orientation.VER : Orientation.HOR); } }
public void genTrolls(int n) { trolls = new List <Troll>(); for (int i = 0; i < n; i++) { int x, y; do { x = StaticRandom.Next(1, map.Height - 1); y = StaticRandom.Next(1, map.Width - 1); } while (!map.isFree(x, y)); trolls.Add(new Troll(x, y)); map[x, y] = Troll.calmCursor; } }
private void PutExit() { switch (StaticRandom.Next(4)) { case 0: int k = StaticRandom.Next(1, Height - 1); while (isWall(k, 1)) { k = StaticRandom.Next(1, Height - 1); } map[k][0] = 'e'; exit = new Point(k, 0); break; case 1: k = StaticRandom.Next(1, Width - 1); while (isWall(1, k)) { k = StaticRandom.Next(1, Width - 1); } map[0][k] = 'e'; exit = new Point(0, k); break; case 2: k = StaticRandom.Next(1, Height - 1); while (isWall(k, Width - 2)) { k = StaticRandom.Next(1, Height - 1); } map[k][Width - 1] = 'e'; exit = new Point(k, Width - 1); break; case 3: k = StaticRandom.Next(1, Width - 1); while (isWall(Height - 2, k)) { k = StaticRandom.Next(1, Width - 1); } map[Height - 1][k] = 'e'; exit = new Point(Height - 1, k); break; } }
private void TrollCalmMode(Troll t) { map[t.Position] = MazeMap.Empty; if (StaticRandom.Next(6) > 1 && map.isFree(t.DesirePosition)) { t.Position += t.Dir; } else { double j = t.Dir.X == 0 ? Math.Acos(t.Dir.Y) : -Math.Asin(t.Dir.X); for (double k = j + Math.PI / 2; k > double.MinValue; k += Math.PI / 2) { t.Dir = Extensions.Direction(k); if (StaticRandom.Next(3) > 1 && (map.isFree(t.DesirePosition) || Player.arrows.Contains(map[t.DesirePosition]))) { break; } } t.Position = t.DesirePosition; } map[t.Position] = Troll.calmCursor; CheckForPlayer(t); }
private void BuildByDivide(int x, int y, int _height, int _width, Orientation or, MazeMode mode) { if (_width < 2 || _height < 2) { return; } if (_width < 3 || _height < 3) { if (StaticRandom.Next(0, 3) > 1) { return; } } bool hor = or == Orientation.HOR; int hy1, hx1, hy2, hx2, hx3, hy3; int wy = y + (hor ? 0 : StaticRandom.Next(_width - 2)); int wx = x + (hor ? StaticRandom.Next(_height - 2) : 0); if ((mode == MazeMode.OneWay) || _height < 5 || _width < 5) { hy1 = hy2 = hy3 = wy + (hor ? StaticRandom.Next(_width) : 0); hx1 = hx2 = hx3 = wx + (hor ? 0 : StaticRandom.Next(_height)); } else if (!hor && _width >= 5 && _width <= 15) { hy1 = hy2 = hy3 = wy; hx1 = wx + StaticRandom.Next(_height / 2 - 1); hx2 = hx3 = wx + StaticRandom.Next(_height / 2, _height); } else if (hor && _height >= 5 && _height <= 15) { hy1 = wy + StaticRandom.Next(_width / 2 - 1); hx1 = hx2 = hx3 = wx; hy2 = hy3 = wy + StaticRandom.Next(_width / 2, _width); } else { hy1 = wy + (hor ? StaticRandom.Next(_width / 3 - 1) : 0); hx1 = wx + (hor ? 0 : StaticRandom.Next(_height / 3)); hy2 = wy + (hor ? StaticRandom.Next(_width / 3 + 1, 2 * _width / 3 - 1) : 0); hx2 = wx + (hor ? 0 : StaticRandom.Next(_height / 3 + 1, 2 * _height / 3 - 1)); hy3 = wy + (hor ? StaticRandom.Next(2 * _width / 3 + 1, _width) : 0); hx3 = wx + (hor ? 0 : StaticRandom.Next(2 * _height / 3 + 1, _height)); } for (int i = 0; i < (hor ? _width : _height); i++) { if (!((wx == hx1 && wy == hy1) || (wx == hx2 && wy == hy2) || (wx == hx3 && wy == hy3))) { if (map[wx][wy] != ' ') { map[wx][wy] = 'b'; } else { map[wx][wy] = hor ? 'h' : 'v'; } } wy += (hor ? 1 : 0); wx += (hor ? 0 : 1); } int newh = hor ? wx - x + 1 : _height; int neww = hor ? _width : wy - y + 1; BuildByDivide(x, y, newh, neww, ChooseOrientation(newh, neww), mode); newh = hor ? _height - wx + x - 1 : _height; neww = hor ? _width : _width - wy + y - 1; BuildByDivide(hor ? wx + 1 : x, hor ? y : wy + 1, newh, neww, ChooseOrientation(newh, neww), mode); }