-5

我正在尝试为 Windoes Phone 8 制作 Simon Says 游戏,但我碰壁了,无法弄清楚出了什么问题……我非常感谢一些帮助。

问题在于“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


    }
}
}
4

2 回答 2

3

您似乎有两个名为“continueGame”的函数和两个“initializeColorSequence”,因此它说已经定义了一个成员。

于 2013-02-14T00:56:44.593 回答
1

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

于 2013-02-14T00:58:48.790 回答