private void InitilizePieceBox() { for (int i = 0; i < 4; i++) { GroupBox Auxiliar = this.Controls.Find("grpBoxJugador" + (i + 1), false)[0] as GroupBox; for (int j = 0; j < 7; j++) { PieceBox[] Aux; switch (i) { case 0: Aux = this.pieceBoxesPlayer1; break; case 1: Aux = this.pieceBoxesPlayer2; break; case 2: Aux = this.pieceBoxesPlayer3; break; case 3: Aux = this.pieceBoxesPlayer4; break; default: Aux = null; break; } Aux[j] = new PieceBox(-1, (Auxiliar.Controls.Find("pictureBoxPlayer" + i + "Piece" + j, false)[0] as PictureBox)); } } }
/*PARA PINTAR LAS COSAS*/ //Al hacer click en imagenes, se ejecuta este metodo: private void ClickEnFichaMesa(object sender, EventArgs e) { if (this.tengoTurno == false) { return; } //controlar que tengo el turno if (ficha_Click == null) { MessageBox.Show("Elige una Ficha."); return; } //controlar que tengo ficha seleccionada al intentar poner en mesa PictureBox Clicked = (sender as PictureBox); PieceBox Table_clicked = null; Table_clicked = ObtainPieceBoxClicked(Clicked, Table_clicked); int selector = 0; int clicked_firstValue = Table_clicked.GetValue() / 10; int clicked_secondValue = Table_clicked.GetValue() % 10; int usedIndex; PieceBox Destination = null; string pictureName = IdentifyPiecePictureName(ficha_Click.GetValue()); int picturePostion = this.imageListPieces.Images.IndexOfKey(pictureName); if (rightIndex == leftIndex) { usedIndex = CasoSeisDoble(Table_clicked, ref selector, clicked_firstValue, clicked_secondValue, ref Destination, picturePostion);//colocar por la derecha if (usedIndex == 999) { return; } } else { if (String.ReferenceEquals(Table_clicked.GetBox().Name, pieceBoxes[rightIndex].GetBox().Name)) { usedIndex = ClickDerecha(Table_clicked, ref selector, clicked_firstValue, clicked_secondValue, ref Destination, picturePostion); if (usedIndex == 999) { return; } } else if (String.ReferenceEquals(Table_clicked.GetBox().Name, pieceBoxes[leftIndex].GetBox().Name)) { usedIndex = ClickIzquierda(Table_clicked, ref selector, clicked_firstValue, clicked_secondValue, ref Destination, picturePostion); if (usedIndex == 999) { return; } } else//si no se hace click en los extremos, no se pone la ficha. { return; } } PonerLaFichaYEnviarAServidor(selector, usedIndex, Destination); }
private void PasoTurno(object sender, EventArgs e)//solo sera posible cuando el boton se active, esto solo pasa cuando no puedo poner { OcultaBotonPasar(); if (ficha_Click != null) { ficha_Click.GetBox().BorderStyle = BorderStyle.None; ficha_Click = null; } control.envia.PasoTurno(); }
private PieceBox ObtainPieceBoxClicked(PictureBox Clicked, PieceBox Table_clicked) { foreach (PieceBox piece in this.pieceBoxes) { if (Clicked.Name.Equals(piece.GetBox().Name)) { Table_clicked = piece; break; } } return(Table_clicked); }
private int ClickDerecha(PieceBox Table_clicked, ref int selector, int clicked_firstValue, int clicked_secondValue, ref PieceBox Destination, int picturePostion) { int usedIndex; PieceBox prev = Table_clicked.GetPrevBox(); int table_firstValue = prev.GetValue() / 10; int table_secondValue = prev.GetValue() % 10; int value_free = -1; if (clicked_firstValue == clicked_secondValue) { value_free = clicked_secondValue; } else { if (clicked_firstValue == table_firstValue || clicked_firstValue == table_secondValue) { value_free = clicked_secondValue; } else if (clicked_secondValue == table_firstValue || clicked_secondValue == table_secondValue) { value_free = clicked_firstValue; } } int hand_firstValue = ficha_Click.GetValue() / 10; int hand_secondValue = ficha_Click.GetValue() % 10; if (hand_firstValue != value_free & hand_secondValue != value_free) { MessageBox.Show("No es posible colocar la ficha (" + hand_firstValue + "|" + hand_secondValue + ") al lado de la ficha (" + clicked_firstValue + "|" + clicked_secondValue + ")."); return(999); } else if (hand_firstValue == value_free) { selector = 1; } else if (hand_secondValue == value_free) { selector = 2; } this.pieceBoxes[rightIndex].GetBox().MouseClick -= new MouseEventHandler(ClickEnFichaMesa); rightIndex++; usedIndex = rightIndex; Destination = this.pieceBoxes[rightIndex]; Destination.GetBox().Image = this.imageListPieces.Images[picturePostion]; GirarFicha(Destination.GetBox().Image, usedIndex, selector); return(usedIndex); }
private void PonerLaFichaYEnviarAServidor(int selector, int usedIndex, PieceBox Destination) { Destination.GetBox().MouseClick += new MouseEventHandler(ClickEnFichaMesa); Destination.SetValue(ficha_Click.GetValue()); ficha_Click.GetBox().MouseClick -= new MouseEventHandler(ClickEnFichaJugador); ficha_Click.GetBox().BorderStyle = BorderStyle.None; ficha_Click.GetBox().Visible = false; DecrementPlayerAvailablepPieces(this.myposition); PieceData data = new PieceData(); data.jugador = this.myposition; data.valor = Destination.GetValue(); data.posicionEnMano = (int)Char.GetNumericValue(ficha_Click.GetBox().Name.ToCharArray()[ficha_Click.GetBox().Name.ToCharArray().Length - 1]); data.selector = selector; data.index = usedIndex; control.envia.RequestPutPiece(data); ficha_Click = null; }
private void ClickEnFichaJugador(object sender, EventArgs e) { if (ficha_Click != null) { ficha_Click.GetBox().BorderStyle = BorderStyle.None; } if (this.tengoTurno == false) { return; } PieceBox[] Aux = null; PictureBox Clicked = (sender as PictureBox); switch (this.myposition) { case 0: Aux = this.pieceBoxesPlayer1; break; case 1: Aux = this.pieceBoxesPlayer2; break; case 2: Aux = this.pieceBoxesPlayer3; break; case 3: Aux = this.pieceBoxesPlayer4; break; } foreach (PieceBox piece in Aux) { if (Clicked.Name.Equals(piece.GetBox().Name)) { this.ficha_Click = piece; this.ficha_Click.GetBox().BorderStyle = BorderStyle.Fixed3D; break; } } //esto de momento tamopc vale para naad }
private void CreatePieceBoxes() { for (int j = 0; j < 55; j++) { pieceBoxes[j] = new PieceBox(-1, (this.pnlTable.Controls.Find("pictureBoxPiece" + j, false)[0]) as PictureBox); } for (int j = 0; j < 55; j++) { if (j == 0) { pieceBoxes[j].SetNextBox(pieceBoxes[j + 1]); } if (j == 54) { pieceBoxes[j].SetPrevBox(pieceBoxes[j - 1]); } if (j > 0 && j < 54) { pieceBoxes[j].SetPrevBox(pieceBoxes[j - 1]); pieceBoxes[j].SetNextBox(pieceBoxes[j + 1]); } } }
public void SetNextBox(PieceBox piece) { this.next = piece; }
public void SetPrevBox(PieceBox piece) { this.prev = piece; }