From 5c1454c0460efebb78d57ea7bec39e130c2f50c2 Mon Sep 17 00:00:00 2001 From: Sverre Rabbelier Date: Sat, 26 Jan 2008 19:36:57 +0100 Subject: [PATCH] Added comments and handling of selecting a card --- 4DMemory/Playground.cs | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/4DMemory/Playground.cs b/4DMemory/Playground.cs index 4227a6e..8cde8f1 100644 --- a/4DMemory/Playground.cs +++ b/4DMemory/Playground.cs @@ -9,8 +9,10 @@ namespace Memory class Playground { private PlayerIndex m_currentPlayer; - private bool m_isFirstCardOfPair; + private Card m_currentCard; + private CardsGrid m_cardsGrid; + private Random m_random; private static int m_dimension = 10; @@ -20,7 +22,7 @@ namespace Memory public Playground() { m_currentPlayer = PlayerIndex.One; - m_isFirstCardOfPair = true; + m_currentCard = null; m_random = new Random(); FillField(); @@ -40,18 +42,40 @@ namespace Memory // The player that gets to select a card next public PlayerIndex SelectCard(int xpos, int ypos, int zpos) { - if (m_isFirstCardOfPair) + Card pickedCard = m_cardsGrid.getCard(xpos, ypos, zpos); + + if (m_currentCard == null) { + m_currentCard = pickedCard; return m_currentPlayer; } else { - int player = (int)m_currentPlayer; - int nextplayer = (player % 4) + 1; - m_currentPlayer = (PlayerIndex)nextplayer; - return m_currentPlayer; + if (m_currentCard.Equals(pickedCard)) + { + // !! Player selected the correct card + return m_currentPlayer; + } + else + { + // !! Player selected the wrong card + return GetNextPlayer(); + } } } + + // Summary: + // Finds the next player and returns it + // + // Returns: + // The next player + private PlayerIndex GetNextPlayer() + { + int player = (int)m_currentPlayer; + int nextplayer = (player % 4) + 1; + m_currentPlayer = (PlayerIndex)nextplayer; + return m_currentPlayer; + } // Summary: // Initializes all the cards -- 2.11.4.GIT