home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d1xx / d186 / cards'o'rama.lha / Cards'O'Rama / Sources / sources.zoo / amigamoves.c next >
C/C++ Source or Header  |  1989-02-25  |  6KB  |  215 lines

  1. /*                               amigamoves.c                           */
  2. /*                                                                      */
  3. /* This function is the brain of my opponent when I choose to play vs.  */
  4. /* my little Amy... If the move is successful it returns TRUE, else i   */
  5. /* returns FALSE and the game can continue...                           */
  6.  
  7. amigamoves()
  8.    {
  9.    extern struct RastPort *rp;
  10.    extern int percentage;
  11.    extern int memory;
  12.    extern UWORD mycardsposition[];
  13.    extern int score2, turn2;
  14.    extern int pairs;
  15.  
  16.    int number, oldnumber;
  17.    int i;
  18.    int cardnumber1, cardnumber2;
  19.    int firstcard, secondcard;
  20.    int cardimage1, cardimage2;
  21.    int distance;
  22.    int found;
  23.  
  24.    /*******************************************************/
  25.    /*                                                     */
  26.    /* Point 1: Little Amy searches for cards in range     */
  27.    /*                                                     */
  28.    /*******************************************************/
  29.  
  30.    number = customrand(1, 100);
  31.  
  32.    if (number < percentage + 20)
  33.       {
  34.       distance = 100;
  35.       found = FALSE;
  36.       i = 1;
  37.  
  38.       while(i < 32)
  39.          {
  40.          cardnumber1 = 1000;
  41.          cardnumber2 = 1000;
  42.  
  43.          while((cardnumber1 == 1000) && (i < 32))
  44.             cardnumber1 = mycardsposition[i++];
  45.          firstcard = i - 2;
  46.  
  47.          while((cardnumber2 != cardnumber1) && (i <= 32))
  48.             cardnumber2 = mycardsposition[i++];
  49.          secondcard = i - 2;
  50.  
  51.          distance = secondcard - firstcard;
  52.          if((distance > 0) && (distance < 10) &&
  53.             (cardnumber1 == cardnumber2))
  54.             {
  55.             found = TRUE;
  56.             break;
  57.             }
  58.          i = firstcard + 2;
  59.          found = FALSE;
  60.          }
  61.  
  62.       if(found == TRUE)
  63.          {
  64.          writestring(rp, "... I'm trying to remember...", COLOR2);
  65.          Delay(70);
  66.          writestring(rp, "... I'm trying to remember...", FALSE);
  67.  
  68.          writestring(rp, "This is the first card...", COLOR2);
  69.          cardimage1 = showcard(firstcard);
  70.          Delay(70);
  71.          writestring(rp, "This is the first card...", FALSE);
  72.  
  73.          writestring(rp, "...and this the second...", COLOR2);
  74.          cardimage2 = showcard(secondcard);
  75.          Delay(70);
  76.          writestring(rp, "...and this the second...", FALSE);
  77.  
  78.          amigaupdate(firstcard, secondcard);
  79.  
  80.          if (pairs > 0)
  81.             {
  82.             writestring(rp, "Score this turn to me!", COLOR2);
  83.             Delay(70);
  84.             writestring(rp, "Score this turn to me!", FALSE);
  85.             }
  86.  
  87.          return(TRUE);
  88.          }
  89.       }
  90.  
  91.    /*******************************************************/
  92.    /*                                                     */
  93.    /* Point 2: Let's see if little Amy can use her memory */
  94.    /*                                                     */
  95.    /*******************************************************/
  96.  
  97.    cardnumber1 = 1000;
  98.    cardnumber2 = 1000;
  99.  
  100.    number = customrand(1, 100);        /* Get a number (1, 100) */
  101.    if (number < percentage)
  102.       {
  103.       i = 1;   /* Skip the first position inside mycardsposition[] */
  104.  
  105.       writestring(rp, "This is the first card...", COLOR2);
  106.       while((cardnumber1 == 1000) && (i <= 32))
  107.          cardnumber1 = mycardsposition[i++];
  108.       firstcard = i - 2;
  109.       cardimage1 = showcard(firstcard);
  110.       Delay(70);
  111.       writestring(rp, "This is the first card...", FALSE);
  112.  
  113.       writestring(rp, "... Hey, I've seen it before!", COLOR2);
  114.       Delay(70);
  115.       writestring(rp, "... Hey, I've seen it before!", FALSE);
  116.  
  117.       writestring(rp, "Here it is the matching one!", COLOR2);
  118.       while((cardnumber2 != cardnumber1) && (i <= 32))
  119.          cardnumber2 = mycardsposition[i++];
  120.       secondcard = i - 2;
  121.       cardimage2 = showcard(secondcard);
  122.       Delay(70);
  123.       writestring(rp, "Here it is the matching one!", FALSE);
  124.  
  125.       amigaupdate(firstcard, secondcard);
  126.  
  127.       if (pairs > 0)
  128.          {
  129.          writestring(rp, "I'm doing well, uh?", COLOR2);
  130.          Delay(70);
  131.          writestring(rp, "I'm doing well, uh?", FALSE);
  132.          }
  133.  
  134.       return(TRUE);     /* return to gameloop() */
  135.       }
  136.  
  137.    /*******************************************************/
  138.    /*                                                     */
  139.    /* Point 3: Little Amy last chance (do or die)...      */
  140.    /*                                                     */
  141.    /*******************************************************/
  142.  
  143.    cardnumber1 = 1000;
  144.    cardnumber2 = 1000;
  145.  
  146.    writestring(rp, "Okay, I pick this card...", COLOR2);
  147.    while(cardnumber1 == 1000)
  148.       {
  149.       number = customrand(1, 32);
  150.       cardnumber1 = mycardsposition[number];
  151.       }
  152.    oldnumber = number;
  153.    firstcard = number - 1;
  154.    cardimage1 = showcard(firstcard);
  155.    Delay(70);
  156.    writestring(rp, "Okay, I pick this card...", FALSE);
  157.  
  158.    writestring(rp, "...and then... let me think...", COLOR2);
  159.    Delay(70);
  160.    writestring(rp, "...and then... let me think...", FALSE);
  161.  
  162.    writestring(rp, "...okay, let's try this one!", COLOR2);
  163.    while((cardnumber2 == 1000) || (number == oldnumber))
  164.       {
  165.       number = customrand(1, 32);
  166.       cardnumber2 = mycardsposition[number];
  167.       }
  168.    secondcard = number - 1;
  169.    cardimage2 = showcard(secondcard);
  170.    Delay(70);
  171.    writestring(rp, "...okay, let's try this one!", FALSE);
  172.  
  173.    if (cardimage1 == cardimage2)
  174.       {
  175.       amigaupdate(firstcard, secondcard);
  176.       if (pairs > 0)
  177.          {
  178.          writestring(rp, "WOW! I'VE DONE IT AGAIN!!!", COLOR2);
  179.          Delay(70);
  180.          writestring(rp, "WOW! I'VE DONE IT AGAIN!!!", FALSE);
  181.          }
  182.       return(TRUE);
  183.       }
  184.  
  185.    writestring(rp, "OOOPS! Even an AMIGA can fail...", COLOR2);
  186.    Delay(70);
  187.    bonus = 0;
  188.    turn2 += 1;
  189.    covercard(firstcard);
  190.    covercard(secondcard);
  191.    update(SECOND, turn2, score2);
  192.    writestring(rp, "OOOPS! Even an AMIGA can fail...", FALSE);
  193.  
  194.    return(FALSE);
  195.    }
  196.  
  197.  
  198.  
  199. amigaupdate(first, second)
  200.    int first, second;
  201.    {
  202.    extern int score2;
  203.    extern int turn2;
  204.    extern int pairs;
  205.  
  206.    bonus += 1000;
  207.    deletecard(first);
  208.    deletecard(second);
  209.    score2 += bonus;
  210.    turn2 += 1;
  211.    pairs -= 1;
  212.    update(SECOND, turn2, score2);
  213.    return(0);
  214.    }
  215.