Code:
/*
- Author: chappo
- Name: Safari Zone
- Desc: A simple safari zone clone
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
struct Pokemon
{
char name[20];
int id;
int catchRate;
int encounterRate;
int timesCaptured;
};
struct Bag
{
char itemName[20];
int itemAmount;
};
int main()
{
// initial setup of pokemon and bag
srand(time(NULL));
int pokemonRand = rand() %5;
// setup pokemon 1
struct Pokemon Pokemon[4];
strcpy(Pokemon[0].name, "Blastoise");
Pokemon[0].id = 9;
Pokemon[0].catchRate = (rand() % 100);
Pokemon[0]. timesCaptured = 0;
// setup pokemon 2
strcpy(Pokemon[1].name, "Golduck");
Pokemon[1].id = 55;
Pokemon[1].catchRate = (rand() % 100);
Pokemon[1]. timesCaptured = 0;
// setup pokemon 3
strcpy(Pokemon[2].name, "Weezing");
Pokemon[2].id = 110;
Pokemon[2].catchRate = (rand() % 100);
Pokemon[2]. timesCaptured = 0;
// setup pokemon 4
strcpy(Pokemon[3].name, "Golem");
Pokemon[3].id = 76;
Pokemon[3].catchRate = (rand() % 100);
Pokemon[3]. timesCaptured = 0;
// setup pokemon 5
strcpy(Pokemon[4].name, "Butterfree");
Pokemon[4].id = 12;
Pokemon[4].catchRate = (rand() % 100);
Pokemon[4]. timesCaptured = 0;
// setup item 1
struct Bag Item[4];
strcpy(Item[0].itemName, "Safariball");
Item[0].itemAmount = 10;
// setup item 2
strcpy(Item[1].itemName, "Pokeball");
Item[1].itemAmount = 5;
// setup item 3
strcpy(Item[2].itemName, "Good Bait");
Item[2].itemAmount = 5;
// setup item 4
strcpy(Item[3].itemName, "Bait");
Item[3].itemAmount = 5;
// setup item 5
strcpy(Item[4].itemName, "Rock");
Item[4].itemAmount = 5;
int choice, stop, currentID, currentCatchRate, currentTimesCaptured, leave, currentBalls, currentBait, currentGoodBait, currentRocks, misses;
int realcatch = rand()%100+1;
char currentName[20], isCaught[20];
label:
printf("\n** Welcome to the Safari Zone**\n\n1)Enter the Safari Zone\n2)Information\n3)Exit\n\nEnter your selection: ");
scanf("%d", &choice);
switch(choice)
{
case 1:
printf("\nYou entered the Safari Zone.\nYou walk around and see lush gardens and ample space for pokemon to roam.");
currentTimesCaptured = Pokemon[pokemonRand].timesCaptured;
currentBalls = Item[0].itemAmount+Item[1].itemAmount;
currentRocks = Item[4].itemAmount;
currentBait = Item[3].itemAmount;
currentGoodBait = Item[2].itemAmount;
label1:
srand(time(NULL));
strcpy(currentName, Pokemon[pokemonRand].name);
currentID = Pokemon[pokemonRand].id;
currentCatchRate = Pokemon[pokemonRand].catchRate;
label2:
printf("\nAll of a sudden you hear a bush move...\n");
printf("\nA wild %s appeared!", currentName);
label3:
printf("\n\nWhat would you like to do?\n1)Throw ball [%d/%d]\t2)Throw Rock [%d/%d]\n3)Bait [%d/%d]\t4)Good Bait [%d/%d]\nPokemon Caught: [%d]\n\nEnter your selection: ", currentBalls, Item[0].itemAmount+Item[1].itemAmount, currentRocks, Item[4].itemAmount, currentBait, Item[3].itemAmount, currentGoodBait, Item[2].itemAmount, currentTimesCaptured);
scanf("%d", &choice);
switch(choice)
{
case 1:
// throw a ball
// if out of balls, you leave
if (currentBalls == 0)
{
printf("You are out of balls! You have to leave now!");
goto label;
}
// if caught
if (currentCatchRate >= realcatch)
{
strcpy(isCaught, "\n!The Pokemon WAS caught!");
leave = 1;
currentTimesCaptured++;
currentBalls--;
misses = 0;
} else {
// if not caught -1 ball, decrease catch chance -1
strcpy(isCaught,"\n!The Pokemon was NOT caught!");
currentBalls--;
realcatch--;
// if you miss three times Pokemon runs away. New Pokemon comes.
if(misses >=3) {
printf("\n!The Pokemon has ran away!\n");
goto label1;
}
// if miss, add to counter
misses++;
}
printf("\nYou threw a Safari Ball at %s...\n%s has a catch rate of %d! Did he get caught?....%s\n", currentName, currentName, currentCatchRate, isCaught);
// if caught, you encounter a new pokemon. goto label1
if (leave == 1)
{
goto label1;
leave == 0;
}
// else goto options again
goto label3;
case 2:
// throw a rock
// if you have rocks make it harder to catch+1, rocks-1
if (currentRocks != 0)
{
printf("You hit %s with a rock! They're angry now!", currentName);
realcatch++;
currentRocks--;
goto label3;
}
// if out or rocks, you cannot use this option
printf("You are out of rocks! You cannot use this option any longer");
goto label3;
case 3:
// throw bait
// if you have bait make it easier to catch-1, bait-1
if (currentBait != 0)
{
printf("You threw some bait at %s! They're less aware now!", currentName);
realcatch--;
currentBait--;
goto label3;
}
// if out or bait, you cannot use this option
printf("You are out of bait! You cannot use this option any longer");
goto label3;
case 4:
// throw good bait
// if you have bait make it easier to catch-1, bait-1
if (currentGoodBait != 0)
{
printf("You threw some good bait at %s! They're less aware now!", currentName);
realcatch = realcatch-5;
currentGoodBait--;
goto label3;
}
// if out or good bait, you cannot use this option
printf("You are out of good bait! You cannot use this option any longer");
goto label3;
default:
goto label3;
}
break;
case 2:
printf("\nIn the Safari Zone you are given Safariballs and some other items to help catch Pokemon!\nThere are currently 5 Pokemon in our Park: %s, %s, %s, %s, and %s. ", Pokemon[0].name, Pokemon[1].name, Pokemon[2].name, Pokemon[3].name, Pokemon[4].name);
printf("Would you like to enter?\n1)Yes\n2)No\n\nEnter your selection: ");
scanf("%d", &choice);
if(choice != 1) {break;}
goto label;
break;
case 3:
default:
printf("\nInvalid option.");
break;
}
}