public bool CanAddSegment(SpaceshipSegment segment, int row, int col) { // Рядом с существующими сегментами if (Matrix[row - 1, col] == null && Matrix[row, col - 1] == null && Matrix[row + 1, col] == null && Matrix[row, col + 1] == null) { return(false); } // Нет противоречий if ((row - 1 >= 0 && Matrix[row - 1, col] != null && !Matrix[row - 1, col].CanPlace(segment, SpaceshipSegment.TDirection.Down)) || (col - 1 >= 0 && Matrix[row, col - 1] != null && !Matrix[row, col - 1].CanPlace(segment, SpaceshipSegment.TDirection.Right)) || (row + 1 < Matrix.GetLength(0) && Matrix[row + 1, col] != null) && !Matrix[row + 1, col].CanPlace(segment, SpaceshipSegment.TDirection.Up) || (col + 1 < Matrix.GetLength(1) && Matrix[row, col + 1] != null) && !Matrix[row, col + 1].CanPlace(segment, SpaceshipSegment.TDirection.Left)) { return(false); } // Есть связь if ((row - 1 >= 0 && Matrix[row - 1, col] != null && Matrix[row - 1, col].CanConnect(segment, SpaceshipSegment.TDirection.Down)) || (col - 1 >= 0 && Matrix[row, col - 1] != null && Matrix[row, col - 1].CanConnect(segment, SpaceshipSegment.TDirection.Right)) || (row + 1 < Matrix.GetLength(0) && Matrix[row + 1, col] != null) && Matrix[row + 1, col].CanConnect(segment, SpaceshipSegment.TDirection.Up) || (col + 1 < Matrix.GetLength(1) && Matrix[row, col + 1] != null) && Matrix[row, col + 1].CanConnect(segment, SpaceshipSegment.TDirection.Left)) { return(true); } return(false); }
public bool Equals(SpaceshipSegment other) { return(other.Type == Type && other.MainDirection == MainDirection && other.SocketDown == SocketDown && other.SocketLeft == SocketLeft && other.SocketRight == SocketRight && other.SocketUp == SocketUp && other.Capacity == Capacity && other.IsMain == IsMain); }
public bool AddSegment(SpaceshipSegment segment, int row, int col) { if (!CanAddSegment(segment, row, col)) { return(false); } Matrix[row, col] = segment; return(true); }
public bool CanConnect(SpaceshipSegment other, TDirection direction) { Tuple <TSocket, TSocket> sockets = CalculateSockets(other, direction); TSocket socket1 = sockets.Item1; TSocket socket2 = sockets.Item2; return(CanPlace(other, direction) && socket1 != SpaceshipSegment.TSocket.No && socket2 != SpaceshipSegment.TSocket.No); }
public bool CanPlace(SpaceshipSegment other, TDirection direction) { Tuple <TSocket, TSocket> sockets = CalculateSockets(other, direction); TSocket socket1 = sockets.Item1; TSocket socket2 = sockets.Item2; return(socket1 == socket2 || (socket2 == SpaceshipSegment.TSocket.Universal && socket1 != SpaceshipSegment.TSocket.No) || (socket1 == SpaceshipSegment.TSocket.Universal && socket2 != SpaceshipSegment.TSocket.No)); }
private async void btnGetSegment_Click(object sender, EventArgs e) { if (queuePictureBox.Image == null && !isReady) { Task <string> taskMessage = connection.GetSegment(); await taskMessage; if (!taskMessage.Result.Equals("Empty")) { CurrentSegment = new SpaceshipSegment(taskMessage.Result.Split(':')[1]); queuePictureBox.SizeMode = PictureBoxSizeMode.StretchImage; queuePictureBox.Image = CurrentSegment.Image; } } }
public Spaceship(int number) { if (number == 1) { ValidCells = new TupleList <int, int> { { 3, 2 }, { 4, 2 }, { 5, 2 }, { 2, 3 }, { 3, 3 }, { 4, 3 }, { 5, 3 }, { 1, 4 }, { 2, 4 }, { 3, 4 }, { 4, 4 }, { 2, 5 }, { 3, 5 }, { 4, 5 }, { 5, 5 }, { 3, 6 }, { 4, 6 }, { 5, 6 } }; MainCabinPosition = new Tuple <int, int>(3, 4); Matrix = new SpaceshipSegment[10, 10]; Matrix[MainCabinPosition.Item1, MainCabinPosition.Item2] = new SpaceshipSegment("Cabin0333321"); } }
public Tuple <TSocket, TSocket> CalculateSockets(SpaceshipSegment other, TDirection direction) { TSocket socket1 = this.SocketUp; TSocket socket2 = other.SocketDown; if (direction == TDirection.Right) { socket1 = this.SocketRight; socket2 = other.SocketLeft; } if (direction == TDirection.Down) { socket1 = this.SocketDown; socket2 = other.SocketUp; } if (direction == TDirection.Left) { socket1 = this.SocketLeft; socket2 = other.SocketRight; } return(new Tuple <TSocket, TSocket>(socket1, socket2)); }
public MainWindow() { FormBorderStyle = FormBorderStyle.FixedSingle; MaximizeBox = false; MinimizeBox = false; StartPosition = FormStartPosition.CenterScreen; InitializeComponent(); queuePictureBox.MouseDown += queuePictureBox_MouseDown; storePictureBox1.DragEnter += storePictureBox_DragEnter; storePictureBox2.DragEnter += storePictureBox_DragEnter; storePictureBox1.DragDrop += storePictureBox_DragDrop; storePictureBox2.DragDrop += storePictureBox_DragDrop; storePictureBox1.AllowDrop = true; storePictureBox2.AllowDrop = true; storePictureBox1.MouseDown += storePictureBox_MouseDown; storePictureBox2.MouseDown += storePictureBox_MouseDown; openPanel.DragEnter += openPanel_DragEnter; openPanel.DragDrop += openPanel_DragDrop; cardsButton1.Click += cardsButton_Click; cardsButton2.Click += cardsButton_Click; cardsButton3.Click += cardsButton_Click; Ship = new Spaceship(1); StoreSegments = new SpaceshipSegment[2]; foreach (Tuple <int, int> coord in Ship.ValidCells) { PictureBox pictureBox = new PictureBox(); pictureBox.BackColor = System.Drawing.SystemColors.ControlDark; tableLayoutPanel1.Controls.Add(pictureBox, coord.Item2, coord.Item1); pictureBox.Dock = DockStyle.Fill; pictureBox.Margin = new Padding(1); pictureBox.AllowDrop = true; pictureBox.DragEnter += pictureBox_DragEnter; pictureBox.DragDrop += pictureBox_DragDrop; } PictureBox cabinControl = (PictureBox)tableLayoutPanel1.GetControlFromPosition( Ship.MainCabinPosition.Item2, Ship.MainCabinPosition.Item1); cabinControl.AllowDrop = false; cabinControl.Image = Ship.Matrix[Ship.MainCabinPosition.Item1, Ship.MainCabinPosition.Item2].Image; for (int i = 0; i < openPanel.RowCount; i++) { for (int j = 0; j < openPanel.ColumnCount; j++) { PictureBox pictureBox = new PictureBox(); pictureBox.BackColor = System.Drawing.SystemColors.ControlLight; openPanel.Controls.Add(pictureBox, j, i); pictureBox.Dock = DockStyle.Fill; pictureBox.Margin = new Padding(1); pictureBox.MouseDown += openPanelPictureBox_MouseDown; } } openedSegments = new List <SpaceshipSegment>(); }