private void PlaceUserShip(Ship sh) { ConsoleKeyInfo rkey; SelectedBlocks sb = new SelectedBlocks(sh.blocks[0].xPos, sh.blocks[0].yPos, sh.length, sh.direction); UserSea.SelectBlocks(sb); do { rkey = Console.ReadKey(true); if (rkey.Key != ConsoleKey.Enter && (rkey.Key == ConsoleKey.LeftArrow || rkey.Key == ConsoleKey.RightArrow || rkey.Key == ConsoleKey.UpArrow || rkey.Key == ConsoleKey.DownArrow || rkey.Key == ConsoleKey.D)) { UserSea.UnSelectBlocks(sb); switch (rkey.Key) { case ConsoleKey.LeftArrow: sb.Move(MoveDirection.Left); break; case ConsoleKey.RightArrow: sb.Move(MoveDirection.Right); break; case ConsoleKey.UpArrow: sb.Move(MoveDirection.Up); break; case ConsoleKey.DownArrow: sb.Move(MoveDirection.Down); break; case ConsoleKey.D: UserSea.ChangeDirection(ref sb); break; default: break; } UserSea.SelectBlocks(sb); } else { for (int i = 0; i < sh.length; i++) { sh.blocks[i].xPos = sb.blocks[i].xPos; sh.blocks[i].yPos = sb.blocks[i].yPos; } if (!UserSea.AddShip(sh)) { //didnt add ship AddMessage(MessageType.System, this.m.SHIP_INTERSECT); rkey = new ConsoleKeyInfo(); } } } while (rkey.Key != ConsoleKey.Enter); }
public Block GetAttackPosition(int xpos = 0, int ypos = 0) { ConsoleKeyInfo rkey; SelectedBlocks sb = new SelectedBlocks(xpos, ypos, 1, ShipDirection.Horizontal); Block b = sb.blocks[0]; do { ComputerSea.SelectBlocks(sb); rkey = Console.ReadKey(true); if (rkey.Key != ConsoleKey.Enter && (rkey.Key == ConsoleKey.LeftArrow || rkey.Key == ConsoleKey.RightArrow || rkey.Key == ConsoleKey.UpArrow || rkey.Key == ConsoleKey.DownArrow || rkey.Key == ConsoleKey.D)) { ComputerSea.UnSelectBlocks(sb); switch (rkey.Key) { case ConsoleKey.LeftArrow: sb.Move(MoveDirection.Left); break; case ConsoleKey.RightArrow: sb.Move(MoveDirection.Right); break; case ConsoleKey.UpArrow: sb.Move(MoveDirection.Up); break; case ConsoleKey.DownArrow: sb.Move(MoveDirection.Down); break; case ConsoleKey.D: ComputerSea.ChangeDirection(ref sb); break; default: break; } } else { b = sb.blocks[0]; if (b.blockType == SeaType.Attacked && b.blockType == SeaType.Hit) { //ALREADY ATTACKED rkey = new ConsoleKeyInfo(); AddMessage(MessageType.System, this.m.USER_ALREADY_ATTACKED); } else { ComputerSea.UnSelectBlocks(sb); } } } while (rkey.Key != ConsoleKey.Enter); return b; }