井字阵列 [英] Tic Tac Toe array

查看:103
本文介绍了井字阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中,我有一个井字游戏,我要检查,如果玩家获得了结果的方法,丢失,或者它是一个平局。我在与code检查的问题,如果它是一个平局。所以现在我有这个。我想它所以如果有任何元素的空间,本场比赛是不是一场平局,并继续上。当我运行code会随机说,它甚至在比赛还没有结束领带。

 布尔平局= TRUE;
        对于(INT行= 0;&行LT; matrix.GetLength(0);排++)
        {
            对(INT COL = 0; COL&下; matrix.GetLength(1);山口++)
            {
                如果(矩阵[行,列] =='')
                {
                    布尔画= FALSE;
                }
            }
        }
        如果(画)
        {
            回归'D'; //返回D代表平局
        }


解决方案

您没有设置变量平局,但在内部范围宣布了新的变数。

In C#, I have a tic tac toe game in which I have a method to check the outcome of if the player won, lost, or it was a tie. I'm having a problem with the code checking if it's a tie. So right now I have this. And I want it so if there is a space in any of the elements the game is not a draw and continues on. When I run the code it would randomly say its a tie even when the game isn't finished yet.

        bool draw = true;
        for (int row = 0; row < matrix.GetLength(0); row++)
        {
            for (int col = 0; col < matrix.GetLength(1); col++)
            {
                if (matrix[row, col] == ' ')
                {
                    bool draw = false;
                }
            }
        }
        if (draw)
        {
            return 'D'; //return D for draw
        }

解决方案

You aren't setting the variable draw, but declaring a new variable in the inner scope.

这篇关于井字阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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