C++ GUI BattleShip

I am really new to the gui side of c++. The problem that I am running into is I have 2 board one for the player and one for the comp. I am trying to creates a function that works with the onclick listen or eventhandler so I can place my ship but not really understanding how it work, so any help would be appreciated
The code is 3500 lines long so I'm not going to burden any one with that so I will just put he section where I am having the problem.

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
  private: void P1_Ship_Sel(System::Object^  sender)
			{
			Button^ button = (Button^)sender;
			int i,j, fininshed;
			bool done = false;
			if (fininshed <= 0)
			{
			//while(!done)
			//{
				for (i = 0; i < carrier; i++)
				{
					button->Text = L"C";
					button->BackColor = System::Drawing::Color::Green;
				}
			//done = true;
			
			
				/*{
					for (j = 0; j < battleship; j++)
				{
					button->Text = L"BS";
					button->BackColor = System::Drawing::Color::Green;
				}
				}*/
			//}//END OF WHILE
			///if (i == carrier)
			fininshed ++;
			}// END OF IF
			
			}

	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
			Button^ button = (Button^)sender;
			int done;
			if(done <= 0)
			{
			P1_Ship_Sel(sender);
			
			}
			done++;
			/*if(button->Text == L"WATER"){
				button->Text = L"MISS";				
				button->BackColor = System::Drawing::Color::Red;
				button->Enabled = false;
				miss++;
				this->P_MISSES->Text = L"Misses: " + miss;
			}
			else{
				button->BackColor = System::Drawing::Color::Green;
				button->Text = L"HIT";
				button->Enabled = false;
				hit++;
				this->P_HITS->Text = L"Hits: " + hit;
				 }*/
			 }


I am still trying to figure out how the GUIs work. it just constantly calls the p1_ship_sel, so just keep putting "C" in all the buttons
Last edited on
I am trying to creates a function that works with the onclick listen or event handler so I can place my ship but not really understanding how it work


It's not really clear what you want to do.What should happen when you click a button?
in the function where I change the text to "C" it is only suppose to do that six times then stop, but it lets me place it infinites times and I don't want to do that. Basically when I call it in the void button_1Click it stay in the p1_ship_sel function.
I still don't understand. You set the text for the same button multiple times to the same value. Shouldn't you change different buttons ?
1
2
3
4
5
for (i = 0; i < carrier; i++)
{
  button->Text = L"C";
  button->BackColor = System::Drawing::Color::Green;
}
Topic archived. No new replies allowed.