Autor Beitrag
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 03.01.08 12:45 
Moin!

Ich kann dir nicht exakt sagen, wohin das gehört, ich kenne ja dein Programm nicht. :nixweiss: ;) Aber das ist einer der Kandidaten, ja.

Du kannst es auch gleich im ObjectInspector für das TImage einstellen, wenn du das erste Bild schon in der IDE geladen hast, ansonsten besser da, wo du das erste mal "1.bmp" von der Platte holst. :idea:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
brainkopf Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 57

Win XP; Win 7
C# (VS 2005/2008)
BeitragVerfasst: Do 03.01.08 13:54 
Hmm. Danke, aber das funktioniert noch nicht. die Figur läuft einfach am Rand raus und das Hintergrundbild bleibt auf 1.
Hier mal der Code
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
unit Unit4;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, MPlayer;

type
  TForm4 = class(TForm)
    Hintergrund: TImage;
    spieler: TImage;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    Label1: TLabel;
    Image1: TImage;
    Button6: TButton;
    Image2: TImage;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure HintergrundClick(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form4: TForm4;

implementation

{$R *.dfm}

procedure TForm4.HintergrundClick(Sender: TObject);
begin
 Hintergrund.Tag:=1;
end;

procedure TForm4.Button1Click(Sender: TObject);
begin
if spieler.Left>=50 then
   spieler.Left:= spieler.Left -50;
   Label1.Caption := '';
end;

procedure TForm4.Button2Click(Sender: TObject);
begin // Button fürs nach Rechts gehen
  spieler.Left := spieler.Left +50;
  Label1.Caption := '';
  case Hintergrund.Tag of // in welchem Bild befinden wir uns?
    1: begin // 1.bmp
         if (spieler.Left >= 690) then begin // nächstes Bild?
           Hintergrund.Picture.LoadFromFile('2.bmp');
           Hintergrund.Tag := 2; // merken
         end;
       end;
    2: begin // 2.bmp
         if (spieler.Left >= 690) then begin // nächstes Bild?
           Hintergrund.Picture.LoadFromFile('3.bmp');
           Hintergrund.Tag := 3; // merken
         end
         else if (spieler.Left < 10) then begin // zurück?
           Hintergrund.Picture.LoadFromFile('1.bmp');
           Hintergrund.Tag := 1; // merken
         end;
       end;
  end;
end;

procedure TForm4.Button3Click(Sender: TObject);
begin
if spieler.Top>=200 then
   spieler.Top:= spieler.Top -50;
   Label1.Caption := '';
end;

procedure TForm4.Button4Click(Sender: TObject);
begin
if spieler.Top<=250 then
   spieler.Top:= spieler.Top +50;
   Label1.Caption := '';
end;

procedure TForm4.Button5Click(Sender: TObject);
begin
case spieler.Left of
  40: Label1.Caption := 'Das ist mein Schrank. Was der schon alles durchgemacht hat...';
  90: Label1.Caption := 'Die eine Kante sieht schon ziemlich ramponiert aus.';
  140: Label1.Caption := 'Mein Bett.';
  190: Label1.Caption := 'Mein Bett.';
  240: Label1.Caption := 'Mein Bett.';
  290: Label1.Caption := 'Mein Bett.';
  340: Label1.Caption := 'Ach, die Aussicht ist nicht so berauschend. Direkt vor dem Fenster ist die Hauptstraße.';
  390: Label1.Caption := 'Ach, die Aussicht ist nicht so berauschend. Direkt vor dem Fenster ist die Hauptstraße.';
  440: Label1.Caption := 'Was kann man schon über eine grüne Wand sagen...';
  490: Label1.Caption := 'Was kann man schon über eine grüne Wand sagen...';
  540: Label1.Caption := 'Was kann man schon über eine grüne Wand sagen...';
  590: Label1.Caption := 'Was kann man schon über eine grüne Wand sagen...';
  640: Label1.Caption := 'Was kann man schon über eine grüne Wand sagen...';
  690: Label1.Caption := 'Abgeschlossen...';
end;
end;

procedure TForm4.Button6Click(Sender: TObject);
begin
case spieler.Left of
  40: Label1.Caption := 'Hallo Schrank';
  90: Label1.Caption := 'Hallo Schrank';
  140: Label1.Caption := 'Heute siehst du aber nicht gut aus. Etwas grün.';
  190: Label1.Caption := 'Heute siehst du aber nicht gut aus. Etwas grün.';
  240: Label1.Caption := 'Heute siehst du aber nicht gut aus. Etwas grün.';
  290: Label1.Caption := 'TAXI!';
  340: Label1.Caption := 'TAXI!';
  390: Label1.Caption := 'TAXI!';
  440: Label1.Caption := 'TAXI!';
  490: Label1.Caption := 'Und wie gehts dir? - Hrmpf - *Heute bist du aber gut gelaunt...*';
  540: Label1.Caption := 'Und wie gehts dir? - Hrmpf - *Heute bist du aber gut gelaunt...*';
  590: Label1.Caption := 'Und wie gehts dir? - Hrmpf - *Heute bist du aber gut gelaunt...*';
  640: Label1.Caption := 'Heute siehst du aber nicht gut aus. Etwas grün.';
  690: Label1.Caption := 'Hilfe!!! Wir sind eingesperrt!!! HILFE!';
end;
end;
end.
Miri
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 657


Delphi 3 Prof., Delphi 2005 PE
BeitragVerfasst: Do 03.01.08 14:00 
user profile iconbrainkopf hat folgendes geschrieben:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm4.HintergrundClick(Sender: TObject);
begin
 Hintergrund.Tag:=1;
end;


Diese Prozedur wird nur aufgerufen, wenn du auf den Hintergrund klickst... Du willst aber doch, dass der Wert gesetzt wird, wenn du dein Programm startest, oder? FormCreate wäre dafür die richtige Prozedur...

Und noch was...
Wenn du den Hintergrund änderst, weil die Figur das Spielfeld verlassen hat, dann wäre es nur logisch, dass du sie dann auch im nächsten Raum wieder an den linken Rand setzt, oder?!

_________________
Anonymes Eckenkind
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 03.01.08 14:03 
Moin!

user profile iconbrainkopf hat folgendes geschrieben:
Hmm. Danke, aber das funktioniert noch nicht. die Figur läuft einfach am Rand raus und das Hintergrundbild bleibt auf 1.
Bitte ;) allerdings hast du meinen Vorschlag ja auch nicht umgesetzt (Miri hat zwischendurch schon was dazu geschrieben). :idea:

Dann noch eine Optimierung: :idea:
user profile iconbrainkopf hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
case spieler.Left of
  40,
  90: Label1.Caption := 'Das ist mein Schrank. Was der schon alles durchgemacht hat...';
  140,
  190,
  240,
  290: Label1.Caption := 'Mein Bett.';
  340,
  390: Label1.Caption := 'Ach, die Aussicht ist nicht so berauschend. Direkt vor dem Fenster ist die Hauptstraße.';
  440,
  490,
  540,
  590,
  640: Label1.Caption := 'Was kann man schon über eine grüne Wand sagen...';
  690: Label1.Caption := 'Abgeschlossen...';
end;

Weiterhin solltest du den Controls (Buttons z.B.) auch einen aussagekräftigen Namen geben, hast du bei den Images ja auch getan. Sowas macht den Code leichter lesbar. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
brainkopf Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 57

Win XP; Win 7
C# (VS 2005/2008)
BeitragVerfasst: Do 03.01.08 14:18 
Hää,
jetzt bin ich verwirrt.
Also doch so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm4.FormCreate(Sender: TObject);
begin
 Hintergrund.Tag:=1;
end;
?
Und mit den Buttons. Ja die hab ich iwi vergessen zu ändern.
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Do 03.01.08 14:30 
Ja genau, da gehört das hin.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
brainkopf Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 57

Win XP; Win 7
C# (VS 2005/2008)
BeitragVerfasst: Do 03.01.08 22:21 
Also das wechseln des Raumes wenn ich nach rechts laufe, funktioniert einwandfrei.
Nur nach links geht nicht.
Muss ich da noch den Code abändern und im Button für nach Links gehen schreiben?
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 03.01.08 22:25 
Moin!

user profile iconbrainkopf hat folgendes geschrieben:
Also das wechseln des Raumes wenn ich nach rechts laufe, funktioniert einwandfrei.
Fein. ;)

user profile iconbrainkopf hat folgendes geschrieben:
Nur nach links geht nicht.
Muss ich da noch den Code abändern und im Button für nach Links gehen schreiben?
Klar, in dem Handler wird ja noch nix geprüft.

An dieser Stelle bietet es sich an, für die Prüfung ein eigene Methode zu erstellen und diese in den Buttonhandlern nur noch aufzurufen - sonst schreibst du den Code ja (min.) 4 mal... :idea:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
brainkopf Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 57

Win XP; Win 7
C# (VS 2005/2008)
BeitragVerfasst: Do 03.01.08 23:31 
Stimmt. Ich was nur etwas irritiert wegen dem else if. Ich hab gedacht das es da mit drin ist. Kann ja aber nich sein. :)