连接4 C#切换播放器转动问题 [英] Connect 4 C# switching player turns problem
问题描述
大家好,对于一个学校项目,我正在制作一个连线4游戏,2个玩家可以玩。然而,我被困在如何切换每个玩家的回合。我使用了一个变量int PlayerNo,它可以是1或2(玩家1或玩家2),并且更改此值可确定绿色计数器(2)还是红色计数器(1)是否会下降。我需要知道如何在每个回合中交替使用该值,以下是使用该变量的所有代码。我的代码在某一刻非常混乱所以请原谅我,如果你需要澄清什么,请问我。
我尝试过:
私人 void SwapPlayer( int playerNumber)
{
if (playerNumber == 1 )
{
playerNumber = 2 ;
}
其他 if (playerNumber == 2 )
{
playerNumber = 1 ;
}
}
您声明playerNo
作为slotArray_DragDrop(..)
中的 local 变量。方法完成后,它会被遗忘,下次再次初始化为1 ...
并将其作为值参数传递进入SwapPlayer(..)
所以对它进行的任何更改都不会反映在<$ c中playerNo
$ C> slotArray_DragDrop(..) ...
Hello everyone for a school project I am making a connect 4 game were 2 players can play. I am stuck however on how to switch each player's turn. I have used a variable int PlayerNo that can either be 1 or 2 (player 1 or player 2) and changing this value determines whether a green counter (2) or a red counter (1) drop down the board. I need to know how to alternate this value every turn and below is all the code where the variable is used. My code is quite messy at the minute so please forgive me and if you need clarification on anything please ask me.
What I have tried:
private void SwapPlayer(int playerNumber)
{
if (playerNumber == 1)
{
playerNumber = 2;
}
else if (playerNumber == 2)
{
playerNumber = 1;
}
}
You declareplayerNo
as a local variable inslotArray_DragDrop(..)
. When the method is done, it's forgotten and the next time it's initialized with 1 again...
And you pass it as a value parameter intoSwapPlayer(..)
so any change being done to it doesn't reflect toplayerNo
inslotArray_DragDrop(..)
...
这篇关于连接4 C#切换播放器转动问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!