home *** CD-ROM | disk | FTP | other *** search
/ The CIA World Factbook 1992 / k3bimage.iso / sel / 04 / 0009 / pfuncs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-02  |  2.4 KB  |  98 lines

  1. /* pfuncs.c -- Project functions for Targ-Hurt ESP Trainer.
  2.  
  3.    History: rhs 14-mar-87 ... Original
  4.    
  5.    Contains these functions:
  6.       pf_getcode,
  7.       pf_display,
  8.       pf_resetscore,
  9.       pf_newscore.
  10.  
  11. */
  12.  
  13. #include <conio.h>
  14. #include "mancon.h"
  15. #include "declares.h"
  16.  
  17.  
  18. /* pf_getcode -- Get character from user, then translate character
  19.                  into an integer that is meaningful to calling functions.
  20. */            
  21. int pf_getcode()
  22. {  IMPORT int gia_cursorkeys[];
  23.    int j;
  24.    char ch;
  25.  
  26.    while(TRUE)
  27.    {  if(getkey(&ch)!=0)          /* Is character extended ASCII? */
  28.       {  for(j=0; j<4; j++)
  29.             if(ch==gia_cursorkeys[j]) return(j);
  30.       }
  31.       else
  32.          switch(toupper(ch))
  33.          {  case 'P': return(PASS);
  34.             case 'R': return(RESET);
  35.             case 'C': return(CHANGE);
  36.             case 'Q': return(QUIT);
  37.             case 'H': return(HELP);
  38.          } /* end switch, end else */
  39.    } /* end while */
  40. } /* end pf_getcode() */
  41.  
  42.  
  43.  
  44. /* pf_newscore -- Update number of answers, correct answers, etc.
  45.                   Record whether this answer was correct.
  46.  
  47.                   input: user's answer, machine's selection.
  48. */
  49. void pf_newscore(user, machine)
  50. int user, machine;                     
  51. {  IMPORT int gi_tries, gi_direction, gi_wasahit;
  52.    IMPORT int gi_encourage, gi_hits;
  53.    IMPORT struct encouragement gsa_enc[];
  54.    int j;
  55.  
  56.    gi_tries++;
  57.    gi_direction=machine;
  58.    gi_wasahit=FALSE;
  59.    gi_encourage= -1;
  60.    if(user==machine) { gi_hits++; gi_wasahit=TRUE; }
  61.  
  62.    for(j=0; j<ENCMSGS; j++)
  63.       if( (gi_hits>=gsa_enc[j].minhits)
  64.             && ((float)gi_hits/gi_tries >= gsa_enc[j].hitpct) )
  65.             gi_encourage++;
  66.  
  67. } /* end pf_newscore() */
  68.  
  69.  
  70. /* pf_newdirec -- Update the global variable which records
  71.                   the machine's choice.  This function lets
  72.                   the the program show the user what choice
  73.                   the machine made without updating the number
  74.                   of tries or hits.
  75. */   
  76. void pf_newdirec(machine)
  77. int machine;
  78. {  IMPORT gi_direction;
  79.    gi_direction = machine;
  80. }
  81.  
  82.  
  83.  
  84. /* pf_resetscore -- Resets answer counters to zero.
  85. */
  86. void pf_resetscore()
  87. {  IMPORT int gi_tries, gi_hits, gi_encourage;
  88.    IMPORT int gi_wasahit, gi_direction;
  89.    gi_tries=0;
  90.    gi_hits=0;
  91.    gi_encourage=0;
  92.    gi_wasahit=FALSE;
  93.    gi_direction=RESET;
  94.  
  95. }
  96.                     
  97.  
  98.