连接4 C#切换播放器转动问题 [英] Connect 4 C# switching player turns problem

查看:54
本文介绍了连接4 C#切换播放器转动问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,对于一个学校项目,我正在制作一个连线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 declare playerNo as a local variable in slotArray_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 into SwapPlayer(..) so any change being done to it doesn't reflect to playerNo in slotArray_DragDrop(..)...


这篇关于连接4 C#切换播放器转动问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆