示例#1
0
 /// <summary>
 /// Mostrar la ventana de fin de partida
 /// </summary>
 /// <param name="nomPlayer"></param>
 private void showVictoryWin(String nomPlayer,Motor.FOUR_CONNECT type)
 {
     try
     {
         String text;
         String caption;
         if (type != Motor.FOUR_CONNECT.NULL)
         {
             text = String.Format("¡¡Enhorabuena {0}!!", nomPlayer);
             caption = "Victoria";
         }
         else
         {
             text = "¡¡Partida en tablas!!";
             caption = "Empate";
         }
         MessageBoxResult victoryWin = MessageBox.Show(text + "\n¿quieres jugar una partida con el mismojugador?", caption, MessageBoxButton.YesNo);
         switch (victoryWin)
         {
             case (MessageBoxResult.Yes):
                 {
                     motor.mode = Motor.MODE.OFF;
                     buildBoard();
                     motor.run();
                     break;
                 }
             default:
                 {
                     changeFlag();//para poder iniciar una nueva partida
                     motor.mode = Motor.MODE.OFF;
                     confi.resetConfi();//reseteamos la configuracion a los valores por defecto
                     break;
                 }
         }
     }
     catch (Exception ex)
     {
         Debugger.WriteException(ex, this);
     }
 }
示例#2
0
 /// <summary>
 /// Iniciar una nueva partida. Abre la ventana NewGameWinModal
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void newGame(object sender, ExecutedRoutedEventArgs e)
 {
     try
     {
         NewGameWinModal newGame = new NewGameWinModal();
         //pasar los parametros
         newGame.Owner = this;
         newGame.Oponent = confi.pcOption;
         newGame.X = confi.xDim;
         newGame.Y = confi.yDim;
         newGame.Time = confi.time;
         newGame.ShowDialog();
         if (newGame.DialogResult == true)
         {
             //recibir los parametros
             confi.xDim = newGame.X;
             confi.yDim = newGame.Y;
             confi.pcOption = newGame.Oponent;
             confi.time = newGame.Time;
             confi.isTimer = newGame.TimeIsChecked;
             //mostramos la de jugadores
             PlayersWinModal playersWinModal = new PlayersWinModal();
             playersWinModal.Owner = this;                    
             //pasar parametros, pasamos los jugadores
             playersWinModal.PcOption = confi.pcOption;
             confi.DefaultGamers();//creamos los jugadores por defecto 1 ó 2
             playersWinModal.Players = confi.playerList;
             //playersWinModal.config = confi;
             playersWinModal.ShowDialog();
             if (playersWinModal.DialogResult == true)
             {
                 //recibir parametros 
                 confi.playerList = playersWinModal.Players;
                 
                 //mostramos el panel
                 this.playerOne.Content = confi.playerList[0];
                 if (confi.pcOption)//si es contra la maquina, lo creo y lo muestro
                 {
                     opponent = OPPONENT.PC;
                     this.playerTwo.Content = confi.createPC();                                 
                 }
                 else//si es contra un amigo, ya lo tengo creado por defecto, y lo muestro
                 {
                     opponent = OPPONENT.HUMAN;
                     this.playerTwo.Content = confi.playerList[1];
                 }
                 //confi.showPlayersDetail();
                 showTime(confi.isTimer);
                 this.mainDock.Visibility = Visibility.Visible;
                 buildBoard();
                 motor = new Motor(confi.xDim,confi.yDim);
                 motor.victoryEvent += new Motor.victoryDel(victoryEvent);
                 statuBar.Text = motor.version;
                 motor.run();
                 changeFlag();
             }
             else//si damos a cancelar hay que resetear los jugadores
             {
                 confi.clearPlayers();
             }
         }
     }
     catch (Exception ex)
     {
         Debugger.WriteException(ex, this);
     }
 }
示例#3
0
 /// <summary>
 /// Este metodo cambia el color de las piezas que consiguen el 4 en raya. Añade una partida ganada al jugador que la ha ganado
 /// y muesra la ventana de victoria
 /// </summary>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <param name="des"></param>
 /// <param name="type"></param>
 private void victoryEvent(int x, int y, int des, Motor.FOUR_CONNECT type)
 {
     try
     {
         if (type == Motor.FOUR_CONNECT.NULL)
         {
             confi.playerList.ElementAt(0).Ganadas += 1/2;
             confi.playerList.ElementAt(1).Ganadas += 1/2;
             showVictoryWin("", type);
         }
         else
         {
             if (type == Motor.FOUR_CONNECT.VERTICAL)
             {
                 int k = 0;
                 while (k < 4)
                 {
                     space[x + k, y].Fill = brushFillVictory;
                     space[x + k, y].Stroke = brusStrokeVictory;
                     k++;
                 }
                 //MessageBox.Show("vertical");
             }
             if (type == Motor.FOUR_CONNECT.HORIZONTAL)
             {
                 int acc = 0;
                 while (acc < 4)
                 {
                     space[x, y - (des - 1) + acc].Fill = brushFillVictory;
                     space[x, y - (des - 1) + acc].Stroke = brusStrokeVictory;
                     acc++;
                 }
                 //MessageBox.Show("horizontal");
             }
             if (type == Motor.FOUR_CONNECT.NOMAIN)
             {
                 int acc = 0;
                 while (acc < 4)
                 {
                     space[x + (des - 1) - acc, y - (des - 1) + acc].Fill = brushFillVictory;
                     space[x + (des - 1) - acc, y - (des - 1) + acc].Stroke = brusStrokeVictory;
                     acc++;
                 }
                 //MessageBox.Show("nomain");
             }
             if (type == Motor.FOUR_CONNECT.MAIN)
             {
                 int acc = 0;
                 while (acc < 4)
                 {
                     space[x - (des - 1) + acc, y - (des - 1) + acc].Fill = brushFillVictory;
                     space[x - (des - 1) + acc, y - (des - 1) + acc].Stroke = brusStrokeVictory;
                     acc++;
                 }
                 //MessageBox.Show("main");
             }
             if (Turn == 1)
             {
                 confi.playerList.ElementAt(0).Ganadas += 1;
                 showVictoryWin(confi.playerList.ElementAt(0).Nombre,type);
             }
             else
             {
                 confi.playerList.ElementAt(1).Ganadas += 1;
                 showVictoryWin(confi.playerList.ElementAt(1).Nombre,type);
             }
         }
     }
     catch (Exception ex)
     {
         Debugger.WriteException(ex, this);
     }
 }
示例#4
0
 public void test(int x, int y, int des, Motor.FOUR_CONNECT type) { }