Esempio n. 1
0
        private void Button_Click(object sender, EventArgs e)
        {
            int speed = 4, initialWidth = ((Button)sender).Width;

            int x = Convert.ToInt32(((Button)sender).Name[3].ToString()),
                y = Convert.ToInt32(((Button)sender).Name[4].ToString());

            int cardValue = board.getValue(x, y);

            if (buttonArray[0] == null)
            {
                buttonArray[0] = ((Button)sender);
                button_flip(sender, e, ref buttonArray[0], speed, buttonArray[0].Width, x, y);
                card1Value = board.getValue(x, y);
            }
            else if (buttonArray[1] == null)
            {
                buttonArray[1] = ((Button)sender);
                button_flip(sender, e, ref buttonArray[1], speed, buttonArray[1].Width, x, y);

                if (card1Value == board.getValue(x, y))
                {
                    String st = Directory.GetCurrentDirectory();
                    st = st.Substring(0, st.IndexOf("\\bin\\"));
                    SoundPlayer file = new SoundPlayer(st + "\\Resources\\card_remove.wav");
                    file.Play();

                    playerList.incrementPlayerScore();

                    if (!playerList.getNextPlayer().Equals(playerList.getCurrentPlayer()))
                    {
                        MessageBox.Show(playerList.getCurrentPlayer().getPlayerName() + " has scored 1 point!\n");
                    }
                    else
                    {
                        MessageBox.Show("It's a match.");
                    }

                    queueUpdate();

                    for (int i = 0; i < 2; i++)
                    {
                        Button_flip(buttonArray[i], e, buttonArray[i].Width, ref buttonArray[i], speed, initialWidth);

                        buttonArray[i].Visible = false;
                        buttonArray[i]         = null;
                    }

                    //playerList.getNextPlayer();

                    if (board.MatchFoundIsGameOver())
                    {
                        if (!playerList.getNextPlayer().Equals(playerList.getCurrentPlayer()))
                        { //check if not one player game
                            Winner getWinner = new Winner(playerList);
                            getWinner.determineWinner();
                            MessageBox.Show("Thanks for playing! Here is a list of everyone's scores!\n" +
                                            playerList.printAll(true), "Scores");
                        }
                        else
                        {
                            MessageBox.Show("Have fun playing solo?");
                        }

                        switch (MessageBox.Show(this, "Do you want to play another game", "Closing", MessageBoxButtons.YesNo))
                        {
                        case DialogResult.No:
                            form.Close();
                            break;

                        default:
                            Close();
                            break;
                        }
                    }
                    else
                    {
                        if (!playerList.getNextPlayer().Equals(playerList.getCurrentPlayer())) //check if not one player game
                        {
                            MessageBox.Show(playerList.getPlayerName() + " gets to go again.");
                        }
                    }
                }
                else
                {
                    MessageBox.Show("No match.", "Scores");

                    for (int i = 0; i < 2; i++)
                    {
                        Button_flip(buttonArray[i], e, buttonArray[i].Width, ref buttonArray[i], speed, initialWidth);
                        buttonArray[i].BackgroundImage = WindowsFormsApplication2.Properties.Resources.cardbackred;
                        Button_flip(buttonArray[i], e, buttonArray[i].Width, ref buttonArray[i], -speed, initialWidth);

                        buttonArray[i].Enabled = true;
                        buttonArray[i]         = null;
                    }

                    playerList.setNextPlayer();
                    queueUpdate();
                }
            }
        }