c++ - Mouse stops working after changing function -


i'm making console board game on c++, , i've been able make mouse work in first function, menu one, however, when getmove function , need click on house, doesn't work.. can help? class mouse.

#include <cstdlib> #include <iostream> #include <process.h> #include <windows.h> #include <time.h> #include <stdio.h> using namespace std; void game(); int chu(); int rato(int &row, int &col) {     handle hin;     hin = getstdhandle(std_input_handle);     bool continue = true;     input_record inrec;     dword numread;     hwnd window = getconsolewindow();     point cursorpos;     rect wpos;     int x = 0;     int y = 0;      //cout << hin << endl;     flushconsoleinputbuffer(hin);     while (continue) {         readconsoleinput(hin, &inrec, 1, &numread);         switch (inrec.eventtype)         {         case mouse_event: if (getasynckeystate(vk_lbutton))         {                               cout << "rato"<<endl;                               getwindowrect(window, &wpos);                               getcursorpos(&cursorpos);                               cursorpos.x -= wpos.left;                               cursorpos.y -= wpos.top;                               x = (cursorpos.x - 5) / 16;                               y = (cursorpos.y - 25) / 24;                               cout << x << " " << y << endl;                               row = x; col = y;                               return row;                         }                           else if (getasynckeystate(vk_rbutton)){                               getwindowrect(window, &wpos);                               getcursorpos(&cursorpos);                               cursorpos.x -= wpos.left;                               cursorpos.y -= wpos.top;                               x = (cursorpos.x - 5) / 16;                               y = (cursorpos.y - 25) / 24;                               cout << x << " " << y << endl;                               row = x; col = y;                               return row;                           }                           break;         }     }  }    int main() {     cout << "\n\n\n   click on stars" << endl;      cout << "        \n\n\n *******" << endl;      int z = 0;     int x = 0;     int y = 0;     int xo = 0;        switch (rato(x,y))      {     case 1: game(); break;     case 2: game(); break;     case 3: game(); break;     case 4: rato(x, y); break;     case 5: rato(x, y); break;     case 6: game(); break;     case 7: game(); break;     case 8: game(); break;     case 9: game(); break;      default: cout << "click again"; break;      }                       return 0;                 }  void game() {     int x = 0;     int y = 0;     int = 0;      cout << "game" << endl;     do{         i++;         rato(x, y);     } while (i <= 2);      chu(); }  int chu() {     int x = 0;     int y = 0;     int = 0;     int b = 0;     int xo = 0;     int yo = 0;      cout << "\   click on stars" << endl;      handle  hconsole;     hconsole = getstdhandle(std_output_handle);      do{         xo = rato(x, y);         if (0 <= xo && xo <= 5) { = 1;}         else cout << "click again" << endl;     } while (xo!=0);      cout << a;      return a;     system("pause");   } 

you need define game board clickable x y regions on console window , have mouse events each board section's x , y coordinates processed in loop. each board section needs x y , , if board has 8x8 sections require alot of x y regions processed in mouse event loop.

a x , y region can defined this:

      if ((mousex>1) && (mousex<8) && (mousey>1) && (mousey<4))       {        } 

if 3x3 tic tac toe console board game, require 3x3 = 9 separate x , y regions , 9 if(mouse... statements.

code simple mouse click event:

#include <iostream> #include <stdlib.h> #include <windows.h> using namespace std;   int main() {      cout<<"click anywhere in console window write - hello world -\n\n\n\n\n\n\n\n\n\n\n\n\n"     "press ctrl+c exit";           handle hout= getstdhandle(std_output_handle);         handle hin = getstdhandle(std_input_handle);          input_record inputrecord;          dword events;          coord coord;         console_cursor_info cci;         cci.dwsize = 25;         cci.bvisible = false;         setconsolecursorinfo(hout, &cci);          setconsolemode(hin, enable_processed_input | enable_mouse_input);        while(1)     {           readconsoleinput(hin, &inputrecord, 1, &events);           if(inputrecord.eventtype == mouse_event)          {             if(inputrecord.event.mouseevent.dwbuttonstate == from_left_1st_button_pressed)              {                  coord.x = inputrecord.event.mouseevent.dwmouseposition.x;                  coord.y = inputrecord.event.mouseevent.dwmouseposition.y;                  setconsolecursorposition(hout,coord);                 setconsoletextattribute(hout,rand() %7+9);                  cout<<"hello world" ;               }          }         flushconsoleinputbuffer(hin);     }     return 0;  } 

Comments

Popular posts from this blog

php - render data via PDO::FETCH_FUNC vs loop -

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

The canvas has been tainted by cross-origin data in chrome only -