所以我正在尝试制作一个机器人应用程序,试图看看我如何在c#中做某些事情。我不是想欺骗,所以,这是我在模拟器上运行的手机游戏。这不是我试图销售或以任何方式从中获利的应用程序,这对我来说只是一项学习如何做这些事情的任务。
当我启动应用程序时,内存会立即达到16 MB,我也会尝试循环直到单击一个停止按钮。
我为每一个动作创建函数,我正在使用一个计时器运行所有函数来扫描是否检测到一个像素,但是应用程序运行缓慢且占用了大量内存,我觉得这样的“循环“不是执行此类操作的正确方法,我也尝试过while
方法。
有谁愿意告诉我我在做什么?
private void timer1_Tick(object sender, EventArgs e)
{
if (timer1.Enabled == true)
{
// Checking if we entered Dragon's B10
if (inDungeon == false)
{
GoToDungeon();
}
// Starting battle
autoSumPoint = AutoIt.AutoItX.PixelGetColor(2078, 61); // 0xF1EECF
if (autoSumPoint == 0xF1EECF)
{
StartBattle();
}
else
{
GoToDungeon();
}
// Starting auto-play
autoSumPoint = AutoIt.AutoItX.PixelGetColor(2296, 969); // 0xFFFFFF
if (autoSumPoint == 0xFFFFFF)
{
AutoCheck();
}
// Starting battle
autoSumPoint = AutoIt.AutoItX.PixelGetColor(2755, 489); // 0xF1EECF
if (autoSumPoint == 0xF1EECF)
{
PauseCheck();
}
// Checking for defeat
if (defeatChecked == false)
{
DefeatCheck();
}
// Checking for defeat
if (defeatChecked == false)
{
DefeatCheck();
}
// Checking for victory
if (victoryChecked == false)
{
VictoryCheck();
}
// Checking for replay
autoSumPoint = AutoIt.AutoItX.PixelGetColor(2602, 587); // 0xF3C761
if (autoSumPoint == 0xF3C761)
{
ReplayCheck();
}
// Checking for refill
if (energyRefilled == false)
{
RefillCheck();
}
}
}
答案 0 :(得分:0)
我会考虑更改定时器每个滴答之间的延迟,这样它就不会烧坏你的CPU。
private void timer1_Tick(object sender, EventArgs e)
{
if (timer1.Enabled == true)
{
// Checking if we entered Dragon's B10
if (inDungeon == false)
{
GoToDungeon();
}
// Starting battle
autoSumPoint = AutoIt.AutoItX.PixelGetColor(2078, 61); // 0xF1EECF
if (autoSumPoint == 0xF1EECF)
{
StartBattle();
}
else
{
GoToDungeon();
}
// Starting auto-play
autoSumPoint = AutoIt.AutoItX.PixelGetColor(2296, 969); // 0xFFFFFF
if (autoSumPoint == 0xFFFFFF)
{
AutoCheck();
}
// Starting battle
autoSumPoint = AutoIt.AutoItX.PixelGetColor(2755, 489); // 0xF1EECF
if (autoSumPoint == 0xF1EECF)
{
PauseCheck();
}
// Checking for defeat
if (defeatChecked == false)
{
DefeatCheck();
}
// Checking for defeat
if (defeatChecked == false)
{
DefeatCheck();
}
// Checking for victory
if (victoryChecked == false)
{
VictoryCheck();
}
// Checking for replay
autoSumPoint = AutoIt.AutoItX.PixelGetColor(2602, 587); // 0xF3C761
if (autoSumPoint == 0xF3C761)
{
ReplayCheck();
}
// Checking for refill
if (energyRefilled == false)
{
RefillCheck();
}
}
System.Threading.Thread.Sleep(1000)//causes it to wait 1 second after each tick before the next one to reduce CPU usage
}
看看这对你有帮助!
Techcraft7:)