3D Tic Tac Toe - back&前进(转动)按钮 [英] 3D Tic Tac Toe - back & forward (turns) buttons

查看:57
本文介绍了3D Tic Tac Toe - back&前进(转动)按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在Windows窗体中创建这个项目(Visual Studio 2013,C#)。你会建议使用哪种方法添加一个允许玩家在转弯之间自由移动的功能?



我卡在其他一些按钮的部分(比X / O-able)应该回转一次。所述按钮应该识别按下的两个最后可播放的按钮,但是这个变量在每个转弯时显然都会发生变化,我似乎无法理解如何操作。



我可以写出按钮应该做什么,而不是在哪里。



轮到我了例程:



so I'm making this project in Windows forms (Visual Studio 2013, C#). Which method would you recommend for adding a feature which would allow players to move freely between turns?

I am stuck at the part where some other button (than the X/O-able) is supposed to go one turn back. Said button should identify the two last playable buttons pressed, but this variable changes obviously each turn and I can't seem to get a hang on how to do it.

I can write what the button is supposed to do, just not where.

here's my turn routine:

public partial class Form1 : Form
    {
        double q = 0;
        bool turn = true; //true = X turn, false = Y turn
        int turn_count = 0;
        
        public Form1()
        {
            InitializeComponent();
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        public void button_click(object sender, EventArgs e)
        {
            Button b = (Button)sender;
            if (turn)
                b.Text = "X";
            else
                b.Text = "O";

            b.Enabled = false;
            turn_count++;

            turn = !turn;

            CheckForWinner();
            
        }





我在这里花了很多时间进行个人研究,youtube,谷歌一般但是它似乎没有人试图解释这一点,或者我无法识别它,因为我刚刚开始编程作为一种爱好。我确信没有人发布有关按钮识别和TTT组合的问题。感谢帮助! : - )



I have spent plenty of hours in individual research in here, youtube, google generally but it seems noone has tried to explain this, or I couldn't identify it because I have just started programming as a hobby. I am sure though that noone posted question concerning button-identifying and TTT combined. Thanks for help! :-)

推荐答案

好的,如果我正确理解了这个问题,你基本上想要创建一个Un-DO按钮,它会带你回到之前最后一步?



创建另一个存储每个动作的部分类。

然后在每次移动后设置LastMove细节。

然后,你可以回到这些价值观!



也许不是别人会这样做的,但我会尝试这样的事情。 />
OK, If I understand the question correctly, you are basically wanting to create an "Un-DO" button, that will take you back to before the LAST move?

Create another partial class that stores each move.
Then set the LastMove details after each move.
Then, you can go back to those values!

Maybe not the way someone else would do it, but I would try something like this.
public partial class Form1 : Form
    {
        double q = 0;
        bool turn = true; //true = X turn, false = Y turn
        int turn_count = 0;
        public LastMove lMove = new LastMove();

        public Form1()
        {
            InitializeComponent();
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        public void button_click(object sender, EventArgs e)
        {
            Button b = (Button)sender;
            if (turn)
                b.Text = "X";
            else
                b.Text = "O";
            b.Enabled = false;
            turn_count++;
            lMove.turn = turn;
            lMove.button = b;
            lMove.tCount = turn_count;
            turn = !turn;
            //CheckForWinner();
        }

        public void UnDo_Button_click(object sender, EventArgs e)
        {
            turn = !turn;  // Sets back to the previous player
            lMove.button.Text = ""; // Clears the Text from the button
            lMove.button.Enabled = true; // Sets button back to Enabled
        }
    }

    public partial class LastMove
    {
        public bool turn { get; set; }
        public Button button { get; set; }
        public int tCount { get; set; }
    }


或者您甚至可以使用数组存储每一步。



然后你可以这样做:



Or you could even store every move by using an Array.

Then you could do something like this:

public partial class Form1 : Form
   {
       double q = 0;
       bool turn = true; //true = X turn, false = Y turn
       int turn_count = 0;
       public LastMove[] lMove = Enumerable
           .Range(0, 9)
           .Select(i => new LastMove())
           .ToArray();

       public Form1()
       {
           InitializeComponent();
       }

       private void exitToolStripMenuItem_Click(object sender, EventArgs e)
       {
           Application.Exit();
       }

       public void button_click(object sender, EventArgs e)
       {
           Button b = (Button)sender;
           if (turn)
               b.Text = "X";
           else
               b.Text = "O";
           b.Enabled = false;
           lMove[turn_count].turn = turn;
           lMove[turn_count].button = b;
           lMove[turn_count].tCount = turn_count;
           turn_count++;
           turn = !turn;
           //CheckForWinner();
       }

       public void UnDo_Button_click(object sender, EventArgs e)
       {
           turn_count = turn_count - 1;
           if (turn_count >= 0)
           {
               turn = !turn;  // Sets back to the previous player
               lMove[turn_count].button.Text = ""; // Clears the Text from the button
               lMove[turn_count].button.Enabled = true; // Sets button back to Enabled
           }
       }
   }

   public partial class LastMove
   {
       public bool turn { get; set; }
       public Button button { get; set; }
       public int tCount { get; set; }
   }


这篇关于3D Tic Tac Toe - back&前进(转动)按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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