Exemplo n.º 1
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            PlayerTurn.Content = "Red Player's turn";
            Color color = (Color)ColorConverter.ConvertFromString("#FF930707");

            PlayerTurn.Foreground = new System.Windows.Media.SolidColorBrush(color);
            PlayerTurn.Visibility = System.Windows.Visibility.Visible;

            /*MainWindowViewModel vm = new MainWindowViewModel();
             * DataContext = vm;
             * List<List<Piesa>> list = (DataContext as MainWindowViewModel).Tabla;
             * Data = 0;*/
            Turn = 0;
            LoadGameViewModel vm = new LoadGameViewModel();

            DataContext = vm;
            List <List <Piesa> > list = (DataContext as LoadGameViewModel).Tabla;

            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    if (i % 2 != j % 2)
                    {
                        if (i < 3)
                        {
                            list[i][j] = new Piesa()
                            {
                                PiesaImg = @"/Images/piesa1.png", X = i, Y = j, Background = @"/Images/back8.png", Player = "Player1", Tip = "piesa"
                            }
                        }
                    }
                    ;
Exemplo n.º 2
0
        public MainWindow()
        {
            InitializeComponent();

            /*MainWindowViewModel vm = new MainWindowViewModel();
             * DataContext = vm;*/
            LoadGameViewModel vm = new LoadGameViewModel();

            DataContext = vm;
            Previous    = null;

            PlayerTurn.Content = "Red Player's turn";
            Color color = (Color)ColorConverter.ConvertFromString("#FF930707");

            PlayerTurn.Foreground = new System.Windows.Media.SolidColorBrush(color);
            PlayerTurn.Visibility = System.Windows.Visibility.Visible;

            Player1S.Text = Player1Score.ToString();
            Player2S.Text = Player2Score.ToString();
        }
Exemplo n.º 3
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            List <List <Piesa> > list;

            /*if(Data==0)
             *  list = (DataContext as MainWindowViewModel).Tabla;
             * else*/
            list = (DataContext as LoadGameViewModel).Tabla;

            if (Turn % 2 == 0)
            {
                if (Previous == null)
                {
                    Piesa aux = (Piesa)((Button)sender).DataContext;
                    if (aux.PiesaImg == null || aux.Player.Equals("Player2"))
                    {
                        return;
                    }
                    else
                    {
                        Previous = (Piesa)((Button)sender).DataContext;
                    }
                }
                else
                {
                    Piesa Curent = (Piesa)((Button)sender).DataContext;

                    if (Curent.X % 2 == Curent.Y % 2)
                    {
                        Curent = null;
                        return;
                    }

                    if (Curent.X == Previous.X && Curent.Y == Previous.Y && ok == 0)
                    {
                        Previous = null;
                    }
                    else
                    {
                        if (Curent.Player != null)
                        {
                            if (Curent.X % 2 == Curent.Y % 2 || Curent.Player.Equals("Player1"))
                            {
                                Curent = null;
                                return;
                            }
                        }
                        else
                        {
                            if (Previous.Tip.Equals("piesa"))
                            {
                                Previous = MV.MovesPlayer1(Previous, Curent, list);
                            }
                            else
                            if (Previous.Tip.Equals("rege"))
                            {
                                Previous = MV.King1(Previous, Curent, list);
                            }

                            if (Previous == null)
                            {
                                Turn++;
                                PlayerTurn.Content = "Blue Player's turn";
                                Color color = (Color)ColorConverter.ConvertFromString("#FF031D49");
                                PlayerTurn.Foreground = new System.Windows.Media.SolidColorBrush(color);
                                PlayerTurn.Visibility = System.Windows.Visibility.Visible;

                                if (MV.End(list, "Player2"))
                                {
                                    PlayerTurn.Content = "Red Player WINS";
                                    color = (Color)ColorConverter.ConvertFromString("#FF930707");
                                    PlayerTurn.Foreground = new System.Windows.Media.SolidColorBrush(color);
                                    PlayerTurn.Visibility = System.Windows.Visibility.Visible;
                                    Player1Score++;
                                    Player1S.Text = Player1Score.ToString();
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                if (Turn % 2 == 1)
                {
                    if (Previous == null)
                    {
                        Piesa aux = (Piesa)((Button)sender).DataContext;
                        if (aux.PiesaImg == null || aux.Player.Equals("Player1"))
                        {
                            return;
                        }
                        else
                        {
                            Previous = (Piesa)((Button)sender).DataContext;
                        }
                    }
                    else
                    {
                        Piesa Curent = (Piesa)((Button)sender).DataContext;

                        if (Curent.X % 2 == Curent.Y % 2)
                        {
                            Curent = null;
                            return;
                        }

                        if (Curent.X == Previous.X && Curent.Y == Previous.Y && ok == 0)
                        {
                            Previous = null;
                        }
                        else
                        {
                            if (Curent.Player != null)
                            {
                                if (Curent.X % 2 == Curent.Y % 2 || Curent.Player.Equals("Player2"))
                                {
                                    Curent = null;
                                    return;
                                }
                            }
                            else
                            {
                                if (Previous.Tip.Equals("piesa"))
                                {
                                    Previous = MV.MovesPlayer2(Previous, Curent, list);
                                }
                                else
                                if (Previous.Tip.Equals("rege"))
                                {
                                    Previous = MV.King2(Previous, Curent, list);
                                }


                                if (Previous == null)
                                {
                                    Turn++;
                                    PlayerTurn.Content = "Red Player's turn";
                                    Color color = (Color)ColorConverter.ConvertFromString("#FF930707");
                                    PlayerTurn.Foreground = new System.Windows.Media.SolidColorBrush(color);
                                    PlayerTurn.Visibility = System.Windows.Visibility.Visible;

                                    if (MV.End(list, "Player1"))
                                    {
                                        PlayerTurn.Content = "Blue Player WINS";
                                        color = (Color)ColorConverter.ConvertFromString("#FF031D49");
                                        PlayerTurn.Foreground = new System.Windows.Media.SolidColorBrush(color);
                                        PlayerTurn.Visibility = System.Windows.Visibility.Visible;
                                        Player2Score++;
                                        Player2S.Text = Player2Score.ToString();
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }