2013-02-14 28 views
-4

我正在尝试让Simon为Windoes Phone 8创建一个游戏,并且我撞上了墙并找不到错在什么地方......我非常感谢一些帮助。A已经定义了一个名为B的成员具有相同的参数 - 卡住

问题在于“continueGame”和“initializeColorSequence”参数。

干杯。

{ 
namespace SimonSez 
{ 
    public sealed partial class MainPage : PhoneApplicationPage 
    { 

     #region Variables 
     //Variables 
     const int colours_amount = 4; 
     const int colour1 = 1; 
     const int colour2 = 2; 
     const int colour3 = 3; 
     const int colour4= 4; 
     const int max_seq_count = 100; // TODO: Make 100 for release version 
     const String startgame_click = "Click to begin!"; 
     const String win = "YOU WIN!"; 

     int currentLengthOfSequence = 0; 

     Random randomNumber; 
     int[] correctColorSequence; 
     int[] playerColorSequence; 
     int correctColorSequenceIndex = 0; 
     int playerColorSequenceIndex = 0; 

     Boolean isPlayerTurn = true; 
     Boolean isSequenceCorrect = false; 
     Boolean isGameStarted = false; 
     Boolean isDoingAnimation = false; 

     long timeStart, timeEnd, timeDifference; 
     #endregion 

     // Constructor 
     public MainPage() 
     { 
      this.InitializeComponent(); 

      randomNumber = new Random(); 

      correctColorSequence = new int[max_seq_count]; 
      playerColorSequence = new int[max_seq_count]; 
      initializeColorSequence(); 

      textBlockRoundNumber.Opacity = 0; 

      // Sample code to localize the ApplicationBar 
      //BuildLocalizedApplicationBar(); 
     } 

     private void startGame() 
     { 
      currentLengthOfSequence = 0; 
      //textBlockCenter.Text = "Round " + roundNumber; 
      textBlockRoundNumber.Text = currentLengthOfSequence.ToString(); 
      textBlockRoundNumber.Foreground = new SolidColorBrush(Colors.White); 
      textBlockRoundNumber.Opacity = 100; 
      textBlockStartGame.Opacity = 0; 
      isGameStarted = true; 
      playerColorSequenceIndex = 0; 
      initializeColorSequence(); 
      isPlayerTurn = false; 
      continueGame(); 
     } 
     private void continueGame() 
     { 
      isSequenceCorrect = true; 
      for (int i = 0; i < playerColorSequenceIndex; i++) 
      { 
       if (correctColorSequence[i] == playerColorSequence[i]) 
       { 
        // do nothing 
       } 
       else 
       { 
        isSequenceCorrect = false; 
        break; 
       } 
      } 
     } 
       private void initializeColorSequence() 
     { 
      for (int i = 0; i < max_seq_count; i++) 
      { 
       correctColorSequence[i] = randomNumber.Next(1, colours_amount); 
       playerColorSequence[i] = 0; 
      } 
     } 

       #region Grip Tapping 
       private void Rect1_Tap(object sender, GestureEventArgs e) 
       { 
        if (isPlayerTurn) 
        { 
         //storyboardRectangle0Player.Begin(); 
         //audioPiano12.Volume = 0.5; 
         //audioPiano12.Play(); 

         if (isGameStarted) 
         { 
          playerColorSequence[playerColorSequenceIndex++] = colour1; 
          isPlayerTurn = false; 
          continueGame(); 
         } 
        } 
       } 
       private void Rect2_Tap(object sender, GestureEventArgs e) 
       { 
        if (isPlayerTurn) 
        { 
         //storyboardRectangle1Player.Begin(); 
         //audioPiano12.Volume = 0.5; 
         //audioPiano12.Play(); 

         if (isGameStarted) 
         { 
          playerColorSequence[playerColorSequenceIndex++] = colour2; 
          isPlayerTurn = false; 
          continueGame(); 
         } 
        } 
       } 
       private void Rect3_Tap(object sender, GestureEventArgs e) 
       { 
        if (isPlayerTurn) 
        { 
         //storyboardRectangle2Player.Begin(); 
         //audioPiano12.Volume = 0.5; 
         //audioPiano12.Play(); 

         if (isGameStarted) 
         { 
          playerColorSequence[playerColorSequenceIndex++] = colour3; 
          isPlayerTurn = false; 
          continueGame(); 
         } 
        } 
       } 
       private void Rect4_Tap(object sender, GestureEventArgs e) 
       { 
        if (isPlayerTurn) 
        { 
         //storyboardRectangle3Player.Begin(); 
         //audioPiano12.Volume = 0.5; 
         //audioPiano12.Play(); 

         if (isGameStarted) 
         { 
          playerColorSequence[playerColorSequenceIndex++] = colour4; 
          isPlayerTurn = false; 
          continueGame(); 
         } 
        } 
       } 
       private void StartGame_Tap(object sender, GestureEventArgs e) 
       { 
        if (textBlockStartGame.Text.Equals(startgame_click)) 
        { 
         if (textBlockStartGame.Opacity != 0) 
         { 
          startGame(); 
         } 
        } 
        else if (textBlockStartGame.Text.Equals(win)) 
        { 
         endGame(startgame_click); 
        } 
        else 
        { 
         // Do nothing 
        } 
       } 

       #endregion 

       private void continueGame() 
       { 
        isSequenceCorrect = true; 
        for (int i = 0; i < playerColorSequenceIndex; i++) 
        { 
         if (correctColorSequence[i] == playerColorSequence[i]) 
         { 
          // do nothing 
         } 
         else 
         { 
          isSequenceCorrect = false; 
          break; 
         } 
        } 

        if (isSequenceCorrect) 
        { 
         if (playerColorSequenceIndex >= currentLengthOfSequence) 
         { 
          currentLengthOfSequence++; 
          if (currentLengthOfSequence < max_seq_count) 
          { 
           //audioShinyDing.Volume = 0.5; 
           //audioShinyDing.Play(); 
           textBlockRoundNumber.Text = currentLengthOfSequence.ToString(); 
          } 
          else // roundNumber == MAX_SEQUENCE_COUNT 
          { 
          // audioApplause.Volume = 0.5; 
           //audioApplause.Play(); 
           endGame(win); 
          } 
         } 
         else // playerColorSequenceIndex < roundNumber 
         { 
          //playerColorSequenceIndex++; 
          isPlayerTurn = true; 
         } 
        } 
        else // isSquenceCorrect == false 
        { 
         endGame(startGame); 
        } 
       } 
       private void endGame(String endGameMessage) 
       { 
        isGameStarted = false; 
        textBlockStartGame.Text = endGameMessage; 
        textBlockStartGame.Opacity = 100; 
        textBlockRoundNumber.Foreground = new SolidColorBrush(Colors.Gray); 
        textBlockRoundNumber.Opacity = 40; 
        isPlayerTurn = true; 
       } 

       #region Helper Functions 

       private void initializeColorSequence() 
       { 
        for (int i = 0; i < max_seq_count; i++) 
        { 
         correctColorSequence[i] = randomNumber.Next(1, colours_amount); 
         playerColorSequence[i] = 0; 
        } 
       } 

       private void waitMilliseconds(int waitTime) // Not used 
       { 
        timeStart = DateTime.Now.Ticks; 

        long totalWaitTimeInTicks = waitTime * 10000; 

        do 
        { 
         timeEnd = DateTime.Now.Ticks; 
         timeDifference = timeEnd - timeStart; 
        } 
        while (timeDifference < totalWaitTimeInTicks); 
       } 

       #endregion 


    } 
} 
} 
+0

FWIW:双击错误列表中的编译器错误会将您带到确切的重复。 – 2013-02-14 01:11:47

回答

3

你似乎有两个功能称为“continueGame”以及两个“initializeColorSequence”,因此为什么它说的成员已定义。

+0

哦,所以我有。我一定很累,我没有注意到,对不起:/ – 2013-02-14 01:10:47

1

您似乎已经在您提供的代码中定义了两次这两种方法。

相关问题