0% found this document useful (0 votes)
3 views

Practice activity

The document is a Delphi unit that defines a form with various interactive elements such as buttons, labels, and edit fields for a color and number guessing game. It includes procedures for handling button clicks, validating user input against predefined values, and implementing a countdown timer. The form allows users to guess colors and numbers, with feedback provided based on their inputs.

Uploaded by

z2cpc8qnzd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Practice activity

The document is a Delphi unit that defines a form with various interactive elements such as buttons, labels, and edit fields for a color and number guessing game. It includes procedures for handling button clicks, validating user input against predefined values, and implementing a countdown timer. The form allows users to guess colors and numbers, with feedback provided based on their inputs.

Uploaded by

z2cpc8qnzd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1: unit Unit1;

2:
3: interface
4:
5: uses
6: Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System
7: Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Math, Vcl.ExtCtrls ;
8:
9: type
10: TForm1 = class(TForm)
11: btnkeypad: TButton;
12: lblDisplay: TLabel;
13: edtColorGuess: TEdit;
14: btnColorGuess: TButton;
15: lblTimer: TLabel;
16: btnTimer: TButton;
17: TTimer: TTimer;
18: btnEnter: TButton;
19: edtColor: TEdit;
20: edtNum: TEdit;
21: procedure btnkeypadClick(Sender: TObject);
22: procedure btnColorGuessClick(Sender: TObject);
23: procedure FormActivate(Sender: TObject);
24: procedure btnTimerClick(Sender: TObject);
25: procedure btnEnterClick(Sender: TObject);
26: private
27: { Private declarations }
28: public
29: { Public declarations }
30: end;
31:
32: var
33: Form1: TForm1;
34: iCountdown : Integer ;
35:
36: implementation
37:
38: {$R *.dfm}
39:
40: procedure TForm1.btnColorGuessClick(Sender: TObject);
41:
42: var
43: iRandomColor : Integer ;
44: sRandomColor, sUserColor : String ;
45:
46: begin
47:
48: iRandomColor := RandomRange(1,4) ;
49:
50: case iRandomColor of
51: 1 : sRandomColor := 'Red' ;
52: 2 : sRandomColor := 'Blue' ;
53: 3 : sRandomColor := 'Green' ;
54: end;
55:
56: sUserColor := edtColorGuess.Text ;
57:
58: if sUserColor = sRandomColor then
59: begin
60: ShowMessage( 'Correct Guess!' ) ;
61: end
62: else
63: begin
64: ShowMessage( 'Incorrect Guess, Please retry!' ) ;
65: edtColorGuess.SetFocus ;
66: end;
67:
68: end;
69:
70: procedure TForm1.btnEnterClick(Sender: TObject);
71:
72: var
73: sColorRight, sColorUser, sNumRight, sNumUser : String ;
74:
75: begin
76:
77: sColorRight := 'blue' ;
78: sNumRight := '7' ;
79:
80: sColorUser := edtColor.Text ;
81: sNumUser := edtNum.Text ;
82:
83: if (sColorUser = sColorRight) AND (sNumUser = sNumRight) then
84: begin
85: Showmessage( 'Both guesses correct! Well done!' ) ;
86: end
87: else if (sColorUser = sColorRight) OR (sNumUser = sNumRight) then
88: begin
89: ShowMessage( 'One guess correct! *Hint, Color = Police. Number = 15-8'
90: end
91: else
92: begin
93: ShowMessage( 'None of your guesses are correct you retard!' ) ;
94: end;
95:
96:
97:
98: end;
99:
100: procedure TForm1.btnkeypadClick(Sender: TObject);
101:
102: var
103: sName, sCode : String ;
104:
105: begin
106:
107: sCode := InputBox('Access Room!' , 'Please enter the 4 digit code to enet
108: sName := InputBox('Agent Name!' , 'Please enter your name!' , '' ) ;
109:
110: if sCode = '1234' then
111: begin
112: lblDisplay.Caption := 'Access Granted, ' + sName ;
113: end
114: else
115: begin
116: lblDisplay.Caption := 'Access Denied!' ;
117: end;
118:
119:
120:
121:
122: end;
123:
124: procedure TForm1.btnTimerClick(Sender: TObject);
125:
126: var
127: k : Integer ;
128:
129: begin
130:
131: lblTimer.Caption := '10' ;
132: TTimer.Enabled := True ;
133:
134: for k := 10 downto 0 do
135: begin
136: lblTimer.Caption := IntToStr(k) ;
137: Refresh ;
138: Sleep(1000) ;
139: end;
140:
141: TTimer.Enabled := False ;
142: ShowMessage( 'Times up! Try Again!' ) ;
143:
144:
145:
146: end;
147:
148: procedure TForm1.FormActivate(Sender: TObject);
149: begin
150:
151: iCountdown := 10 ;
152: TTimer.Enabled := False ;
153:
154: end;
155:
156: end.
157:

You might also like