hangman

[b][red]This message was edited by bickoCookie at 2003-5-5 22:49:36[/red][/b][hr]
hey i am just wondering if you could help me a delphi project. I am creating a hangman game and i am stuck on how to display underscores to represent the amount of letters in the randomly selected word.
i need to have a word randomly select which i have done below and then to have that chosen word display up in underscores which equals the number of letters in the word.





unit kenMainUnit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons;
type
TNewGame = class(TForm)
Button1: TButton;
Edit1: TEdit;
Label1: TLabel;
Guess_A_Letter_text: TLabel;
press: TButton;
Guessletter: TEdit;
BitBtn1: TBitBtn;
Rulesbtn: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure RulesbtnClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

type tword = string[10];
twordArray = array[1..20] of tword;
const secretword : twordArray
= ('ADVENTURE','COMPUTER','TELEPHONE',
'CALCULATOR','DESK','INTERNET','PENCIL',
'KANGAROO','PASSWORD','MOTORBIKE','FLOWER',
'CLOCK','CINEMA','STUDENT','CHAIR','MUSIC',
'UNIVERSITY','TEACHER','SCHOOL','BRISBANE');
var
NewGame: TNewGame;

implementation
uses Unit2;
{$R *.DFM}
procedure TNewGame.Button1Click(Sender: TObject);
VAR AWORD : tword;
awordindex : integer;

begin
awordindex := random(20) + 1;
aword := secretword[awordindex];
edit1.Text := aword;
end;
procedure TNewGame.FormActivate(Sender: TObject);
begin
randomize;
end;
type str10 = string[10];
charset = set of char;
procedure buildLetterSet (S : str10; var letters : charset);
{Builds a set of letters (letters : charset) contained in an
input stiring (S : str10).}
var x :integer;
begin
letters := [];
// Start with an empty set
for x := 1 to length (S) do
letters := letters + [S[x]]
// Scan string and add each letter to the set
end;

procedure buildTemplate(secretword : str10;
chosenletters : charset;
var template :str10);
{Builds a "Hangman Template" (template : str10) based on a
secret word (secretword : str10) and a set of chosen letters
(template : str10).}
var x : integer; // looping variable
begin
template := ''; // starts a null string
// scans along the secretword inspecting each letter
for x := 1 to length(secretword) do
if secretword[x] in chosenletters then
// add the current letter to the template
template := template + secretword[x]
// otherwise add a place holder character
else template := template + '-';
end;
procedure TNewGame.RulesbtnClick(Sender: TObject);
begin
AboutForm.showmodal;
end;
procedure TNewGame.FormCreate(Sender: TObject);
begin
end;
end.


>From: "Sheri Taylor"
>To: dirtydoneman@hotmail.com
>Subject: Hangman program
>Date: Tue, 06 May 2003 15:23:41 +1000
>



Comments

  • Will setting the passwordchar property of the edit
    box to an asterix or a dash not do the trick? Also i would be interested in trying the full version when finished if possible.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion