⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cd5_4u.cpp

📁 C++ Builder程序员学习数据结构第4章
💻 CPP
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
#include <math.h>       //使用math函数
#include "cd5_4u.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
String tree[16]={"欢迎","你曾经自己完成一件程序设计作品吗?",
                 "你学过数据结构或BCB吗?", "你所设计的程序[成功]吗?",
                 "你学过其他程序或逻辑方法吗?", "你现在的学习有瓶颈吗?",
                 "你现在的程序设计基础打的好吗?","你所设计的程序有没有对外发布过?",
                 "先长出的耳朵,不如后长出的犄角坚硬","积沙成塔,聚少成多",
                 "有志者事尽成","恒心与毅力是成功的基石","熟练本书范例将对你大有助益",
                 "他山之石可以攻玉","或许本书可以提供你一些创意",
                 "对你而言本书仅为鸡肋耳"};

int idx,timer=0;
boolean restart=false;     //是否从新开始
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::rightClick(TObject *Sender)    //单击是的事件函数
{
   idx=idx*2+1;                     	//定义为右子树

   lout->Font->Size=8;                      //文字刚出现时的大小
   lout->Caption=tree[idx];                 //输出结点对应的文字内容
   timer=1;                                 //开启文字变大动画
   right->Visible=false;                     //使决策结点暂时消失
   left->Visible=false;
   if(idx>7)                             //游戏结果设置
   {
      lout->Font->Color=clRed;
      rep->Visible=true;
      rep->Caption="重新开始      ";
      idx=0;
      restart=true;
   }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::leftClick(TObject *Sender)
{
   idx=idx*2;                       //左子树

   lout->Font->Size=8;
   lout->Caption=tree[idx];
   timer=1;
   right->Visible=false;
   left->Visible=false;
   rep->Visible=false;
   if(idx>7)
   {
      lout->Font->Color=clRed;
      rep->Visible=true;
      rep->Caption="重新开始     ";
      idx=0;
      restart=true;
   }
}
//---------------------------------------------------------------------------


void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
   if(timer==1)                                //使字符串显示由小变大
   {
      if((lout->Font->Size)<24)               //让字体逐渐放大到24
         lout->Font->Size=(lout->Font->Size)+2;
      else
      {
         timer=0;                             //关闭时间控制器
         if(idx<8)
         {
           if (restart== false)
            {
            right->Visible=true;               //显示决策结点
            left->Visible=true;
            }
           restart=false;
         }
     }
   }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::repClick(TObject *Sender)        //开始及还原游戏起始状态
{
   idx=1;                             //还原游戏起始状态
   timer=1;
   lout->Caption=tree[idx];
   rep->Visible=false;
   right->Visible=true;
   left->Visible=true;
   lout->Font->Color=clBlack;
}
//---------------------------------------------------------------------------




⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -