错误说我不使用我输入的东西c#

时间:2013-03-13 04:07:04

标签: c# boolean

嗨,我正在尝试制作一个tic tac toe游戏。互联网上有很多代码和灵感,但我需要以某种方式制作它,似乎没有多少人使用这种方式,而且我遇到了麻烦。我需要使用数组,然后说我的x = 10和我的y = 1,每当我得到30或3的总和,我就会知道其中哪一个赢了。

  1. 但是在胜利者检查的方法中说有一个错误的东西是预期得到或设定的交易者,我不知道那是什么?

  2. 除了它一直警告我,我已经将x定义为1而o为10,而我的播放器2并且从不使用该命令

  3. 我不知道我怎么能这样做,就像我说的总结数字一样?

  4. 这是我的代码

    namespace tictactoe
    {
        public partial class Form1 : Form
        { 
             bool player1 = true;
             bool player2 = false; 
             int x=1;
             int o=10;
    
            public Form1()
            {
                InitializeComponent();
                value();
            }
    
            private string[] status;
    
            private void value()
    
    
            { 
    
    
    
                int[] status = new int[9];
                myarrays();
    
            }
    
    
            private void myarrays()
    
            {  
                button1.Text = status[0];
                button2.Text = status[1];
                button3.Text = status[2];
                button4.Text = status[3];
                button5.Text = status[4];
                button6.Text = status[5]; 
                button7.Text = status[6];
                button8.Text = status[7];
                button9.Text = status[8];
    
            }
    
    
    
    
            private void label1_Click(object sender, EventArgs e)
            {
    
    
            }
            private void Form1_Load(object sender, EventArgs e)
            { 
            }
    
    
    
    
    
            private void button1_Click(object sender, EventArgs e)
            {
                if (player1 == true)
                {
                    player1 = true;
                    button1.Text = "X";
                    player1 = false;
                }
                else
                {
                    player2 = true;
                    button1.Text = "O";
                    player2 = false;
                    player1 = true;
                }
            }
    
            private void textBox1_TextChanged(object sender, EventArgs e)
            {
    
            }
    
            private void button2_Click(object sender, EventArgs e)
            {
                if (player1 == true)
                {
                    player1 = true;
                    button2.Text = "X";
                    player1 = false;
                }
                else
                {
                    player2 = true;
                    button2.Text = "O";
                    player2 = false;
                    player1 = true;
                }
    
            }
    
            private void button3_Click(object sender, EventArgs e)
            {
                if (player1 == true)
                {
                     player1 = true;
                    button2.Text = "X";
                    player1 = false;
                }
                else
                {
                    player2 = true;
                    button2.Text = "O";
                    player2 = false;
                    player1 = true;
                }
            }
    
            private void button4_Click(object sender, EventArgs e)
            {
                if (player1 == true)
                {
                     player1 = true;
                    button2.Text = "X";
                    player1 = false;
                }
                else
                {
                    player2 = true;
                    button2.Text = "O";
                    player2 = false;
                    player1 = true;
            }
    
            private void button5_Click(object sender, EventArgs e)
            {
                if (player1 == true)
                {
                     player1 = true;
                    button2.Text = "X";
                    player1 = false;
                }
                else
                {
                    player2 = true;
                    button2.Text = "O";
                    player2 = false;
                    player1 = true;            }
            }
    
            private void button6_Click(object sender, EventArgs e)
            {
                if (player1 == true)
                {
                     player1 = true;
                    button2.Text = "X";
                    player1 = false;
                }
                else
                {
                    player2 = true;
                    button2.Text = "O";
                    player2 = false;
                    player1 = true;            }
            }
    
            private void button7_Click(object sender, EventArgs e)
            {
                if (player1 == true)
                {
                     player1 = true;
                    button2.Text = "X";
                    player1 = false;
                }
                else
                {
                    player2 = true;
                    button2.Text = "O";
                    player2 = false;
                    player1 = true;            }
            }
    
            private void button8_Click(object sender, EventArgs e)
            {
                if (player1 == true)
                {
                     player1 = true;
                    button2.Text = "X";
                    player1 = false;
                }
                else
                {
                    player2 = true;
                    button2.Text = "O";
                    player2 = false;
                    player1 = true;            }
            }
    
            private void button9_Click(object sender, EventArgs e)
            {
                if (førstespiller == true)
                {
                    if (player1 == true)
                {
                     player1 = true;
                    button2.Text = "X";
                    player1 = false;
                }
                else
                {
                    player2 = true;
                    button2.Text = "O";
                    player2 = false;
                    player1 = true;
                }
            }
    
    
            private void checkwinner 
            {
            if (button1.Text =="X" & button2.Text =="X" & button3.Text= ="x")
                MessageBox.Show
                MessageBox.Show
    
    
            }
    
    
            private void button10Newgame_Click(object sender, EventArgs e)
            {
    
                button1.Text = "";
                button2.Text = "";
                button3.Text = "";
                button4.Text = "";
                button5.Text = "";
                button6.Text = "";
                button7.Text = "";
                button8.Text = "";
                button9.Text = "";
                player1 = true;
                player2 = false;
            }
    
    
    
    
            }
    
    }
    

3 个答案:

答案 0 :(得分:2)

private void checkwinner

需要private void checkwinner()

答案 1 :(得分:0)

您的代码存在许多问题,但我认为您在标题中引用的警告与此行有关:

int[] status = new int[9];

您正在创建一个新变量但从未实际使用它,status内的value变量仅存在于该方法的范围内。虽然status中的myarrays变量引用了成员字段string[] status

答案 2 :(得分:0)

仅针对您的第一个问题 -

MessageBox.Show

应该是 -

MessageBox.Show("you won!");