Semi-automatic bot for the game "Farm Frenzy"

Good evening, readers of Habr! Recently, one person showed a macro bot for the browser-based game Diamond Dash, a post . And he did everything using the macro language AutoIt. And I remembered that I used the AutoIt library to develop a semi-automatic bot in C #.
As I developed, see below ...

Necessary tools for work


  • VisualStudio 2010 itself
  • C # Skills
  • And AutoIt library

The first thing I downloaded was AutoIt ( AutoIt Full Installation ) and installed it. Then he added a library to VisualStudio. I don’t know why, but I couldn’t use the library without installing the exe file.

Beginning of work


The essence of my program was that I needed to select a rectangle and then use its hot keys to indicate its position, and also to indicate how many fields were in it.
For instance:
image
  • The position of the rectangle is given by points 1.1, 1.n, n.1.
  • Height 4
  • Width 3


Hotkeys:

To use hot keys, I used a class found on the Internet , which used hot keys not only with the application active window, but also with the inactive one.

My hotkey code: We get 3 hotkeys: Shift + Q, Shift + W, Shift + E, which execute the events position1, position2 and position3. You can use not only Shift but also Ctrl, Alt, Win or nothing.

HotKey[] Key = new HotKey[4];
Key[1] = new HotKey();
Key[2] = new HotKey();
Key[3] = new HotKey();
Key[1].KeyModifier = HotKey.KeyModifiers.Shift;
Key[1].Key = Keys.Q;
Key[1].HotKeyPressed += new KeyEventHandler(position1);
Key[2].KeyModifier = HotKey.KeyModifiers.Shift;
Key[2].Key = Keys.W;
Key[2].HotKeyPressed += new KeyEventHandler(position2);
Key[3].KeyModifier = HotKey.KeyModifiers.Shift;
Key[3].Key = Keys.E;
Key[3].HotKeyPressed += new KeyEventHandler(position3);





Calculation of points for a "click":

We pass the program the position for calculating the grid on which you want to make clicks.

Calculation Code: Parameters:

private void button1_Click(object sender, EventArgs e)
{
int shirina = Convert.ToInt32(textBox4.Text);
int Vnax, Vnay, Vx, Vy, Nx, Ny;
Vx = Convert.ToInt32(textBox1.Text);
Vy = Convert.ToInt32(textBox2.Text);
Nx = Convert.ToInt32(textBox3.Text);
Ny = Convert.ToInt32(textBox6.Text);
Vnax = (Convert.ToInt32(textBox7.Text) - Convert.ToInt32(textBox1.Text)) / (shirina - 1);
Vnay = (Convert.ToInt32(textBox2.Text) - Convert.ToInt32(textBox8.Text)) / (shirina - 1);
for (int i = 1; i <= shirina; i++)
{
Shag(Vx, Vy, Nx, Ny);
Vx += Vnax;
Vy -= Vnay;
Nx += Vnax;
Ny -= Vnay;
}
}
private void Shag(int Vx, int Vy, int Nx, int Ny)
{
int vysota = Convert.ToInt32(textBox5.Text);
int nax, nay, x, y;
int nS = 4;
int nCout = 1;
String Str = "left";
nax = (Nx - Vx) / (vysota - 1);
nay = (Ny - Vy) / (vysota - 1);
x = Vx;
y = Vy;
for (int i = 1; i <= vysota; i++)
{
autoIt.MouseClick(Str, x, y, nCout, nS);
x += nax;
y += nay;
}



  • Vx, Vy the top position of the point
  • Nx, Ny lower point position


And the most interesting thing in the Shag method , in which we call the method from the AutoIt MouseClick library, its parameters:

  • x, y - point position for click
  • nS - cursor movement speed from one point to another
  • nCout - number of clicks
  • Str - which button to click, right or left


Well, that's all I have shown you. Sources of my program: Download .

A small video of the application:



  • I don’t know why the cursor disappeared but in the previous. watching he was. Used Camtasia
  • pressing hangs a little, my weak beech is guilty of this + Camtasia loaded the system well
  • and yet, the accuracy of clicks depends on the correct determination of the position of the area for “clicking”


PS: I express my gratitude to my mother, who once asked me to come up with how to spend less time on the Merry Farm applications, but since she couldn’t refuse anything, I wrote this program. At first I had to teach her a little how to use the program, but now she is happy.

Thanks to all.

Also popular now: