Problem z odwoływaniem się do tablicy z innej klasy

0

Witam serdeczniee!
To znowu ja z jakże wielkim problemem dla początkującego. Otóż stworzyłem klasę Gra, a w niej tablicę. Problem polega na tym, że nie umiem wykorzystać tej tablicy w innej klasie. Od razu dodam, że z funkcjami oraz zmiennymi nie mam takiego problemu. Poniżej fragmenty kodów tych dwóch klas.

KLASA GRA

class Gra
{

      public:
	bool poprawnosc_obstawienia[12];

	public:
		Gra();
		Gra(const Gra &gra);
};

Gra::Gra()
{
	for (int i=0; i<12; i++)
		{
			poprawnosc_obstawienia[i] = false;
		}
}

KLASA FORM1.H

#include "Gra.h"

namespace RULETKA12 {

	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>
	/// Summary for Form1
	///
	/// WARNING: If you change the name of this class, you will need to change the
	///          'Resource File Name' property for the managed resource compiler tool
	///          associated with all .resx files this class depends on.  Otherwise,
	///          the designers will not be able to interact properly with localized
	///          resources associated with this form.
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
		
	public:
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
			obstawiana_suma_pieniedzy = 0;
			kredyt = 200;
			potencjalna_wygrana = 0;
			
		}
	

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
				if(this->gra)
			{
				delete this->gra;
			}
		}
	
	private: Gra *gra;





	protected: 
	
	private: System::Windows::Forms::PictureBox^  pictureBox1;
	private: System::Windows::Forms::PictureBox^  pictureBox12;
	public: 

	private: System::Windows::Forms::PictureBox^  pictureBox11;

	private: System::Windows::Forms::PictureBox^  pictureBox10;

	private: System::Windows::Forms::PictureBox^  pictureBox9;

	private: System::Windows::Forms::PictureBox^  pictureBox8;

	private: System::Windows::Forms::PictureBox^  pictureBox7;

	private: System::Windows::Forms::PictureBox^  pictureBox6;

	private: System::Windows::Forms::PictureBox^  pictureBox5;

	private: System::Windows::Forms::PictureBox^  pictureBox4;

	private: System::Windows::Forms::PictureBox^  pictureBox3;

	private: System::Windows::Forms::PictureBox^  pictureBox2;

	private: System::Windows::Forms::Button^  button_losuj;
	private: System::Windows::Forms::TextBox^  textBox;
	private: System::Windows::Forms::Button^  button_5zl;




	public: int obstawiana_suma_pieniedzy; // zmienna sluzy do zapamietania ile pieniedzy obstawiamy w jednym momencie
	public: int kredyt; //zmienna sluzy do zapamietania ilosci pieniedzy grazcza
	public: int potencjalna_wygrana; //zmienna sluzy do zapamietania ile pieniedzy gracz postawil w calej rundzie
	



		
	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
			this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
			this->pictureBox12 = (gcnew System::Windows::Forms::PictureBox());
			this->pictureBox11 = (gcnew System::Windows::Forms::PictureBox());
			this->pictureBox10 = (gcnew System::Windows::Forms::PictureBox());
			this->pictureBox9 = (gcnew System::Windows::Forms::PictureBox());
			this->pictureBox8 = (gcnew System::Windows::Forms::PictureBox());
			this->pictureBox7 = (gcnew System::Windows::Forms::PictureBox());
			this->pictureBox6 = (gcnew System::Windows::Forms::PictureBox());
			this->pictureBox5 = (gcnew System::Windows::Forms::PictureBox());
			this->pictureBox4 = (gcnew System::Windows::Forms::PictureBox());
			this->pictureBox3 = (gcnew System::Windows::Forms::PictureBox());
			this->pictureBox2 = (gcnew System::Windows::Forms::PictureBox());
			this->button_losuj = (gcnew System::Windows::Forms::Button());
			this->textBox = (gcnew System::Windows::Forms::TextBox());
			this->button_5zl = (gcnew System::Windows::Forms::Button());
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox1))->BeginInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox12))->BeginInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox11))->BeginInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox10))->BeginInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox9))->BeginInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox8))->BeginInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox7))->BeginInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox6))->BeginInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox5))->BeginInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox4))->BeginInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox3))->BeginInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox2))->BeginInit();
			this->SuspendLayout();
			// 
			// pictureBox1
			// 
			this->pictureBox1->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"pictureBox1.Image")));
			this->pictureBox1->Location = System::Drawing::Point(49, 121);
			this->pictureBox1->Name = L"pictureBox1";
			this->pictureBox1->Size = System::Drawing::Size(67, 39);
			this->pictureBox1->TabIndex = 0;
			this->pictureBox1->TabStop = false;
			this->pictureBox1->Click += gcnew System::EventHandler(this, &Form1::pictureBox1_Click);
			// 
			// pictureBox12
			// 
			this->pictureBox12->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"pictureBox12.Image")));
			this->pictureBox12->Location = System::Drawing::Point(852, 121);
			this->pictureBox12->Name = L"pictureBox12";
			this->pictureBox12->Size = System::Drawing::Size(67, 39);
			this->pictureBox12->TabIndex = 12;
			this->pictureBox12->TabStop = false;
			// 
			// pictureBox11
			// 
			this->pictureBox11->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"pictureBox11.Image")));
			this->pictureBox11->Location = System::Drawing::Point(779, 121);
			this->pictureBox11->Name = L"pictureBox11";
			this->pictureBox11->Size = System::Drawing::Size(67, 39);
			this->pictureBox11->TabIndex = 13;
			this->pictureBox11->TabStop = false;
			// 
			// pictureBox10
			// 
			this->pictureBox10->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"pictureBox10.Image")));
			this->pictureBox10->Location = System::Drawing::Point(705, 121);
			this->pictureBox10->Name = L"pictureBox10";
			this->pictureBox10->Size = System::Drawing::Size(67, 39);
			this->pictureBox10->TabIndex = 14;
			this->pictureBox10->TabStop = false;
			// 
			// pictureBox9
			// 
			this->pictureBox9->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"pictureBox9.Image")));
			this->pictureBox9->Location = System::Drawing::Point(632, 121);
			this->pictureBox9->Name = L"pictureBox9";
			this->pictureBox9->Size = System::Drawing::Size(67, 39);
			this->pictureBox9->TabIndex = 15;
			this->pictureBox9->TabStop = false;
			// 
			// pictureBox8
			// 
			this->pictureBox8->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"pictureBox8.Image")));
			this->pictureBox8->Location = System::Drawing::Point(559, 121);
			this->pictureBox8->Name = L"pictureBox8";
			this->pictureBox8->Size = System::Drawing::Size(67, 39);
			this->pictureBox8->TabIndex = 16;
			this->pictureBox8->TabStop = false;
			// 
			// pictureBox7
			// 
			this->pictureBox7->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"pictureBox7.Image")));
			this->pictureBox7->Location = System::Drawing::Point(486, 121);
			this->pictureBox7->Name = L"pictureBox7";
			this->pictureBox7->Size = System::Drawing::Size(67, 39);
			this->pictureBox7->TabIndex = 17;
			this->pictureBox7->TabStop = false;
			// 
			// pictureBox6
			// 
			this->pictureBox6->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"pictureBox6.Image")));
			this->pictureBox6->Location = System::Drawing::Point(413, 121);
			this->pictureBox6->Name = L"pictureBox6";
			this->pictureBox6->Size = System::Drawing::Size(67, 39);
			this->pictureBox6->TabIndex = 18;
			this->pictureBox6->TabStop = false;
			// 
			// pictureBox5
			// 
			this->pictureBox5->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"pictureBox5.Image")));
			this->pictureBox5->Location = System::Drawing::Point(341, 121);
			this->pictureBox5->Name = L"pictureBox5";
			this->pictureBox5->Size = System::Drawing::Size(67, 39);
			this->pictureBox5->TabIndex = 19;
			this->pictureBox5->TabStop = false;
			// 
			// pictureBox4
			// 
			this->pictureBox4->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"pictureBox4.Image")));
			this->pictureBox4->Location = System::Drawing::Point(268, 121);
			this->pictureBox4->Name = L"pictureBox4";
			this->pictureBox4->Size = System::Drawing::Size(67, 39);
			this->pictureBox4->TabIndex = 20;
			this->pictureBox4->TabStop = false;
			// 
			// pictureBox3
			// 
			this->pictureBox3->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"pictureBox3.Image")));
			this->pictureBox3->Location = System::Drawing::Point(195, 121);
			this->pictureBox3->Name = L"pictureBox3";
			this->pictureBox3->Size = System::Drawing::Size(67, 39);
			this->pictureBox3->TabIndex = 21;
			this->pictureBox3->TabStop = false;
			// 
			// pictureBox2
			// 
			this->pictureBox2->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"pictureBox2.Image")));
			this->pictureBox2->Location = System::Drawing::Point(122, 121);
			this->pictureBox2->Name = L"pictureBox2";
			this->pictureBox2->Size = System::Drawing::Size(67, 39);
			this->pictureBox2->TabIndex = 22;
			this->pictureBox2->TabStop = false;
			// 
			// button_losuj
			// 
			this->button_losuj->BackColor = System::Drawing::Color::Gold;
			this->button_losuj->Font = (gcnew System::Drawing::Font(L"Wide Latin", 21.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->button_losuj->ForeColor = System::Drawing::Color::DimGray;
			this->button_losuj->Location = System::Drawing::Point(705, 420);
			this->button_losuj->Name = L"button_losuj";
			this->button_losuj->Size = System::Drawing::Size(245, 109);
			this->button_losuj->TabIndex = 23;
			this->button_losuj->Text = L"LOSUJ";
			this->button_losuj->UseVisualStyleBackColor = false;
			this->button_losuj->Click += gcnew System::EventHandler(this, &Form1::button_losuj_Click);
			// 
			// textBox
			// 
			this->textBox->BackColor = System::Drawing::SystemColors::ControlLightLight;
			this->textBox->Location = System::Drawing::Point(13, 420);
			this->textBox->Multiline = true;
			this->textBox->Name = L"textBox";
			this->textBox->ScrollBars = System::Windows::Forms::ScrollBars::Vertical;
			this->textBox->Size = System::Drawing::Size(540, 109);
			this->textBox->TabIndex = 24;
			this->textBox->Text = L"Witaj w rultece!!!!";
			// 
			// button_5zl
			// 
			this->button_5zl->BackColor = System::Drawing::Color::Lime;
			this->button_5zl->ForeColor = System::Drawing::Color::Black;
			this->button_5zl->Location = System::Drawing::Point(573, 420);
			this->button_5zl->Name = L"button_5zl";
			this->button_5zl->Size = System::Drawing::Size(43, 41);
			this->button_5zl->TabIndex = 25;
			this->button_5zl->Text = L"5";
			this->button_5zl->UseVisualStyleBackColor = false;
			this->button_5zl->Click += gcnew System::EventHandler(this, &Form1::button_5zl_Click_1);
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(962, 541);
			this->Controls->Add(this->button_5zl);
			this->Controls->Add(this->textBox);
			this->Controls->Add(this->button_losuj);
			this->Controls->Add(this->pictureBox2);
			this->Controls->Add(this->pictureBox3);
			this->Controls->Add(this->pictureBox4);
			this->Controls->Add(this->pictureBox5);
			this->Controls->Add(this->pictureBox6);
			this->Controls->Add(this->pictureBox7);
			this->Controls->Add(this->pictureBox8);
			this->Controls->Add(this->pictureBox9);
			this->Controls->Add(this->pictureBox10);
			this->Controls->Add(this->pictureBox11);
			this->Controls->Add(this->pictureBox12);
			this->Controls->Add(this->pictureBox1);
			this->ForeColor = System::Drawing::Color::White;
			this->Name = L"Form1";
			this->Text = L"Form1";
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox1))->EndInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox12))->EndInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox11))->EndInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox10))->EndInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox9))->EndInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox8))->EndInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox7))->EndInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox6))->EndInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox5))->EndInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox4))->EndInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox3))->EndInit();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox2))->EndInit();
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion
	
private: System::Void button_losuj_Click(System::Object^  sender, System::EventArgs^  e) 
		 {
			 ////SLUZY DO NUMERACJI LICZB
			 int obstawiana_liczba[12];
			 for (int i=0; i<12; i++)
				{
					obstawiana_liczba[i] = i + 1;
				}

			
				
			//////
			
			//SLUZY DO WYLOSOWANIA LICZBY

			 /////////
			 int los;
			 los = gra->losuj();
			 this->textBox->Text += "\n Wylosowana liczba to: " + los;
			//////

			 //SLUZY DO SPRAWDZENIA CZY GRACZ OBSTAWIL WYLOSOWANA LICZBE

			 /////
			 for (int i=0; i<12; i++)
			 {
				this->textBox->Text += "\n Sprawdzam obstawiana liczbe: " + obstawiana_liczba[i];
				 if(obstawiana_liczba[i] == los && gra->poprawnosc_obstawienia[i] == true)
				 {
					kredyt += potencjalna_wygrana;
					this->textBox->Text += "\n Wygrales! Twoj kredyt to: " + kredyt;
				 }
			 }
			//////

			 /// ZERUJE POPRAWNOSC OBSTAWIENIA

			 /////
			 for (int i=0; i<12; i++)
				{
					gra->poprawnosc_obstawienia[i] = false;
				}
		 }
private: System::Void button_5zl_Click_1(System::Object^  sender, System::EventArgs^  e) {
			 obstawiana_suma_pieniedzy = 5;
			 
		 }
private: System::Void pictureBox1_Click(System::Object^  sender, System::EventArgs^  e) {
			 if (obstawiana_suma_pieniedzy != 0)
			 {
				gra->poprawnosc_obstawienia[0] = true;
				this->textBox->Text += "\n obstawiono " + obstawiana_suma_pieniedzy + "zl na liczbe 1";
				//gra->kredyt - obstawiana;
				kredyt = kredyt - obstawiana_suma_pieniedzy;
				this->textBox->Text += "\n Zostalo Ci " + kredyt + "zlotych";
				potencjalna_wygrana += obstawiana_suma_pieniedzy;
				obstawiana_suma_pieniedzy = 0;
			 }
		 }
};
}

0

Gdzie tworzysz i przypisujesz obiekt do Form1::gra?

1 użytkowników online, w tym zalogowanych: 0, gości: 1