public static bool MapSwitcherChanged(MenuEvent e) { MenuControll controll = ((MenuControllEvent)e).Controll; Int2 newSize = new Int2(); if (controll.Identificator == "width") { if (controll.GetValue() == prepareMap.ContentSize.x) { return(false); } newSize = new Int2(controll.GetValue(), prepareMap.ContentSize.y); } if (controll.Identificator == "height") { if (controll.GetValue() == prepareMap.ContentSize.y) { return(false); } newSize = new Int2(prepareMap.ContentSize.x, controll.GetValue()); } EraseShips(); prepareMap.ContentSize = newSize; prepareMap.Draw(); DrawShips(); return(true); }
static bool HostAGame(MenuEvent e) { l.Erase(); GameSetup.SetupGame(e); l.Draw(); return(true); }
public static bool CollisionChanges(MenuEvent e) { CheckBoxControll c = (CheckBoxControll)((MenuControllEvent)e).Controll; prepareMap.DiagonalCollisions = c.Value == 1; prepareMap.Draw(); return(true); }
public static bool ShipCountChanged(MenuEvent e) { EraseShips(); IntSwitcherEvent ise = (IntSwitcherEvent)e; int value = ise.Value; string id = ise.Controll.Identificator; id = id.Replace("len", ""); int shipNo; if (!int.TryParse(id, out shipNo)) { return(false); } ships[shipNo - 1] = value; DrawShips(); return(true); }
public static bool ShipSetup(MenuEvent e) { EraseShips(); e.Menu.Erase(); shipControlls = new List <MenuControll>(); prepareMap.Erase(); Menu boardMenu = new Menu(new Int2(1, 1), new Int2(32, 45), "Board Setup", Boxes.BoxType.doubled) { VerticalTextWrapping = Menu.Wrapping.wrapping }; boardMenu.AddControll(new LineSeparatorControll("sep0", "sep0")); boardMenu.AddControll(new LabelControll("- Select ship -", "ship_label")); for (int i = 0; i < ships.Length; i++) { if (ships[i] > 0) { shipControlls.Add(boardMenu.AddControll(new MenuControll($"Lenght {i + 1} - {shipsOnBoard[i]}/{ships[i]} on board", $"len{i + 1}"), PutDownShip)); } } boardMenu.AddControll(new LineSeparatorControll("sep4", "sep4")); boardMenu.AddControll(new MenuControll("Go back", "exit"), boardMenu.Exit); boardMenu.AddControll(new LineSeparatorControll("sep_fin", "sep_fin")); prepareMap.ShowCollisions = true; prepareMap.Draw(); boardMenu.WaitForInput(); prepareMap.Erase(); prepareMap.ShowCollisions = false; e.Menu.Draw(); DrawShips(); prepareMap.Draw(); return(true); }
public static bool PutDownShip(MenuEvent e) { MenuControllEvent ce = (MenuControllEvent)e; TextLine comm = new TextLine(new Int2(prepareMap.Position.x, prepareMap.Size.y + 1), " ", true); comm.Size = new Int2(prepareMap.Size.x, 1); comm.Alignment = Stringer.TextAlignment.Middle; string id = ce.Controll.Identificator; id = id.Replace("len", ""); int len; bool done = false; bool save = false; if (!int.TryParse(id, out len)) { return(false); } ; Ship s = prepareMap.AddShip(len, new Int2(0, 0)); s.PickUp(); prepareMap.GenerateCollisionsMap(); s.UpdateCollisionState(); Int2 cursorPosition = new Int2(); bool wereColliding = false; bool doUpdate = true; ConsoleKey response; do { //prepareMap.GenerateCollisionsMap(); if (s.Collision == Ship.CollisionState.overlap) { wereColliding = true; comm.SetText("SHIPS ARE OVERLAPPING!", Color.Red, Color.Black); } else if (s.Collision == Ship.CollisionState.zone) { wereColliding = true; comm.SetText("SHIP IN COLLISION ZONE!", Color.DarkRed, Color.Black); } else { if (wereColliding) { wereColliding = false; comm.SetText(""); } } if (doUpdate) { prepareMap.Draw(); } response = Console.ReadKey(true).Key; switch (response) { case ConsoleKey.A: case ConsoleKey.LeftArrow: doUpdate = s.MoveBy(Int2.Left); break; case ConsoleKey.W: case ConsoleKey.UpArrow: doUpdate = s.MoveBy(Int2.Down); break; case ConsoleKey.D: case ConsoleKey.RightArrow: doUpdate = s.MoveBy(Int2.Right); break; case ConsoleKey.S: case ConsoleKey.DownArrow: doUpdate = s.MoveBy(Int2.Up); break; case ConsoleKey.Enter: done = true; break; case ConsoleKey.Escape: done = true; s.Delete(); s = null; doUpdate = true; break; case ConsoleKey.R: doUpdate = s.RotateShip(); break; } if (s != null && s.Collision != Ship.CollisionState.none) { done = false; } } while (!done); if (s != null) { s.PutDown(); shipsOnBoard[s.lenght - 1]++; Renderer.AddDissapearingText("Added a new ship", 1000, new Int2(prepareMap.Position.x + prepareMap.Size.x - 8, 0)); } prepareMap.GenerateCollisionsMap(); prepareMap.Draw(); return(save); }
public static bool TurnTimerChanges(MenuEvent e) { TurnTimer = ((MenuControllEvent)e).Controll.GetValue(); return(true); }
public static bool CollisionDistanceChanges(MenuEvent e) { prepareMap.CollisionDistance = ((MenuControllEvent)e).Controll.GetValue(); prepareMap.Draw(); return(true); }
public static bool SetupGame(MenuEvent e) { e.Menu.Erase(); GameSetup GS = new GameSetup(); Menu gameMenu = new Menu(new Int2(1, 1), new Int2(32, 45), "Game Setup", Boxes.BoxType.doubled) { VerticalTextWrapping = Menu.Wrapping.wrapping }; gameMenu.AddControll(new LineSeparatorControll("sep0", "sep0")); gameMenu.AddControll(new LabelControll("- Game options -", "game_label")); gameMenu.AddControll(new IntSwitcherControll("Turn timer", "timer") { Max = 600, Min = 0, Step = 1, Value = 0, MinSpecialText = "∞", FastStepTime = 200 }); gameMenu.AddControll(new IntSwitcherControll("Total lenght limit", "len_lim") { Max = 1152, Min = 0, Step = 1, Value = 0, MinSpecialText = "∞", FastStepTime = 200 }); gameMenu.AddControll(new IntSwitcherControll("Collision distance", "col_dist") { Value = 1, Min = 0, Max = 32, Step = 1, FastStepTime = 200 }, CollisionDistanceChanges); gameMenu.AddControll(new CheckBoxControll("Corner collisions", "cor_coll", true) { TrueValue = "■", FalseValue = " " }, CollisionChanges); gameMenu.AddControll(new LineSeparatorControll("sep1", "sep1")); gameMenu.AddControll(new LabelControll("- Board -", "board_label")); gameMenu.AddControll(new IntSwitcherControll("Board width", "width", 10, 4, 50, 1), MapSwitcherChanged); gameMenu.AddControll(new IntSwitcherControll("Board height", "height", 10, 4, 40, 1), MapSwitcherChanged); gameMenu.AddControll(new LineSeparatorControll("sep2", "sep2")); gameMenu.AddControll(new LabelControll("- Ships -", "ships_label")); for (int i = 0; i < 8; i++) { gameMenu.AddControll(new IntSwitcherControll($"Lenght {i+1}", $"{i+1}len", Arit.Clamp(4 - i, 0, 8), 0, 32, 1), ShipCountChanged); ships[i] = Arit.Clamp(4 - i, 0, 8); shipsOnBoard[i] = 0; } gameMenu.AddControll(new LineSeparatorControll("sep3", "sep3")); gameMenu.AddControll(new MenuControll("◊ START THE GAME ◊", "start"), ShipSetup); gameMenu.AddControll(new LineSeparatorControll("sep4", "sep4")); gameMenu.AddControll(new MenuControll("Go back", "exit"), gameMenu.Exit); gameMenu.AddControll(new LineSeparatorControll("sep_fin", "sep_fin")); prepareMap = new Map(new Int2(10, 10), new Int2(34, 1)); prepareMap.Draw(); DrawShips(); gameMenu.WaitForInput(); EraseShips(); prepareMap.Erase(); e.Menu.Draw(); return(true); }