鱼C论坛

 找回密码
 立即注册
查看: 2927|回复: 1

[作品展示] 点名器,Delphi

[复制链接]
发表于 2016-1-25 10:37:13 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. unit u2;

  2. interface

  3. uses
  4.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5.   Dialogs, StdCtrls, ExtCtrls, MPlayer;

  6. type
  7.   TForm1 = class(TForm)
  8.     Label1: TLabel;
  9.     Button1: TButton;
  10.     RadioButton1: TRadioButton;
  11.     RadioButton2: TRadioButton;
  12.     RadioButton3: TRadioButton;
  13.     Label2: TLabel;
  14.     Label3: TLabel;
  15.     Label4: TLabel;
  16.     Label5: TLabel;
  17.     Label6: TLabel;
  18.     Label7: TLabel;
  19.     Label8: TLabel;
  20.     Timer1: TTimer;
  21.     CheckBox1: TCheckBox;
  22.     Label9: TLabel;
  23.     Label10: TLabel;
  24.     procedure Button1Click(Sender: TObject);
  25.     procedure FormCreate(Sender: TObject);
  26.     procedure RadioButton1Click(Sender: TObject);
  27.     procedure RadioButton3Click(Sender: TObject);
  28.     procedure RadioButton2Click(Sender: TObject);
  29.     procedure Timer1Timer(Sender: TObject);
  30.     procedure CheckBox1Click(Sender: TObject);
  31.     procedure stop();
  32.     procedure Timer2Timer(Sender: TObject);
  33.   private
  34.     { Private declarations }
  35.   public
  36.     { Public declarations }
  37.   end;

  38. var
  39.   Form1: TForm1;

  40. implementation
  41. var
  42.   num:Integer;
  43.   InList:Boolean; //是否是最后一次点名(按下button),加入already
  44.   circle:Boolean =False;   //是否不重复
  45.   picking1:String='None';//与picking2构成“不重复”的帮助条件
  46.   picking2:Integer=1;   //1.点名模式,如果是不重复且切换了模式则警告 2.是否是第一次当前模式
  47.   status:Integer=0;  //0-全班,默认全班点名
  48.   already:Array of Integer;
  49.   names:Array [1..43] of String;



  50. procedure mode_changed(x: String);
  51. begin
  52.             if ((picking2=0) and (picking1 <> x)) then
  53.             begin
  54.                 SetLength(already,0);
  55.                 picking1:=x;
  56.                 MessageBox(0,'本次更改点名范围会导致下次重新回到本模式时重新开始新的一轮点名。' ,'警告',MB_OK or MB_ICONWARNING);
  57.             end;
  58.             if (picking2=1) then
  59.             begin
  60.                 picking1:=x;
  61.                 picking2:=0;
  62.             end;
  63. end;

  64. procedure TForm1.stop();
  65. begin
  66.   SetLength(already,0);
  67.   MessageBox(0,'已经循环一遍。' ,'警告',MB_OK or MB_ICONSTOP);


  68. end;
  69. procedure TForm1.CheckBox1Click(Sender: TObject);
  70. begin
  71.   circle:=not circle;
  72.   if(circle=False) then //circle现在是False : 刚才是True,不重复->要重复,要警告会导致。。。
  73.   begin
  74.     MessageBox(0,'本次更改是否重复会导致下次重新回到本模式时重新开始新的一轮点名。' ,'警告',MB_OK or MB_ICONWARNING);
  75.     SetLength(already,0); //already初始化
  76.   end;
  77. end;


  78. {$R *.dfm}

  79. procedure TForm1.Button1Click(Sender: TObject);
  80. var
  81.   t:Integer;
  82.   c:String;
  83. begin
  84.   if ((Timer1.Enabled) and (circle=True))then   //circle=1:要不循环模式
  85.     InList:=True
  86.   else
  87.     InList:=False; //即,如果已被激活,说明是最后一次,要InList。反之亦然。
  88.   Timer1.Enabled:=not Timer1.Enabled;
  89.   Label10.Caption:=BoolToStr(InList);
  90. //Debug
  91.   Label8.Caption:=IntToStr(status);
  92.   Label7.Caption:=IntToStr(Length(already));
  93.   If(Length(already)=0) then
  94.     Label6.Caption:='NULL'
  95.   else
  96.   begin
  97.     c:='';
  98.     For t:=0 to Length(already)-1 do
  99.     begin
  100.       c:=c+IntToStr(already[t])+',';
  101.     end;
  102.     Label6.Caption:=c;
  103.   end;
  104.   if(InList=True) then
  105.   begin
  106.     SetLength(already,Length(already)+1);
  107.     already[Length(already)-1]:=num;//length反回长度,长度-1为最后一个
  108.   end;
  109.   //Debug   Show Labels
  110.   Label8.Caption:=IntToStr(status);
  111.   Label7.Caption:=IntToStr(Length(already));
  112.   If(Length(already)=0) then
  113.     Label6.Caption:='NULL'
  114.   else
  115.   begin
  116.     c:='';
  117.     For t:=0 to Length(already)-1 do
  118.     begin
  119.       c:=c+IntToStr(already[t])+',';
  120.     end;
  121.     Label6.Caption:=c;
  122.   end;
  123. //End Debug.
  124. end;

  125. procedure TForm1.FormCreate(Sender: TObject);
  126. begin
  127.   //定义数组names
  128.   names[1]:='XX';
  129.   names[2]:='XX';
  130.   names[3]:='XX';
  131.   names[4]:='XX';
  132.   names[5]:='XX';
  133.   names[6]:='XX';
  134.   names[7]:='XX';
  135. ……………………………………………………
  136.   names[39]:='X';
  137.   names[40]:='X';
  138.   names[41]:='X';
  139.   names[42]:='XXX';
  140.   names[43]:='XXX';

  141. end;

  142. procedure TForm1.RadioButton1Click(Sender: TObject);
  143. begin
  144.    status:=0;   //全班
  145.    if(Timer1.Enabled) then
  146.     Timer1.Enabled:=False;
  147. end;

  148. procedure TForm1.RadioButton3Click(Sender: TObject);
  149. begin
  150.   status:=2;   //双班
  151.   if(Timer1.Enabled) then
  152.     Timer1.Enabled:=False;
  153. end;

  154. procedure TForm1.RadioButton2Click(Sender: TObject);
  155. begin
  156.   status:=1; //单班
  157.   if(Timer1.Enabled) then
  158.     Timer1.Enabled:=False;
  159. end;

  160. procedure TForm1.Timer1Timer(Sender: TObject);
  161. var
  162.   temp,mark:Integer;
  163.   content:String;
  164. begin
  165. //Debug

  166.     Randomize;
  167.     num:=Random(42)+1;
  168.   if (circle=False) then   //如果可重复
  169.   begin
  170.     if (status=0) then
  171.         Randomize;
  172.         num:=Random(42)+1;
  173.     if (status=1) then
  174.         while (num Mod 2)<>1 do
  175.         begin
  176.           Randomize;
  177.           num:=Random(42)+1;
  178.         end;
  179.     if (status=2) then
  180.         while (num Mod 2)<>0 do
  181.         begin
  182.             Randomize;
  183.             num:=Random(43)+1;
  184.         end;

  185.     content:='No. '+IntToStr(num)+' '+names[num];
  186.     Label1.Caption:=content;
  187.   end //还有else,没了';'
  188.   else   //circle=True,要“不循环”
  189.   begin
  190.         if (status=0) then
  191.         begin
  192.             mode_changed('全班') ;
  193.             while (True) do
  194.             begin

  195.                 if (Length(already)=43) then
  196.                 begin
  197.                     stop();
  198.                     break;
  199.                 end;
  200.                 Randomize;
  201.                 num:=Random(43)+1; //0-42+1 -- 1-43
  202.                 //本段太高频
  203.                 mark:=0; //初始化标志位
  204.                 For temp:=0 to (Length(already)-1) do
  205.                 begin
  206.                   if (num=already[temp]) then
  207.                   Begin
  208.                     mark:=1;
  209.                     break;
  210.                   end;            //如果在就标1
  211.                   end;
  212.                 //end。
  213.                 if (mark=0) then  //mark=0: "num not in already"(python)
  214.                 begin
  215.                   content:='No. '+IntToStr(num)+' '+names[num];
  216.                   Label1.Caption:=content ;
  217.                   break;
  218.                 end;
  219.             end;
  220.         end;

  221.         if (status=1) then
  222.         begin
  223.             mode_changed('单班') ;
  224.             while (True) do
  225.             begin
  226.                 if (Length(already)=22) then
  227.                 begin
  228.                     stop();
  229.                     break;
  230.                 end;
  231.                 Randomize;
  232.                 num:=Random(43)+1; //0-42+1 -- 1-43
  233.                 //本段太高频
  234.                 mark:=0; //初始化标志位
  235.                 For temp:=0 to (Length(already)-1) do
  236.                 begin
  237.                   if (num=already[temp]) then
  238.                     mark:=1;            //如果在就标1
  239.                   end;
  240.                 //end。
  241.                 if ((mark=0) and (num Mod 2=1)) then //如果是奇数
  242.                 begin
  243.                   content:='No. '+IntToStr(num)+' '+names[num];
  244.                   Label1.Caption:=content;//显示
  245.                   break;
  246.                 end;
  247.             end;
  248.         end;

  249.         if (status=2) then
  250.         begin
  251.             mode_changed('双班');
  252.             while (True) do
  253.             begin
  254.                 if (Length(already)=21) then
  255.                 begin
  256.                     stop();
  257.                     break;
  258.                 end;
  259.                 Randomize;
  260.                 num:=Random(43)+1; //0-42+1 -- 1-43
  261.                 //本段太高频
  262.                 mark:=0; //初始化标志位
  263.                 For temp:=0 to (Length(already)-1) do
  264.                 begin
  265.                   if (num=already[temp]) then
  266.                     mark:=1;            //如果在就标1
  267.                   end;
  268.                 //end。
  269.                 if ((mark=0) and (num Mod 2=0)) then //如果是偶数
  270.                 begin
  271.                   content:='No. '+IntToStr(num)+' '+names[num];
  272.                   Label1.Caption:=content;//显示
  273.                   break;
  274.                 end;
  275.             end;
  276.         end;
  277.   end;


  278. end;








  279. procedure TForm1.Timer2Timer(Sender: TObject);
  280. var
  281.   t:Integer;
  282.   c:String;
  283. begin
  284.   Timer1.Enabled:=not Timer1.Enabled;
  285.   Label10.Caption:=BoolToStr(InList);
  286. //Debug
  287.   Label8.Caption:=IntToStr(status);
  288.   Label7.Caption:=IntToStr(Length(already));
  289.   If(Length(already)=0) then
  290.     Label6.Caption:='NULL'
  291.   else
  292.   begin
  293.     c:='';
  294.     For t:=0 to Length(already)-1 do
  295.     begin
  296.       c:=c+IntToStr(already[t])+',';
  297.     end;
  298.     Label6.Caption:=c;
  299.   end;
  300. end;

  301. end.
复制代码


定义数组names的过程略变态,我当时用python帮忙处理一部分。
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2016-1-27 22:35:19 | 显示全部楼层
看看支持一下。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-5-15 23:33

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表