home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 427_01 / testware / joytest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-17  |  1.9 KB  |  86 lines

  1. /*                                                 */     
  2. /* main program for Multijoy joystick test program */
  3. /*                                                 */
  4. /* written in Borland C++ 3.1                      */
  5. /*                                                 */
  6.  
  7. #include <conio.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>     /* for getenv  */
  10. #include <dos.h>    /* for inportb */
  11. #include <string.h>    /* for strchr  */
  12. #include <ctype.h>    /* for toupper */
  13. #include "minijoy.h"
  14.  
  15.  
  16. void hit(void)
  17. {
  18.   putc('█',stdout);
  19.   sound(440);
  20.   delay(10);
  21.   nosound();
  22. }
  23.  
  24. void main(void)
  25. {
  26.   int i;
  27.  
  28.   /* init the joystick interface */
  29.   InitMultiJoy ();
  30.  
  31.   /* print static elements */
  32.   clrscr();
  33.   for (i=1; i<=MAXPLAYER; i++)
  34.   {
  35.     gotoxy(i*10-2, 3);
  36.     printf("Joy %d",i);
  37.   }
  38.   gotoxy(1,24);
  39.   printf("Press any key to exit");
  40.  
  41.   /* main loop */
  42.   do
  43.   {
  44.     /* keypressed? -> exit */
  45.     if (kbhit()) { clrscr(); exit(0); }
  46.  
  47.     /* get the joystick status of the 6 joysticks */
  48.     GetAllJoyState ();
  49.  
  50.     for (i=0; i<MAXPLAYER; i++)
  51.     {
  52.       /* now show the direction the joystick is pressed */
  53.       gotoxy(i*10,5);
  54.       if (JoyState[i].y ==-1)
  55.     {if (JoyState[i].uhit) hit(); else puts("^");}
  56.       else puts(" ");
  57.  
  58.       gotoxy(i*10-2,6);
  59.       if (JoyState[i].x ==-1)
  60.     {if (JoyState[i].lhit) hit(); else puts("<");}
  61.       else puts(" ");
  62.  
  63.       gotoxy(i*10+2,6);
  64.       if (JoyState[i].x ==1)
  65.     {if (JoyState[i].rhit) hit(); else puts(">");}
  66.       else puts(" ");
  67.  
  68.       gotoxy(i*10,7);
  69.       if (JoyState[i].y == 1)
  70.     {if (JoyState[i].dhit) hit(); else puts("v");}
  71.       else puts(" ");
  72.  
  73.       gotoxy(i*10,9);
  74.       if (JoyState[i].knopf)
  75.     {if (JoyState[i].khit) hit(); else puts("K");}
  76.       else puts(" ");
  77.  
  78.       gotoxy(i*10,10);
  79.       if (JoyState[i].xtra)
  80.     {if (JoyState[i].xhit) hit(); else puts("X");}
  81.       else puts(" ");
  82.  
  83.     }
  84.   }
  85.   while (1);
  86. }