#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Posts
    5
    Rep Power
    0

    Exclamation Urgent help needed, Newbie to Delphi 7,please help with the errors in my code!!!


    I'm a new person to Delphi 7 as well, only been using delphi for bout 2 to 3 months and this is my first atempt at a game.
    I know my code has errors, so any help would be great. The game is Hangman.
    The full code is:

    type
    THangman = class(TForm)
    WelcomePanel: TPanel;
    CheckBox1: TCheckBox;
    Edit1: TEdit;
    Exit1Button: TButton;
    OkayButton: TButton;
    GamePanel: TPanel;
    Label2: TLabel;
    CorrectGuessLabel: TLabel;
    Label3: TLabel;
    LettersGuessedLabel: TLabel;
    Exit2Button: TButton;
    NewGameButton: TButton;
    Label4: TLabel;
    Edit2: TEdit;
    ClearButton: TButton;
    Image1: TImage;
    Image2: TImage;
    Image3: TImage;
    Image4: TImage;
    Image5: TImage;
    Image6: TImage;
    Image8: TImage;
    Image7: TImage;
    Image9: TImage;
    Image10: TImage;
    ToHangmanLabel: TLabel;
    HangmanTitle: TImage;
    WelcomeTitle: TImage;
    procedure Exit1ButtonClick(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure Edit1KeyPress(Sender:TObject; var Key: char);
    procedure OkayButtonClick(Sender: TObject);
    procedure Exit2ButtonClick(Sender: TObject);
    procedure NewGameButtonClick(Sender: TObject);
    procedure Edit2KeyPress (Sender: TObject; var Key: char);
    procedure ClearButtonClick(Sender: TObject);


    private
    { Private declarations }
    public
    { Public declarations }
    Letter : char;
    TheWord:string;
    GuessedLetters:set of char;
    procedure CheckALetter(ch:char);

    end;

    var
    Hangman: THangman;


    implementation

    {$R *.dfm}
    var Letter : array[1..26] of char;
    type
    LetterList = record
    Letter : char;
    end;

    procedure THangman.Exit1ButtonClick(Sender: TObject);
    begin
    application.Terminate;
    end;

    procedure THangman.Edit1KeyPress(Sender: TObject; var Key: char);
    begin
    Key:=UpCase(Key);
    if not (upcase(key) in ['A'..'Z']) then
    begin
    key:= #0;
    messagebeep(mb_iconexclamation);
    end;
    end;
    procedure THangman.CheckBox1Click(Sender: TObject);
    begin
    if CheckBox1.Checked then Edit1.passwordchar:= '*'
    else Edit1.passwordchar:= #0;

    end;
    procedure THangman.OkayButtonClick(Sender: TObject);
    var i:integer;
    begin
    if length(Edit1.Text)<=1
    then showmessage('Too short, need longer word please!!')
    else
    begin
    WelcomePanel.Visible:= false;
    GamePanel.Visible:=true;
    TheWord:=uppercase(Edit1.Text);
    CorrectGuessLabel.Caption:='';
    for i:=1 to length(TheWord) do
    CorrectGuessLabel.Caption:=CorrectGuessLabel.Caption+'_ ';
    guessedletters:=[];
    LettersGuessedLabel.Caption:='';
    end;
    end;

    procedure THangman.Exit2ButtonClick(Sender: TObject);
    begin
    application.Terminate;
    end;

    procedure THangman.NewGameButtonClick(Sender: TObject);
    begin
    WelcomePanel.Visible:= true;
    GamePanel.Visible:=false;
    Edit2.Text:='';
    Edit1.Text:='';
    end;

    procedure THangman.Edit2KeyPress(Sender: TObject; var Key: Char);
    begin
    Key := UpCase(Key);
    edit2.text:= '';
    if not (key in['A'..'Z']) then
    begin
    key:= #0;
    messagebeep(mb_iconexclamation);
    end
    else CheckALetter(Key);
    end;

    procedure THangman.CheckALetter(ch:char);
    var
    i:integer;
    s:string;
    count:integer;
    goodguess:boolean;
    LetterList: char;
    begin
    GuessedLetters:=GuessedLetters+[ch];
    LettersGuessedLabel.caption:=LettersGuessedLabel.caption+ch+' , ';
    s:=CorrectGuessLabel.Caption;
    for i:=1 to length(TheWord) do
    begin
    if ch=TheWord[i] then
    begin
    s[2*i-1]:= ch;
    goodguess:= true;
    end;
    CorrectGuessLabel.Caption:= s;
    if not goodguess then count := count + 1;
    case count of
    1:Image1.visible := true;
    2:Image2.visible:= true;
    3:Image3.visible := true;
    4:Image4.Visible:=true;
    5:Image5.Visible:= true;
    6:Image6.Visible:= true;
    7:Image7.Visible := true;
    8:Image8.Visible:= true;
    9:Image9.visible:= true;
    10:Image10.Visible:= true;
    end;//end case
    ch := LetterList;
    if not (ch<>0) then
    showmessage('You have used that letter already, choose another letter!');
    LetterList.Letter := ch+LetterList.Letter ;
    if pos('_',CorrectGuessLabel.Caption)=0 then
    showmessage('Congratulations, you have guessed the word, click on new game to restart!!!')
    end;
    end;
    procedure THangman.ClearButtonClick(Sender: TObject);
    begin
    Edit1.Text:= '';
    end;

    end.


    I know that I have a whole ton of errors in here. If you spot any that anyone can help me with, it would be a great help.
    Thanx in advance for any assistance with the code.
    Christel.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Posts
    4
    Rep Power
    0

    Talking


    If you would be willing to, zip and email your project files to me, Id be quite happy to debug the entire project and email it to you.

    Just a hint: When posting to forums, make sure that you explain the problem and not post your sourcecode. Most people who want to help but can only get your source will turn them off because of the lack of explanation and they will need the whole package or Delphi will simply refuse to compile the code.

    justinsavidge@dodo.com.au

IMN logo majestic logo threadwatch logo seochat tools logo