Бесконечный цикл с выходом при условии ,не выходит даже после return - C#
Формулировка задачи:
private void start()
{
testboi();
}
private void testboi()
{
provesti_1_boi();
MessageBox.Show("Вышли из цикла боя.");
}
#region Функция проведения 1 боя
private void provesti_1_boi()
{
zapusk_poiska_hp();
AutoItX3 au3 = new AutoItX3();
ImageSearch img = new ImageSearch();
int pitgigda = 1;
while (true)
{
int y = au3.WinGetPosY("Raga Dwar Bot C#");
int x = au3.WinGetPosX("Raga Dwar Bot C#");
this.toolStripStatusLabel2.Text = ("Ищу");
string col_udarov_read = au3.IniRead("settings.ini", "SU", "udarov", "");
int mochnaudar = Convert.ToInt32(au3.IniRead("settings.ini", "boevaya_sistema", "nas3data", ""));
int krovnaudar = Convert.ToInt32(au3.IniRead("settings.ini", "boevaya_sistema", "nas4data", ""));
int vampnaudar = Convert.ToInt32(au3.IniRead("settings.ini", "boevaya_sistema", "nas5data", ""));
int col_udarov = Convert.ToUInt16(col_udarov_read);
var end_battle1 = img.CapSearchBmp(435, 249, 509, 282, "img/main/end_battle.bmp", "temp.bmp", 0, "Raga Dwar Bot C#");
if (end_battle1.Location.X > 1)
{
au3.MouseClick("LEFT", x + 479, y + 371, 1, 0); // выход из боя
Thread.Sleep(2000);
foreach (Thread potokhp in threads) potokhp.Abort();
this.toolStripStatusLabel2.Text = ("Вышел из цикла");
// Если бой закончен выходим из provesti_1_boi() и возвращаемся в testboi()
return;
}
for (int i = 0; i < col_udarov; )
{
var need_udar = img.CapSearchBmp(414, 410, 452, 443, "img/main/need_udar.bmp", "temp.bmp", 0, "Raga Dwar Bot C#");
var end_battle = img.CapSearchBmp(435, 249, 509, 282, "img/main/end_battle.bmp", "temp.bmp", 0, "Raga Dwar Bot C#");
if (end_battle.Location.X > 1)
{
break;
// Если бой закончен выходим из цикла For
}
if (need_udar.Location.X > 1)
{
if (au3.IniRead("settings.ini", "boevaya_sistema", "nas6", "") == "da" && i == 0)
{
au3.MouseClick("LEFT", 363 + x, 374 + y, 1, 0);
Thread.Sleep(200);
}
if (au3.IniRead("settings.ini", "boevaya_sistema", "nas6", "") == "da" && i == col_udarov - 1)
{
au3.MouseClick("LEFT", 363 + x, 374 + y, 1, 0);
Thread.Sleep(200);
}
if (pitgigda == 1)
{
pitgig();
pitgigda = 0;
}
if (i == mochnaudar - 1)
{
mosh();
}
if (i == krovnaudar - 1)
{
krov();
}
if (i == vampnaudar - 1)
{
vamp();
}
string udarit = au3.IniRead("settings.ini", "SU", "udar" + i, "");
if (udarit == "1")
{
pitjizniqq();
toolStripStatusLabel2.Text = "Удар в голову";
au3.MouseClick("LEFT", x + 447, y + 317, 1, 0); // удар по голове
Thread.Sleep(2500);
i++;
}
if (udarit == "2")
{
pitjizniqq();
toolStripStatusLabel2.Text = "Удар в корпус";
au3.MouseClick("LEFT", x + 475, y + 369, 1, 0); // удар по телу
Thread.Sleep(2500);
i++;
}
if (udarit == "3")
{
pitjizniqq();
toolStripStatusLabel2.Text = "Удар в ноги";
au3.MouseClick("LEFT", x + 449, y + 419, 1, 0); // удар по ногам
Thread.Sleep(2500);
i++;
}
}
else if (need_udar.Location.X < 1)
{
this.toolStripStatusLabel2.Text = ("Не нашел... ищу");
Thread.Sleep(150);
}
}
}
}
#endregionРешение задачи: «Бесконечный цикл с выходом при условии ,не выходит даже после return»
textual
Листинг программы
#region Функция проведения 1 боя
private void provesti_1_boi()
{
zapusk_poiska_hp();
AutoItX3 au3 = new AutoItX3();
ImageSearch img = new ImageSearch();
int pitgigda = 1;
while (true)
{
int y = au3.WinGetPosY("Raga Dwar Bot C#");
int x = au3.WinGetPosX("Raga Dwar Bot C#");
this.toolStripStatusLabel2.Text = ("Ищу");
string col_udarov_read = au3.IniRead("settings.ini", "SU", "udarov", "");
int mochnaudar = Convert.ToInt32(au3.IniRead("settings.ini", "boevaya_sistema", "nas3data", ""));
int krovnaudar = Convert.ToInt32(au3.IniRead("settings.ini", "boevaya_sistema", "nas4data", ""));
int vampnaudar = Convert.ToInt32(au3.IniRead("settings.ini", "boevaya_sistema", "nas5data", ""));
int col_udarov = Convert.ToUInt16(col_udarov_read);
var end_battle1 = img.CapSearchBmp(435, 249, 509, 282, "img/main/end_battle.bmp", "temp.bmp", 0, "Raga Dwar Bot C#");
if (end_battle1.Location.X > 1)
{
au3.MouseClick("LEFT", x + 479, y + 371, 1, 0); // выход из боя
Thread.Sleep(2000);
foreach (Thread potokhp in threads) potokhp.Abort();
this.toolStripStatusLabel2.Text = ("Вышел из цикла");
goto test;
}
for (int i = 0; i < col_udarov; )
{
var need_udar = img.CapSearchBmp(414, 410, 452, 443, "img/main/need_udar.bmp", "temp.bmp", 0, "Raga Dwar Bot C#");
var end_battle = img.CapSearchBmp(435, 249, 509, 282, "img/main/end_battle.bmp", "temp.bmp", 0, "Raga Dwar Bot C#");
if (end_battle.Location.X > 1)
{
break;
}
if (need_udar.Location.X > 1)
{
if (au3.IniRead("settings.ini", "boevaya_sistema", "nas6", "") == "da" && i == 0)
{
au3.MouseClick("LEFT", 363 + x, 374 + y, 1, 0);
Thread.Sleep(200);
}
if (au3.IniRead("settings.ini", "boevaya_sistema", "nas6", "") == "da" && i == col_udarov - 1)
{
au3.MouseClick("LEFT", 363 + x, 374 + y, 1, 0);
Thread.Sleep(200);
}
if (pitgigda == 1)
{
pitgig();
pitgigda = 0;
}
if (i == mochnaudar - 1)
{
mosh();
}
if (i == krovnaudar - 1)
{
krov();
}
if (i == vampnaudar - 1)
{
vamp();
}
string udarit = au3.IniRead("settings.ini", "SU", "udar" + i, "");
if (udarit == "1")
{
pitjizniqq();
toolStripStatusLabel2.Text = "Удар в голову";
au3.MouseClick("LEFT", x + 447, y + 317, 1, 0); // удар по голове
Thread.Sleep(2500);
i++;
}
if (udarit == "2")
{
pitjizniqq();
toolStripStatusLabel2.Text = "Удар в корпус";
au3.MouseClick("LEFT", x + 475, y + 369, 1, 0); // удар по телу
Thread.Sleep(2500);
i++;
}
if (udarit == "3")
{
pitjizniqq();
toolStripStatusLabel2.Text = "Удар в ноги";
au3.MouseClick("LEFT", x + 449, y + 419, 1, 0); // удар по ногам
Thread.Sleep(2500);
i++;
}
}
else if (need_udar.Location.X < 1)
{
this.toolStripStatusLabel2.Text = ("Не нашел... ищу");
Thread.Sleep(150);
}
}
test:
{
return;
}
}
}
#endregion