使用 Builder 6 应用程序表单进行井字游戏

发布于 2024-10-04 22:39:08 字数 647 浏览 0 评论 0原文

我正在使用动态按钮在 Builder 6 中玩 tic tac toe 游戏,我遇到了一个问题,当我按下按钮时,该功能会交替 X 和 0。

void __fastcall show(TObject *Sender)
{
    v=1;
    if(v%2==1)
        btn->Caption="X";
    else
        btn->Caption="0";
    v++;
    btn->Enabled=false;
}


for(i=0;i<5;i++)
{
     for(j=0;j<5;j++)
     {
         object[i][j] = new C;

         //object[i][j]->v=i;
         object[i][j]->btn = new TButton(this);

apel 看起来像这样:

    object[i][j]->btn->OnClick=object[i][j]->show;
    }
}

如果我不使用 object[i][j]->v=i; 它只显示 X 或 0

我想知道如何在之后显示 0 X等等。

i'm doing a tic tac toe game in builder 6 with dinamic buttons and i encounted a issue whit the function which alternates the X and 0 when i pressed a button.

void __fastcall show(TObject *Sender)
{
    v=1;
    if(v%2==1)
        btn->Caption="X";
    else
        btn->Caption="0";
    v++;
    btn->Enabled=false;
}


for(i=0;i<5;i++)
{
     for(j=0;j<5;j++)
     {
         object[i][j] = new C;

         //object[i][j]->v=i;
         object[i][j]->btn = new TButton(this);

the apel looks like this :

    object[i][j]->btn->OnClick=object[i][j]->show;
    }
}

if i dont use object[i][j]->v=i; it shows me only X or 0

I want to know how can i make to show 0 after X and so on.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

咋地 2024-10-11 22:39:08

也许您应该检查该按钮是否也已启用:

if(btn->Enabled==true)
{
    if(v%2==1)
    {...

我希望这可以解决您的问题。

干杯,
贝科。

Maybe you should check if the button is enabled also:

if(btn->Enabled==true)
{
    if(v%2==1)
    {...

I hope this solves your problem.

Cheers,
Beco.

凉薄对峙 2024-10-11 22:39:08

不要在每次点击时设置 v=1,仅在程序启动时(或开始新游戏时)设置一次。

Don't set v=1 on every click, only do that once when the program starts (or when you begin a new game).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文