/*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 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; }