home *** CD-ROM | disk | FTP | other *** search
- /* amigamoves.c */
- /* */
- /* This function is the brain of my opponent when I choose to play vs. */
- /* my little Amy... If the move is successful it returns TRUE, else i */
- /* returns FALSE and the game can continue... */
-
- amigamoves()
- {
- extern struct RastPort *rp;
- extern int percentage;
- extern int memory;
- extern UWORD mycardsposition[];
- extern int score2, turn2;
- extern int pairs;
-
- int number, oldnumber;
- int i;
- int cardnumber1, cardnumber2;
- int firstcard, secondcard;
- int cardimage1, cardimage2;
- int distance;
- int found;
-
- /*******************************************************/
- /* */
- /* Point 1: Little Amy searches for cards in range */
- /* */
- /*******************************************************/
-
- number = customrand(1, 100);
-
- if (number < percentage + 20)
- {
- distance = 100;
- found = FALSE;
- i = 1;
-
- while(i < 32)
- {
- cardnumber1 = 1000;
- cardnumber2 = 1000;
-
- while((cardnumber1 == 1000) && (i < 32))
- cardnumber1 = mycardsposition[i++];
- firstcard = i - 2;
-
- while((cardnumber2 != cardnumber1) && (i <= 32))
- cardnumber2 = mycardsposition[i++];
- secondcard = i - 2;
-
- distance = secondcard - firstcard;
- if((distance > 0) && (distance < 10) &&
- (cardnumber1 == cardnumber2))
- {
- found = TRUE;
- break;
- }
- i = firstcard + 2;
- found = FALSE;
- }
-
- if(found == TRUE)
- {
- writestring(rp, "... I'm trying to remember...", COLOR2);
- Delay(70);
- writestring(rp, "... I'm trying to remember...", FALSE);
-
- writestring(rp, "This is the first card...", COLOR2);
- cardimage1 = showcard(firstcard);
- Delay(70);
- writestring(rp, "This is the first card...", FALSE);
-
- writestring(rp, "...and this the second...", COLOR2);
- cardimage2 = showcard(secondcard);
- Delay(70);
- writestring(rp, "...and this the second...", FALSE);
-
- amigaupdate(firstcard, secondcard);
-
- if (pairs > 0)
- {
- writestring(rp, "Score this turn to me!", COLOR2);
- Delay(70);
- writestring(rp, "Score this turn to me!", FALSE);
- }
-
- return(TRUE);
- }
- }
-
- /*******************************************************/
- /* */
- /* Point 2: Let's see if little Amy can use her memory */
- /* */
- /*******************************************************/
-
- cardnumber1 = 1000;
- cardnumber2 = 1000;
-
- number = customrand(1, 100); /* Get a number (1, 100) */
- if (number < percentage)
- {
- i = 1; /* Skip the first position inside mycardsposition[] */
-
- writestring(rp, "This is the first card...", COLOR2);
- while((cardnumber1 == 1000) && (i <= 32))
- cardnumber1 = mycardsposition[i++];
- firstcard = i - 2;
- cardimage1 = showcard(firstcard);
- Delay(70);
- writestring(rp, "This is the first card...", FALSE);
-
- writestring(rp, "... Hey, I've seen it before!", COLOR2);
- Delay(70);
- writestring(rp, "... Hey, I've seen it before!", FALSE);
-
- writestring(rp, "Here it is the matching one!", COLOR2);
- while((cardnumber2 != cardnumber1) && (i <= 32))
- cardnumber2 = mycardsposition[i++];
- secondcard = i - 2;
- cardimage2 = showcard(secondcard);
- Delay(70);
- writestring(rp, "Here it is the matching one!", FALSE);
-
- amigaupdate(firstcard, secondcard);
-
- if (pairs > 0)
- {
- writestring(rp, "I'm doing well, uh?", COLOR2);
- Delay(70);
- writestring(rp, "I'm doing well, uh?", FALSE);
- }
-
- return(TRUE); /* return to gameloop() */
- }
-
- /*******************************************************/
- /* */
- /* Point 3: Little Amy last chance (do or die)... */
- /* */
- /*******************************************************/
-
- cardnumber1 = 1000;
- cardnumber2 = 1000;
-
- writestring(rp, "Okay, I pick this card...", COLOR2);
- while(cardnumber1 == 1000)
- {
- number = customrand(1, 32);
- cardnumber1 = mycardsposition[number];
- }
- oldnumber = number;
- firstcard = number - 1;
- cardimage1 = showcard(firstcard);
- Delay(70);
- writestring(rp, "Okay, I pick this card...", FALSE);
-
- writestring(rp, "...and then... let me think...", COLOR2);
- Delay(70);
- writestring(rp, "...and then... let me think...", FALSE);
-
- writestring(rp, "...okay, let's try this one!", COLOR2);
- while((cardnumber2 == 1000) || (number == oldnumber))
- {
- number = customrand(1, 32);
- cardnumber2 = mycardsposition[number];
- }
- secondcard = number - 1;
- cardimage2 = showcard(secondcard);
- Delay(70);
- writestring(rp, "...okay, let's try this one!", FALSE);
-
- if (cardimage1 == cardimage2)
- {
- amigaupdate(firstcard, secondcard);
- if (pairs > 0)
- {
- writestring(rp, "WOW! I'VE DONE IT AGAIN!!!", COLOR2);
- Delay(70);
- writestring(rp, "WOW! I'VE DONE IT AGAIN!!!", FALSE);
- }
- return(TRUE);
- }
-
- writestring(rp, "OOOPS! Even an AMIGA can fail...", COLOR2);
- Delay(70);
- bonus = 0;
- turn2 += 1;
- covercard(firstcard);
- covercard(secondcard);
- update(SECOND, turn2, score2);
- writestring(rp, "OOOPS! Even an AMIGA can fail...", FALSE);
-
- return(FALSE);
- }
-
-
-
- amigaupdate(first, second)
- int first, second;
- {
- extern int score2;
- extern int turn2;
- extern int pairs;
-
- bonus += 1000;
- deletecard(first);
- deletecard(second);
- score2 += bonus;
- turn2 += 1;
- pairs -= 1;
- update(SECOND, turn2, score2);
- return(0);
- }
-