예제 #1
0
 private void resetGame()
 {
     player1.Score = 0;
     player2.Score = 0;
     CardsPanel1.Controls.Clear();
     CardsPanel2.Controls.Clear();
     m_SongCards   = new List <BoardCard>();
     m_SingerCards = new List <BoardCard>();
     m_Pairs       = new List <BoardCard>();
     songChoice    = null;
     singerChoice  = null;
     addBoardButtons();
     run();
 }
예제 #2
0
        private void addBoardButtons()
        {
            int verticalSpaceing  = 5;
            int horizontalSpacing = 5;
            int id = 1;

            for (int i = 0; i < ROWS; i++)
            {
                for (int j = 0; j < COLUMNS; j++)
                {
                    /// Insert Song Cards into Left Panel
                    BoardCard card   = new BoardCard();
                    string    choice = chooseSong();
                    card.SetCard(choice);                                   // Insert Song names
                    card.Card.Type = eCardType.SONG;
                    card.SetLocation(new Point(i * card.BoardButton.Size.Width + horizontalSpacing, j * card.BoardButton.Size.Height + verticalSpaceing));
                    m_SongCards.Add(card);
                    CardsPanel1.Controls.Add(card.BoardButton);
                    card.ButtonWasClicked += new EventHandler(ButtonWasClicked);

                    /// Insert Singer Cards into Right Panel
                    BoardCard SingerCard = new BoardCard();
                    SingerCard.SetCard(choice);                             // Insert Song names
                    SingerCard.Card.Text = currentArtist;                   // Insert Artist names
                    SingerCard.Card.Type = eCardType.SINGER;
                    SingerCard.SetLocation(new Point(i * card.BoardButton.Size.Width + horizontalSpacing, j * card.BoardButton.Size.Height + verticalSpaceing));
                    m_SingerCards.Add(SingerCard);
                    CardsPanel2.Controls.Add(SingerCard.BoardButton);
                    SingerCard.ButtonWasClicked += new EventHandler(ButtonWasClicked);

                    // Set matching ID
                    card.Card.ID       = id;
                    SingerCard.Card.ID = card.Card.ID;
                    id++;

                    verticalSpaceing += 10;
                }
                horizontalSpacing += 10;
                verticalSpaceing   = 5;
            }
            // Shuffles cards
            shuffle();
        }
예제 #3
0
        private void shuffleAllOnce()
        {
            Random rand = new Random();

            foreach (BoardCard card in m_SongCards)
            {
                int       index    = rand.Next(0, m_SongCards.Count);
                BoardCard other    = m_SongCards[index];
                Point     location = other.BoardButton.Location;
                other.BoardButton.Location = card.BoardButton.Location;
                card.BoardButton.Location  = location;
            }

            foreach (BoardCard card in m_SingerCards)
            {
                int       index    = rand.Next(0, m_SingerCards.Count);
                BoardCard other    = m_SingerCards[index];
                Point     location = other.BoardButton.Location;
                other.BoardButton.Location = card.BoardButton.Location;
                card.BoardButton.Location  = location;
            }
        }
예제 #4
0
        /// <summary>
        ///     This method is invoked whenever a button is clicked, the sender is a BoardCard object
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ButtonWasClicked(object sender, EventArgs e)
        {
            BoardCard boardCard = sender as BoardCard;

            disablePairs();

            if (boardCard.Card.Type == eCardType.SONG)
            {
                songChoice          = boardCard;
                CardsPanel2.Enabled = true;
                CardsPanel1.Enabled = false;
                songChoice.BoardButton.BackColor = colorSelected;
            }
            else if (boardCard.Card.Type == eCardType.SINGER && songChoice != null)
            {
                singerChoice = boardCard;

                // Found a matching pair
                if (songChoice != null && singerChoice != null && songChoice.Card.ID == singerChoice.Card.ID)
                {
                    // Increase players score
                    nowPlaying.Score++;

                    // Color the matching pair of buttons with the player's color
                    Color scoringPlayerColor = (nowPlaying.Name == player1.Name) ? player1Color : player2Color;
                    songChoice.BoardButton.BackColor   = scoringPlayerColor;
                    singerChoice.BoardButton.BackColor = scoringPlayerColor;

                    // Add the matching pair to the already discovered collection
                    m_Pairs.Add(songChoice);
                    m_Pairs.Add(singerChoice);

                    // Remove the matching pair from the collection of cards left to play with
                    m_SongCards.Remove(songChoice);
                    m_SingerCards.Remove(singerChoice);
                }

                // Not a matching pair
                else
                {
                    singerChoice.BoardButton.UseVisualStyleBackColor = true;
                    singerChoice.BoardButton.BackColor = colorSelected;
                    singerChoice.BoardButton.Refresh();
                    Thread.Sleep(1500);
                    HideAll();
                    changeTurns();
                    singerChoice.BoardButton.BackColor = colorDefault;
                    songChoice.BoardButton.BackColor   = colorDefault;
                }

                songChoice          = null;
                singerChoice        = null;
                CardsPanel1.Enabled = true;
                CardsPanel2.Enabled = false;
            }

            // Detect if game has ended
            if (m_Pairs.Count >= (ROWS * COLUMNS * 2))
            {
                gameEnded();
            }

            // Update the name and score graphics of both players
            updateGraphics();
        }