Advertisement
Guest User

Untitled

a guest
Mar 11th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 8.49 KB | None | 0 0
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  7.   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls,
  8.   Vcl.Samples.Spin, Vcl.ComCtrls, DateUtils;
  9.  
  10. type
  11.   TForm1 = class(TForm)
  12.     Panel1: TPanel;
  13.     Panel2: TPanel;
  14.     Panel3: TPanel;
  15.     Panel4: TPanel;
  16.     Panel5: TPanel;
  17.     InputDigits: TGroupBox;
  18.     Button1: TButton;
  19.     Button2: TButton;
  20.     Button3: TButton;
  21.     Button4: TButton;
  22.     Button5: TButton;
  23.     Button6: TButton;
  24.     Button7: TButton;
  25.     Button8: TButton;
  26.     Button9: TButton;
  27.     DigitsBoard: TGroupBox;
  28.     Button11: TButton;
  29.     ShownDigits: TLabel;
  30.     GroupBox3: TGroupBox;
  31.     Button12: TButton;
  32.     RadioGroup1: TRadioGroup;
  33.     Timer1: TTimer;
  34.     DigitsPanel: TPanel;
  35.     Button10: TButton;
  36.     GroupBox1: TGroupBox;
  37.     SpinEdit1: TSpinEdit;
  38.     Label1: TLabel;
  39.     GroupBox2: TGroupBox;
  40.     ListView1: TListView;
  41.     procedure Button12Click(Sender: TObject);
  42.     procedure FormCreate(Sender: TObject);
  43.     procedure Timer1Timer(Sender: TObject);
  44.     function GiveMeStars(Count: integer): string;
  45.     procedure Button1Click(Sender: TObject);
  46.     procedure AddDigit(aDigit: integer);
  47.     procedure CheckResult;
  48.     procedure Button2Click(Sender: TObject);
  49.     procedure Button3Click(Sender: TObject);
  50.     procedure Button4Click(Sender: TObject);
  51.     procedure Button5Click(Sender: TObject);
  52.     procedure Button6Click(Sender: TObject);
  53.     procedure Button7Click(Sender: TObject);
  54.     procedure Button8Click(Sender: TObject);
  55.     procedure Button9Click(Sender: TObject);
  56.     procedure Button10Click(Sender: TObject);
  57.     procedure Button11Click(Sender: TObject);
  58.   private
  59.     { Private declarations }
  60.   public
  61.     { Public declarations }
  62.   end;
  63.  
  64. var
  65.   Form1: TForm1;
  66.   digits: array[1..5] of integer;
  67.   userdigits : string;
  68.   RomeAlphabet: array[1..9] of ShortString;
  69.   WordAlphabet: array[1..9] of ShortString;
  70.   score: integer;
  71.   time,nowtime:TDateTime;
  72.  
  73. implementation
  74.  
  75. {$R *.dfm}
  76.  
  77. { TForm1 }
  78.  
  79. procedure TForm1.AddDigit(aDigit: integer);
  80. var tempdigits: string;
  81.   i: integer;
  82.   dublicate: boolean;
  83. begin
  84.   tempdigits := ShownDigits.Caption;
  85.   dublicate := False;
  86.   case aDigit of
  87.     -1:begin
  88.       if (tempdigits[5] in ['1'..'9']) then
  89.       tempdigits[5] := '_'
  90.       else Delete(tempdigits, length(tempdigits)-1, 1);
  91.     end;
  92.     1..9:begin
  93.       if tempdigits[Length(tempdigits)] = '_' then begin
  94.         for i := 1 to Length(tempdigits)-1 do begin
  95.           if StrToInt(tempdigits[i]) = aDigit then dublicate := True;
  96.         end;
  97.         if not dublicate then begin
  98.           tempdigits[Length(tempdigits)] := IntToStr(aDigit)[1];
  99.           if Length(tempdigits) <5 then begin
  100.             tempdigits := tempdigits + '_';
  101.           end;
  102.         end;
  103.       end;
  104.     end;
  105.     10:begin
  106.       userdigits := '';
  107.       for i := 1 to Length(tempdigits) do begin
  108.         if tempdigits[i] <> '_' then begin
  109.           userdigits := userdigits + tempdigits[i];
  110.           if i<5 then userdigits := userdigits + ',';
  111.         end;
  112.       end;
  113.       CheckResult;
  114.     end;
  115.   end;
  116.   ShownDigits.Caption := tempdigits;
  117. end;
  118.  
  119. procedure TForm1.Button10Click(Sender: TObject);
  120. begin
  121.   AddDigit(-1);
  122. end;
  123.  
  124. procedure TForm1.Button11Click(Sender: TObject);
  125. begin
  126.   score := 0;
  127.   AddDigit(10);
  128. end;
  129.  
  130. procedure TForm1.Button12Click(Sender: TObject);
  131. var
  132.   i, j: Integer;
  133.   stop: boolean;
  134. begin
  135.   ShownDigits.Caption := '_';
  136.   for i := 1 to 5 do begin
  137.     repeat
  138.       stop := true;
  139.       if RadioGroup1.ItemIndex = 2 then digits[i] := Random(9)+1;
  140.       digits[i] := Random(9)+1;
  141.       for j := 1 to i-1 do
  142.         if digits[i] = digits[j]
  143.         then stop := false;
  144.     until stop;
  145.   end;
  146.   case RadioGroup1.ItemIndex of
  147.     0:begin
  148.       DigitsPanel.Font.Size := 60;
  149.       Panel1.Caption := IntToStr(digits[1]);
  150.       Panel2.Caption := IntToStr(digits[2]);
  151.       Panel3.Caption := IntToStr(digits[3]);
  152.       Panel4.Caption := IntToStr(digits[4]);
  153.       Panel5.Caption := IntToStr(digits[5]);
  154.     end;
  155.     1:begin
  156.       DigitsPanel.Font.Size := 30;
  157.       Panel1.Caption := RomeAlphabet[digits[1]];
  158.       Panel2.Caption := RomeAlphabet[digits[2]];
  159.       Panel3.Caption := RomeAlphabet[digits[3]];
  160.       Panel4.Caption := RomeAlphabet[digits[4]];
  161.       Panel5.Caption := RomeAlphabet[digits[5]];
  162.     end;
  163.     2:begin
  164.       DigitsPanel.Font.Size := 15;
  165.       Panel1.Caption := WordAlphabet[digits[1]];
  166.       Panel2.Caption := WordAlphabet[digits[2]];
  167.       Panel3.Caption := WordAlphabet[digits[3]];
  168.       Panel4.Caption := WordAlphabet[digits[4]];
  169.       Panel5.Caption := WordAlphabet[digits[5]];
  170.     end;
  171.     3:begin
  172.       DigitsPanel.Font.Size := 13;
  173.       Panel1.Caption := GiveMeStars(digits[1]);
  174.       Panel2.Caption := GiveMeStars(digits[2]);
  175.       Panel3.Caption := GiveMeStars(digits[3]);
  176.       Panel4.Caption := GiveMeStars(digits[4]);
  177.       Panel5.Caption := GiveMeStars(digits[5]);
  178.     end;
  179.   end;
  180.   Panel1.Visible := True;
  181.   Panel2.Visible := True;
  182.   Panel3.Visible := True;
  183.   Panel4.Visible := True;
  184.   Panel5.Visible := True;
  185.   Timer1.Interval := SpinEdit1.Value;
  186.   Timer1.Enabled := True;
  187. end;
  188.  
  189. procedure TForm1.Button1Click(Sender: TObject);
  190. begin
  191.   AddDigit(1);
  192. end;
  193.  
  194. procedure TForm1.Button2Click(Sender: TObject);
  195. begin
  196.   AddDigit(2);
  197. end;
  198.  
  199. procedure TForm1.Button3Click(Sender: TObject);
  200. begin
  201.   AddDigit(3);
  202. end;
  203.  
  204. procedure TForm1.Button4Click(Sender: TObject);
  205. begin
  206.   AddDigit(4);
  207. end;
  208.  
  209. procedure TForm1.Button5Click(Sender: TObject);
  210. begin
  211.   AddDigit(5);
  212. end;
  213.  
  214. procedure TForm1.Button6Click(Sender: TObject);
  215. begin
  216.   AddDigit(6);
  217. end;
  218.  
  219. procedure TForm1.Button7Click(Sender: TObject);
  220. begin
  221.   AddDigit(7);
  222. end;
  223.  
  224. procedure TForm1.Button8Click(Sender: TObject);
  225. begin
  226.   AddDigit(8);
  227. end;
  228.  
  229. procedure TForm1.Button9Click(Sender: TObject);
  230. begin
  231.   AddDigit(9);
  232. end;
  233.  
  234. procedure TForm1.CheckResult;
  235. var i,j: integer;
  236.   temp, temp2: string;
  237. begin
  238.   for i := 1 to Length(ShownDigits.Caption) do begin
  239.     if ShownDigits.Caption[i]<>'_' then begin
  240.       for j := 1 to 5 do begin
  241.         if StrToInt(ShownDigits.Caption[i]) = digits[j] then begin
  242.           inc(score);
  243.           break;
  244.         end;
  245.       end;
  246.     end;
  247.   end;
  248.   Panel1.Visible := True;
  249.   Panel2.Visible := True;
  250.   Panel3.Visible := True;
  251.   Panel4.Visible := True;
  252.   Panel5.Visible := True;
  253.   with ListView1.Items.Add do begin
  254.     Caption := RadioGroup1.Items[RadioGroup1.ItemIndex];
  255.     temp := '';
  256.     case RadioGroup1.ItemIndex of
  257.       0:begin
  258.         for i := 1 to 5 do begin
  259.           temp := temp + IntToStr(digits[i]);
  260.           if i < 5 then temp := temp + ',';
  261.         end;
  262.       end;
  263.       1:begin
  264.         for i := 1 to 5 do begin
  265.           temp := temp + RomeAlphabet[digits[i]];
  266.           if i < 5 then temp := temp + ',';
  267.         end;
  268.       end;
  269.       2:begin
  270.         for i := 1 to 5 do begin
  271.           temp := temp + WordAlphabet[digits[i]];
  272.           if i < 5 then temp := temp + ',';
  273.         end;
  274.       end;
  275.       3:begin
  276.         for i := 1 to 5 do begin
  277.           temp := temp + GiveMeStars(digits[i]);
  278.           if i < 5 then temp := temp + ',';
  279.         end;
  280.       end;
  281.     end;
  282.     SubItems.Add(temp);
  283.     SubItems.Add(userdigits);
  284.     SubItems.Add(FloatToStr((MilliSecondsBetween(time,now)/1000))+'с');
  285.     SubItems.Add(IntToStr(Round(score/5*100))+'%');
  286.   end;
  287.   ShowMessage('Ваш результат: '+IntToStr(Round(score/5*100))+'%');
  288. end;
  289.  
  290. procedure TForm1.FormCreate(Sender: TObject);
  291. begin
  292.   Randomize;
  293.   RomeAlphabet[1] := 'I';
  294.   RomeAlphabet[2] := 'II';
  295.   RomeAlphabet[3] := 'III';
  296.   RomeAlphabet[4] := 'IV';
  297.   RomeAlphabet[5] := 'V';
  298.   RomeAlphabet[6] := 'VI';
  299.   RomeAlphabet[7] := 'VII';
  300.   RomeAlphabet[8] := 'VIII';
  301.   RomeAlphabet[9] := 'IX';
  302.   WordAlphabet[1] := 'ОДИН';
  303.   WordAlphabet[2] := 'ДВА';
  304.   WordAlphabet[3] := 'ТРИ';
  305.   WordAlphabet[4] := 'ЧЕТЫРЕ';
  306.   WordAlphabet[5] := 'ПЯТЬ';
  307.   WordAlphabet[6] := 'ШЕСТЬ';
  308.   WordAlphabet[7] := 'СЕМЬ';
  309.   WordAlphabet[8] := 'ВОСЕМЬ';
  310.   WordAlphabet[9] := 'ДЕВЯТЬ';
  311. end;
  312.  
  313. function TForm1.GiveMeStars(Count: integer): string;
  314. var
  315.   i: Integer;
  316. begin
  317.   Result := '';
  318.   for i := 1 to Count do Result := Result + '*';
  319. end;
  320.  
  321. procedure TForm1.Timer1Timer(Sender: TObject);
  322. begin
  323.   Panel1.Visible := False;
  324.   Panel2.Visible := False;
  325.   Panel3.Visible := False;
  326.   Panel4.Visible := False;
  327.   Panel5.Visible := False;
  328.   time:=now;
  329.   Timer1.Enabled := False;
  330. end;
  331.  
  332. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement