C# A已经使用相同的参数定义了名为B的成员-stuck
我正试图为Windoes Phone 8制作一个Simon Says游戏,但我遇到了麻烦,弄不清出了什么问题。。。我非常感谢你的帮助 问题在于“continueGame”和“initializeColorSequence”参数 干杯C# A已经使用相同的参数定义了名为B的成员-stuck,c#,windows,windows-phone-8,C#,Windows,Windows Phone 8,我正试图为Windoes Phone 8制作一个Simon Says游戏,但我遇到了麻烦,弄不清出了什么问题。。。我非常感谢你的帮助 问题在于“continueGame”和“initializeColorSequence”参数 干杯 { namespace SimonSez { public sealed partial class MainPage : PhoneApplicationPage { #region Variables //Var
{
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
}
}
}
{
名称空间SimonSez
{
公共密封部分类主页面:PhoneApplicationPage
{
#区域变量
//变数
const int colors_amount=4;
常数int color1=1;
常数int color2=2;
常数int color3=3;
常数int color4=4;
const int max_seq_count=100;//TODO:发布版本为100
常量字符串startgame_click=“单击开始!”;
const String win=“你赢了!”;
int currentLengthOfSequence=0;
随机数;
int[]颜色序列;
int[]playerColor序列;
int correctColorSequenceIndex=0;
int playerColorSequenceIndex=0;
布尔值isPlayerTurn=true;
布尔值isSequenceCorrect=false;
布尔值isGameStarted=false;
布尔值IsDoInganization=false;
长时间启动、时间结束、时差;
#端区
//建造师
公共主页()
{
this.InitializeComponent();
随机数=新随机数();
correctColorSequence=新整数[最大顺序计数];
playerColorSequence=新整数[最大顺序计数];
初始化颜色序列();
textBlockRoundNumber.Opacity=0;
//本地化ApplicationBar的示例代码
//BuildLocalizedApplicationBar();
}
私有void startGame()
{
currentLengthOfSequence=0;
//Text blockcenter.Text=“Round”+roundNumber;
textBlockRoundNumber.Text=currentLengthOfSequence.ToString();
textBlockRoundNumber.前台=新的SolidColorBrush(Colors.White);
textBlockRoundNumber.Opacity=100;
textBlockStartGame.Opacity=0;
isGameStarted=true;
playerColorSequenceIndex=0;
初始化颜色序列();
isPlayerTurn=false;
continueGame();
}
私有void continueGame()
{
isSequenceCorrect=真;
对于(int i=0;i