Steichholzprogramm Grafisch
-
Hallo Leute,
ich hoffe ich bin nun im richtigen Unterforum.
Ich muss ein Programm mit einer Grafischen Oberfläche schreiben.
Wir haben nur die minimalsten Grundlagen in der Informatik Vorlesung gezeigt bekommen. Den Rest sollen wir uns durch das Internet usw selbst erarbeiten.
Nun hoffe ich auf einige TIPPS (ich will keine Lösungen).Ich arbeite mit in Visual Studio 2008 mit Windows Forms. Ich hoffe die Angaben reichen so ?!
Ich muss ein Programm schreiben, was eigentlich jeder kennt. Es ist ein Spiel. Es sollen 20 Streichhölzer auf dem Tisch (Bildschirm) liegen. Ich soll gegen den Computer spielen. Jeder kann 1-3 Streichhölzer ziehen. Wer das letzte zieht hat verloren.
Ich bin noch so am Anfang, dass ich erstmal ohne Gegner spielen möchte.
Die grafische Oberfläche habe ich eingerichtet. Ich habe 20 pictureBox'en mit jeweils einem Streichholz Foto. Ebenfas drei Buttons mit "Ziehe 1 Holz" "Ziehe 2" "Ziehe 3".
In dem Button 1 habe ich nun stehen:
pictureBox1->Image = Image::FromFile("Sth_transparent.jpg");
In Button 2 und 3 das selbe, bloß zwei bzw. drei mal. Er läd also beim klicken, ein anderes Bild ein, in meinem Falle ein transparentes Streichholz.
Nun mein Problem:
Wie kriege ich es hin, dass er die Anzahl meiner noch vorhanden pictureboxen zählt? Denn ziehe ich einmal 3 Streichhölzer weg, darf beim nächsten Zug ja nur noch Streichholz 4-20 in Angriff genommen werden.Mein Grundidee war in dem Button irgendwie eine Funktion aufrufen zu lassen... Ich kriege es aber nicht so recht hin. Ich sitze seit 4 Std vor dem Programm und habe noch quasi nichts geschafft.
Ich stehe auf dem Schlauch.
Ich weiß nicht wie ich es schaffen soll, dass irgendwie alle meine pictureboxen gezählt werden, und nach dem anklicken eines Buttons die spezifische Anzahl von pictureBoxen abgezogen wird.Ich hoffe ihr habt einen Tipp für mich. Bitte bedenkt ich bin ein ziemlicher Anfänger.
Danke im Voraus.
Gruß und schönes Wochenende!
-
Beinahe richtig.
Aber WinForms ist http://www.c-plusplus.net/forum/285168 und nicht MFC.
-
Um einmal einen nützlichen Tipp zu geben:
1. Wozu die Bilder vertauschen? Setze doch einfach visible=false.2. Mach doch einfach eine Zählvariable, die mit jedem Klick auf einen Button runterzählt und wenn der Wert <= 0 wird, ist das Spiel vorbei.
3. "Schöner" aussehen würde es imo, wenn du die ImageBoxen in Arrayform zur Laufzeit erstellst und dann immer die Imagebox invisible machst, bei der die Zählvariable gerade steht.
-
GR-Thunderstorm schrieb:
2. Mach doch einfach eine Zählvariable, die mit jedem Klick auf einen Button runterzählt und wenn der Wert <= 0 wird, ist das Spiel vorbei.
Ja genau, da ist mein Problem.
Zuerst wollte ich eine Zählvariable in den Konstruktor schreiben, doch von dort aus, kann ich keine Beziehung in die "Button_Click" nehmen. Nehm ich also die Zählvariable "Streichholz_Anzahl" im Konstruktor und möchte mich nacher unter "ClickButton" darauf beziehen, erscheint beim debuggen eine Fehlermeldung "Bezeichner nicht deklariert". Das wundert mich.So nun weiß ich nicht, wo ich eine Zählvariable erstellen soll, sodass alle drei Button "Ziehe 1" "Ziehe 2" und "Ziehe 3" jeweils die Zählvariable zum laufen bringen.
Und die letzte Frage: Im Gegensatz zu einer Konsolenanwendung in C++ läuft bei meiner GUI Anwendung das Programm doch NICHT von oben nach unten, sondern es steht in der ganzen Laufzeit durchgehen mit dem Betriebssystem in Kontakt oder? Bei C++ mit einer Konsolenanwendung läuft das Programm ja von oben nach unten ab, ist es unten angekommen ist es vorbei. So ist es bei meiner GUI Anwendung nicht oder?! Oder fängt es nach jedem "Click_Button" wieder von oben an?!
Gruß
-
Dann mußt du diese Variable halt an eine Stelle packen, wo jeder Beteiligte sie sehen kann - z.B. als Member der Fenster-Klasse.
Und die letzte Frage: Im Gegensatz zu einer Konsolenanwendung in C++ läuft bei meiner GUI Anwendung das Programm doch NICHT von oben nach unten, sondern es steht in der ganzen Laufzeit durchgehen mit dem Betriebssystem in Kontakt oder? Bei C++ mit einer Konsolenanwendung läuft das Programm ja von oben nach unten ab, ist es unten angekommen ist es vorbei. So ist es bei meiner GUI Anwendung nicht oder?! Oder fängt es nach jedem "Click_Button" wieder von oben an?!
Stark vereinfacht: Prinzipiell hast du ganz oben eine Nachrichten-Warteschlange, die vom System gefüllt wird (bei SendMessage(), PostMessage() etc) und im Hintergrund läuft eine Hauptschleife, die diese Nachrichten ausliest und in Methodenaufrufe deines Fensters übersetzt. So ein Design könntest du auch in einer Konsolenanwendung aufbauen, müsstest dann allerdings die Verteilung selber schreiben.
PS: Dieser Thread folgt jetzt seinem Vorgänger ins richtige Board.
-
Dieser Thread wurde von Moderator/in CStoll aus dem Forum MFC (Visual C++) in das Forum C++/CLI mit .NET verschoben.
Im Zweifelsfall bitte auch folgende Hinweise beachten:
C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?Dieses Posting wurde automatisch erzeugt.
-
CStoll schrieb:
Dann mußt du diese Variable halt an eine Stelle packen, wo jeder Beteiligte sie sehen kann - z.B. als Member der Fenster-Klasse.
"Member der Fenster-Klasse" Kannst du da ein bisschen mehr zu sagen? Das sagt mir leider nichts, sorry
Ich habe einfach kein "Ort" gefunden, wo jeder Beteiligte zugriff drauf hat. Magst du das evtl noch einmal etwas "einfach" sagen, bzw genauer zu beschreiben? Bin halt noch ein ziemicher Anfänger.Gruß und Danke!
-
Dein Konstruktor ist doch in einer Klasse definiert, die (hoffe ich) auch die OnClick-Methoden für die Buttons bereitstellt. Und in dieser Klasse kannst du auch Member-Variablen definieren, auf die jede deiner Methoden zugreifen kann.
(für den konkreten Aufbau mußt du auf die einheimischen CLI-Experten warten, die können das sicher ausführlicher erklären als ich)
-
Darauf was ich im Kontruktor deklariere, können die Click_Buttons nicht drauf zu greifen, bzw ich wüsste nicht wie.
Wenn ich im Kontruktor was deklariere und es im "Click_Button" nutzen will, kommt "nicht deklarierter Bezeichner" wie oben beschrieben.Gruß und Danke
-
nicht im Konstruktor, sondern in der Klasse, deren Konstruktor du schreibst:
class Window { public: Window(...) : anzahl(20) { } void Click_Button() { --anzahl; //... } private: int anzahl; };
-
So bin jetzt ein Stück weiter. Habe eine Zählervariable drin, die zäht, wie viel Streichhölzer noch auf dem Bildschirm liegen.
Jetzt muss ich es aber noch hin bekommen, dass zuerst Streichholz 1-3 verschwinden soll und danach die folgenden.
Da ist mein Problem jetztiges Problem.Um mein Problem genauer zu erläutern poste ich nun mal meinen ganzen Quelltext sowieso ein Screenshot der grafischen Oberfläche und hoffe dann auf weitere Hilfe.
Ihr seit Super!#pragma once namespace Projektaufgabe_Streichholzspiel_Tom_Reske { using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; /// <summary> /// Zusammenfassung für Form1 /// /// Warnung: Wenn Sie den Namen dieser Klasse ändern, müssen Sie auch /// die Ressourcendateiname-Eigenschaft für das Tool zur Kompilierung verwalteter Ressourcen ändern, /// das allen RESX-Dateien zugewiesen ist, von denen diese Klasse abhängt. /// Anderenfalls können die Designer nicht korrekt mit den lokalisierten Ressourcen /// arbeiten, die diesem Formular zugewiesen sind. /// </summary> public ref class Form1 : public System::Windows::Forms::Form { public: Form1(void) { InitializeComponent(); { } // //TODO: Konstruktorcode hier hinzufügen. // } static Int32 sth_anzahl=20; private: System::Windows::Forms::TextBox^ textBox1; public: protected: /// <summary> /// Verwendete Ressourcen bereinigen. /// </summary> ~Form1() { if (components) { delete components; } } public: System::Windows::Forms::PictureBox^ pictureBox1; protected: private: System::Windows::Forms::PictureBox^ pictureBox2; private: System::Windows::Forms::PictureBox^ pictureBox3; private: System::Windows::Forms::PictureBox^ pictureBox4; private: System::Windows::Forms::PictureBox^ pictureBox5; private: System::Windows::Forms::PictureBox^ pictureBox6; private: System::Windows::Forms::PictureBox^ pictureBox7; private: System::Windows::Forms::PictureBox^ pictureBox8; private: System::Windows::Forms::PictureBox^ pictureBox9; private: System::Windows::Forms::PictureBox^ pictureBox10; private: System::Windows::Forms::PictureBox^ pictureBox11; private: System::Windows::Forms::PictureBox^ pictureBox12; private: System::Windows::Forms::PictureBox^ pictureBox13; private: System::Windows::Forms::PictureBox^ pictureBox14; private: System::Windows::Forms::PictureBox^ pictureBox15; private: System::Windows::Forms::PictureBox^ pictureBox16; private: System::Windows::Forms::PictureBox^ pictureBox17; private: System::Windows::Forms::PictureBox^ pictureBox18; private: System::Windows::Forms::PictureBox^ pictureBox19; private: System::Windows::Forms::PictureBox^ pictureBox20; private: System::Windows::Forms::Button^ button1; private: System::Windows::Forms::Button^ button2; private: System::Windows::Forms::Button^ button3; private: System::Windows::Forms::Button^ button4; protected: private: /// <summary> /// Erforderliche Designervariable. /// </summary> System::ComponentModel::Container ^components; #pragma region Windows Form Designer generated code /// <summary> /// Erforderliche Methode für die Designerunterstützung. /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden. /// </summary> void InitializeComponent(void) { System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid)); this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox()); this->pictureBox2 = (gcnew System::Windows::Forms::PictureBox()); this->pictureBox3 = (gcnew System::Windows::Forms::PictureBox()); this->pictureBox4 = (gcnew System::Windows::Forms::PictureBox()); this->pictureBox5 = (gcnew System::Windows::Forms::PictureBox()); this->pictureBox6 = (gcnew System::Windows::Forms::PictureBox()); this->pictureBox7 = (gcnew System::Windows::Forms::PictureBox()); this->pictureBox8 = (gcnew System::Windows::Forms::PictureBox()); this->pictureBox9 = (gcnew System::Windows::Forms::PictureBox()); this->pictureBox10 = (gcnew System::Windows::Forms::PictureBox()); this->pictureBox11 = (gcnew System::Windows::Forms::PictureBox()); this->pictureBox12 = (gcnew System::Windows::Forms::PictureBox()); this->pictureBox13 = (gcnew System::Windows::Forms::PictureBox()); this->pictureBox14 = (gcnew System::Windows::Forms::PictureBox()); this->pictureBox15 = (gcnew System::Windows::Forms::PictureBox()); this->pictureBox16 = (gcnew System::Windows::Forms::PictureBox()); this->pictureBox17 = (gcnew System::Windows::Forms::PictureBox()); this->pictureBox18 = (gcnew System::Windows::Forms::PictureBox()); this->pictureBox19 = (gcnew System::Windows::Forms::PictureBox()); this->pictureBox20 = (gcnew System::Windows::Forms::PictureBox()); this->button1 = (gcnew System::Windows::Forms::Button()); this->button2 = (gcnew System::Windows::Forms::Button()); this->button3 = (gcnew System::Windows::Forms::Button()); this->button4 = (gcnew System::Windows::Forms::Button()); this->textBox1 = (gcnew System::Windows::Forms::TextBox()); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->BeginInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox2))->BeginInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox3))->BeginInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox4))->BeginInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox5))->BeginInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox6))->BeginInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox7))->BeginInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox8))->BeginInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox9))->BeginInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox10))->BeginInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox11))->BeginInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox12))->BeginInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox13))->BeginInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox14))->BeginInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox15))->BeginInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox16))->BeginInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox17))->BeginInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox18))->BeginInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox19))->BeginInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox20))->BeginInit(); this->SuspendLayout(); // // pictureBox1 // this->pictureBox1->BackgroundImage = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"pictureBox1.BackgroundImage"))); this->pictureBox1->ErrorImage = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"pictureBox1.ErrorImage"))); this->pictureBox1->Location = System::Drawing::Point(12, 12); this->pictureBox1->Name = L"pictureBox1"; this->pictureBox1->Size = System::Drawing::Size(27, 196); this->pictureBox1->TabIndex = 0; this->pictureBox1->TabStop = false; this->pictureBox1->Click += gcnew System::EventHandler(this, &Form1::pictureBox1_Click); // // pictureBox2 // this->pictureBox2->BackgroundImage = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"pictureBox2.BackgroundImage"))); this->pictureBox2->Location = System::Drawing::Point(45, 12); this->pictureBox2->Name = L"pictureBox2"; this->pictureBox2->Size = System::Drawing::Size(28, 196); this->pictureBox2->TabIndex = 1; this->pictureBox2->TabStop = false; // // pictureBox3 // this->pictureBox3->BackgroundImage = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"pictureBox3.BackgroundImage"))); this->pictureBox3->Location = System::Drawing::Point(79, 12); this->pictureBox3->Name = L"pictureBox3"; this->pictureBox3->Size = System::Drawing::Size(27, 196); this->pictureBox3->TabIndex = 2; this->pictureBox3->TabStop = false; // // pictureBox4 // this->pictureBox4->BackgroundImage = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"pictureBox4.BackgroundImage"))); this->pictureBox4->Location = System::Drawing::Point(112, 12); this->pictureBox4->Name = L"pictureBox4"; this->pictureBox4->Size = System::Drawing::Size(28, 196); this->pictureBox4->TabIndex = 3; this->pictureBox4->TabStop = false; // // pictureBox5 // this->pictureBox5->BackgroundImage = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"pictureBox5.BackgroundImage"))); this->pictureBox5->Location = System::Drawing::Point(146, 12); this->pictureBox5->Name = L"pictureBox5"; this->pictureBox5->Size = System::Drawing::Size(31, 196); this->pictureBox5->TabIndex = 4; this->pictureBox5->TabStop = false; // // pictureBox6 // this->pictureBox6->BackgroundImage = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"pictureBox6.BackgroundImage"))); this->pictureBox6->Location = System::Drawing::Point(183, 12); this->pictureBox6->Name = L"pictureBox6"; this->pictureBox6->Size = System::Drawing::Size(29, 196); this->pictureBox6->TabIndex = 5; this->pictureBox6->TabStop = false; // // pictureBox7 // this->pictureBox7->BackgroundImage = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"pictureBox7.BackgroundImage"))); this->pictureBox7->Location = System::Drawing::Point(218, 12); this->pictureBox7->Name = L"pictureBox7"; this->pictureBox7->Size = System::Drawing::Size(27, 196); this->pictureBox7->TabIndex = 6; this->pictureBox7->TabStop = false; // // pictureBox8 // this->pictureBox8->BackgroundImage = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"pictureBox8.BackgroundImage"))); this->pictureBox8->Location = System::Drawing::Point(251, 12); this->pictureBox8->Name = L"pictureBox8"; this->pictureBox8->Size = System::Drawing::Size(28, 196); this->pictureBox8->TabIndex = 7; this->pictureBox8->TabStop = false; // // pictureBox9 // this->pictureBox9->BackgroundImage = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"pictureBox9.BackgroundImage"))); this->pictureBox9->Location = System::Drawing::Point(285, 12); this->pictureBox9->Name = L"pictureBox9"; this->pictureBox9->Size = System::Drawing::Size(27, 196); this->pictureBox9->TabIndex = 8; this->pictureBox9->TabStop = false; // // pictureBox10 // this->pictureBox10->BackgroundImage = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"pictureBox10.BackgroundImage"))); this->pictureBox10->Location = System::Drawing::Point(318, 12); this->pictureBox10->Name = L"pictureBox10"; this->pictureBox10->Size = System::Drawing::Size(29, 196); this->pictureBox10->TabIndex = 9; this->pictureBox10->TabStop = false; // // pictureBox11 // this->pictureBox11->BackgroundImage = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"pictureBox11.BackgroundImage"))); this->pictureBox11->Location = System::Drawing::Point(353, 12); this->pictureBox11->Name = L"pictureBox11"; this->pictureBox11->Size = System::Drawing::Size(27, 196); this->pictureBox11->TabIndex = 10; this->pictureBox11->TabStop = false; // // pictureBox12 // this->pictureBox12->BackgroundImage = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"pictureBox12.BackgroundImage"))); this->pictureBox12->Location = System::Drawing::Point(386, 12); this->pictureBox12->Name = L"pictureBox12"; this->pictureBox12->Size = System::Drawing::Size(30, 196); this->pictureBox12->TabIndex = 11; this->pictureBox12->TabStop = false; // // pictureBox13 // this->pictureBox13->BackgroundImage = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"pictureBox13.BackgroundImage"))); this->pictureBox13->Location = System::Drawing::Point(422, 12); this->pictureBox13->Name = L"pictureBox13"; this->pictureBox13->Size = System::Drawing::Size(31, 196); this->pictureBox13->TabIndex = 12; this->pictureBox13->TabStop = false; // // pictureBox14 // this->pictureBox14->BackgroundImage = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"pictureBox14.BackgroundImage"))); this->pictureBox14->Location = System::Drawing::Point(459, 12); this->pictureBox14->Name = L"pictureBox14"; this->pictureBox14->Size = System::Drawing::Size(32, 196); this->pictureBox14->TabIndex = 13; this->pictureBox14->TabStop = false; // // pictureBox15 // this->pictureBox15->BackgroundImage = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"pictureBox15.BackgroundImage"))); this->pictureBox15->Location = System::Drawing::Point(497, 12); this->pictureBox15->Name = L"pictureBox15"; this->pictureBox15->Size = System::Drawing::Size(30, 196); this->pictureBox15->TabIndex = 14; this->pictureBox15->TabStop = false; // // pictureBox16 // this->pictureBox16->BackgroundImage = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"pictureBox16.BackgroundImage"))); this->pictureBox16->Location = System::Drawing::Point(533, 12); this->pictureBox16->Name = L"pictureBox16"; this->pictureBox16->Size = System::Drawing::Size(29, 196); this->pictureBox16->TabIndex = 15; this->pictureBox16->TabStop = false; // // pictureBox17 // this->pictureBox17->BackgroundImage = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"pictureBox17.BackgroundImage"))); this->pictureBox17->Location = System::Drawing::Point(568, 12); this->pictureBox17->Name = L"pictureBox17"; this->pictureBox17->Size = System::Drawing::Size(31, 196); this->pictureBox17->TabIndex = 16; this->pictureBox17->TabStop = false; // // pictureBox18 // this->pictureBox18->BackgroundImage = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"pictureBox18.BackgroundImage"))); this->pictureBox18->Location = System::Drawing::Point(605, 12); this->pictureBox18->Name = L"pictureBox18"; this->pictureBox18->Size = System::Drawing::Size(29, 196); this->pictureBox18->TabIndex = 17; this->pictureBox18->TabStop = false; // // pictureBox19 // this->pictureBox19->BackgroundImage = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"pictureBox19.BackgroundImage"))); this->pictureBox19->Location = System::Drawing::Point(640, 12); this->pictureBox19->Name = L"pictureBox19"; this->pictureBox19->Size = System::Drawing::Size(32, 196); this->pictureBox19->TabIndex = 18; this->pictureBox19->TabStop = false; // // pictureBox20 // this->pictureBox20->BackgroundImage = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"pictureBox20.BackgroundImage"))); this->pictureBox20->Location = System::Drawing::Point(678, 12); this->pictureBox20->Name = L"pictureBox20"; this->pictureBox20->Size = System::Drawing::Size(30, 196); this->pictureBox20->TabIndex = 19; this->pictureBox20->TabStop = false; // // button1 // this->button1->AccessibleName = L""; this->button1->BackgroundImage = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"button1.BackgroundImage"))); this->button1->ForeColor = System::Drawing::SystemColors::ControlLightLight; this->button1->Location = System::Drawing::Point(621, 330); this->button1->Name = L"button1"; this->button1->Size = System::Drawing::Size(103, 31); this->button1->TabIndex = 20; this->button1->Text = L"NEW GAME"; this->button1->UseVisualStyleBackColor = true; // // button2 // this->button2->BackgroundImage = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"button2.BackgroundImage"))); this->button2->Location = System::Drawing::Point(517, 330); this->button2->Name = L"button2"; this->button2->Size = System::Drawing::Size(82, 31); this->button2->TabIndex = 21; this->button2->Text = L"Ziehe 3"; this->button2->UseVisualStyleBackColor = true; this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click); // // button3 // this->button3->BackgroundImage = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"button3.BackgroundImage"))); this->button3->Location = System::Drawing::Point(416, 330); this->button3->Name = L"button3"; this->button3->Size = System::Drawing::Size(75, 31); this->button3->TabIndex = 22; this->button3->Text = L"Ziehe 2"; this->button3->UseVisualStyleBackColor = true; this->button3->Click += gcnew System::EventHandler(this, &Form1::button3_Click); // // button4 // this->button4->BackgroundImage = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"button4.BackgroundImage"))); this->button4->Location = System::Drawing::Point(318, 330); this->button4->Name = L"button4"; this->button4->Size = System::Drawing::Size(75, 31); this->button4->TabIndex = 23; this->button4->Text = L"Ziehe 1"; this->button4->UseVisualStyleBackColor = true; this->button4->Click += gcnew System::EventHandler(this, &Form1::button4_Click); // // textBox1 // this->textBox1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 40, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, static_cast<System::Byte>(0))); this->textBox1->Location = System::Drawing::Point(12, 239); this->textBox1->Multiline = true; this->textBox1->Name = L"textBox1"; this->textBox1->Size = System::Drawing::Size(688, 74); this->textBox1->TabIndex = 24; this->textBox1->TextChanged += gcnew System::EventHandler(this, &Form1::textBox1_TextChanged); // // Form1 // this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this->BackColor = System::Drawing::SystemColors::ControlLightLight; this->ClientSize = System::Drawing::Size(736, 388); this->Controls->Add(this->textBox1); this->Controls->Add(this->button4); this->Controls->Add(this->button3); this->Controls->Add(this->button2); this->Controls->Add(this->button1); this->Controls->Add(this->pictureBox20); this->Controls->Add(this->pictureBox19); this->Controls->Add(this->pictureBox18); this->Controls->Add(this->pictureBox17); this->Controls->Add(this->pictureBox16); this->Controls->Add(this->pictureBox15); this->Controls->Add(this->pictureBox14); this->Controls->Add(this->pictureBox13); this->Controls->Add(this->pictureBox12); this->Controls->Add(this->pictureBox11); this->Controls->Add(this->pictureBox10); this->Controls->Add(this->pictureBox9); this->Controls->Add(this->pictureBox8); this->Controls->Add(this->pictureBox7); this->Controls->Add(this->pictureBox6); this->Controls->Add(this->pictureBox5); this->Controls->Add(this->pictureBox4); this->Controls->Add(this->pictureBox3); this->Controls->Add(this->pictureBox2); this->Controls->Add(this->pictureBox1); this->Name = L"Form1"; this->Text = L"Form1"; this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->EndInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox2))->EndInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox3))->EndInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox4))->EndInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox5))->EndInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox6))->EndInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox7))->EndInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox8))->EndInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox9))->EndInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox10))->EndInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox11))->EndInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox12))->EndInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox13))->EndInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox14))->EndInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox15))->EndInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox16))->EndInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox17))->EndInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox18))->EndInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox19))->EndInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox20))->EndInit(); this->ResumeLayout(false); this->PerformLayout(); } #pragma endregion private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) { } private: System::Void pictureBox1_Click(System::Object^ sender, System::EventArgs^ e) { } private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) { pictureBox1->Image = Image::FromFile("Sth_transparent.jpg"); pictureBox2->Image = Image::FromFile("Sth_transparent.jpg"); pictureBox3->Image = Image::FromFile("Sth_transparent.jpg"); sth_anzahl=sth_anzahl-3; if (sth_anzahl<1) { textBox1->Text="G-A-M-E O-V-E-R"; } } public: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e) { pictureBox1->Image = Image::FromFile("Sth_transparent.jpg"); sth_anzahl=sth_anzahl-1; if (sth_anzahl<1) { textBox1->Text="G-A-M-E O-V-E-R"; } } private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) { pictureBox1->Image = Image::FromFile("Sth_transparent.jpg"); pictureBox2->Image = Image::FromFile("Sth_transparent.jpg"); sth_anzahl=sth_anzahl-2; if (sth_anzahl<1) { textBox1->Text="G-A-M-E O-V-E-R"; } } private: System::Void textBox1_TextChanged(System::Object^ sender, System::EventArgs^ e) { } }; }
http://www.bilder-space.de/show_img.php?img=0b010c-1303204096.jpg&size=original
Gruß
-
Habe grade in meinem anderen Thread diese Schleife gefunden:
for(i=0;i<20;++i) if(i<restzahl) picture[i] = transparent; else picture[i] = streichholz;
Finde ich spitze, verstehe ich auch. Es ist bloß das Problem, dass wenn ich es umsetzen will, diesen Befehl hier verwenden möchte:
pictureBox[i]->Image = Image::FromFile("Sth_transparent.jpg");
Doch dann gibt es einen Fehler, denn links von "->Image" darf nicht [i] stehen, sondern muss eine Zahl stehen. Ich weiß also nicht wie ich das jetzt umsetzen soll.
Gruß
-
Hat denn niemand einen Tipp?
Gruß
-
So Leute, ich hab es geschafft. Wie? Das verate ich euch am Ende des Projekts Ihr lacht euch sonst tot
Ich bräuchte nun noch Hilfe, wie ich den Computer mit in die Sache einbeziehe. Sodas ich und der Computer abwechselnd spielen.
Gruß
-
Schade - ich wollte dir gerade den Tip geben, die ganzen pictureBox'en in ein Array zu packen
Zur Beteiligung des Computers: Du solltest nach jedem Zug des Spielers eine Methode aufrufen, mit der der Computer eine Anzahl Streichhölzer auswählt (entweder zufällig oder mit Strategie) und die Anzeige aktualisiert.
Dabei fällt mir ein zu erwähnen, daß du diese Aktualisierung besser in eine eigene MEthode auslagern solltest.
-
Ja so ähnlich wie du es sagst, habe ich es mir auch gedacht, jedoch weiß ich grade gar nicht, wie ich eine eigene Methode für den Computer aufrufen kann ?!
Gruß
Achja, pictureboxen in ein Array packen, daran hatte ich auch gedacht, aber es hatte nicht so funktioniert, wie ich das wollte, habe es nun unglaublich simpel gelöst, mit unglaublich viel Quelltext
-
Motors-Freak schrieb:
Ja so ähnlich wie du es sagst, habe ich es mir auch gedacht, jedoch weiß ich grade gar nicht, wie ich eine eigene Methode für den Computer aufrufen kann ?!
Genauso wie du jede andere Methode auch aufrufen kannst. Eine Möglichkeit wäre am Ende der Button-Behandlungsroutinen (dort würde ich die gemeinsame Funktionaliät sowieso in eine eigene Funktion zusammenfassen)
Achja, pictureboxen in ein Array packen, daran hatte ich auch gedacht, aber es hatte nicht so funktioniert, wie ich das wollte, habe es nun unglaublich simpel gelöst, mit unglaublich viel Quelltext
Warum habe ich jetzt eine Schleife mit einem geschachtelten switch() vor Augen? Und was genau hat mit dem Array nicht funktioniert?
(PS: Es gibt sicher auch ein paar andere Containerklassen, die du zum Zusammenfassen der ganzen pictureBox'en verwenden kannst)
-
Hallo,
habe das Prgramm fertig mit vielen Funktionen. Danke euch allen.
Werde das Prgramm bei Zeiten online stellen.Nun aber eine Frage:
Beim Debuggen wird automatisch eine .exe erstellt, jedoch wird diese nicht aktualisiert? Alle Datein im Ordner "Debugg" sind immer aktuell, auser die .exe, diese hat das Änderungsdatum XXX also ein was schon 2 Wochen alt ist. Lösche ich den Ordner Debugg erstellt er ihn neu OHNE .exe.Wie bekomme ich eine neue aktuelle .exe?
Gruß