Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <time.h>
- #include <ctype.h>
- #include <string.h>
- #include <stdlib.h>
- FILE * fptr;
- getLocationName();
- getWeapon();
- getEnemy();
- battle();
- damageCalc();
- int dmg = 0;
- //all of the player info
- int progress = 1;
- int score = 0;
- char playerName[14];
- int playerLevel = 1;
- char currentLocationName[50];
- char c;
- int playerHp = 10;
- int playerMaxHp = 10;
- int playerMp = 10;
- int playerMaxMp = 10;
- int dexterity = 1;
- int sword = 1;
- int strength = 1;
- int axe = 0;
- int accuracy = 1;
- int bow = 0;
- int power = 1;
- int staff = 0;
- int arrowCount = 5;
- int checkedLetter = 0;
- //all of the enemy info
- char currentEnemyName[20];
- int enemyID = 0;
- int enemyHp = 0;
- int enemyMaxHp = 0;
- int enemyStrength = 0;
- int enemyScoreGive = 0;
- //worker variables
- int choice = 1;
- int checkedForLoot = 0;
- time_t t;
- int locationID = 0;
- int baseDMG = 0;
- int valid = 0;
- //int x;
- //int y;
- //for map system. 0 is wall, 1-10 are occupied rooms. 11-20 are unoccupied rooms.
- //rowOne[0]is x-0, y-0. row5[9] is x-10 y-5.
- //note that the y affects the row, and x affects the actual value
- //within the row.
- //-------------------------------------------------------------
- //int row_Five[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 0};
- //int row_Four[10] = {1, 0, 1, 0, 1, 0, 0, 0, 1, 0};
- //int rowThree[10] = {1, 0, 1, 0, 1, 1, 1, 1, 1, 1};
- //int row__Two[10] = {1, 0, 1, 0, 0, 0, 1, 0, 0, 1};
- //int row__One[10] = {2, 1, 1, 1, 1, 1, 1, 1, 1, 1};
- //-------------------------------------------------------------
- char * locationNames[10] = {"A Dark, Creepy Room with bones laying about.",
- "A Stone Room with rats chattering in the walls.",
- "A Long, Dark Hall with blood stains on the floors.",
- "A Stone Room with a table in the corner.",
- "An old Armory. Broken swords hang along the walls.",
- "An Open Room of a Cave.",
- "An old Throne Room with a corpse in the seat.",
- "A Stone Room with a chest in the corner.",
- "A room with walls made of strange crystals.",
- "An ancient Dining Hall. There is no food, though."};
- main()
- {
- srand(time(&t));
- printf("Welcome to Avelaroar, Chapter 1:\n");
- printf("# # ### # ### ### ### ##### ##\n");
- printf("# # # # # # # # # # # #\n");
- printf("# # ### # # # ## # # # # ####\n");
- printf("# # # # # # # # # # # # #\n");
- printf(" # ### ### ### #### ### # # # # #\n");
- printf("PRESS ANY CHARACTER TO CONTINUE\n");
- c = getch();
- system("cls");
- printf("Deep in the lands of Avelaroar, in the year 980, within the caves of Mount Veligima\n");
- printf("lives an evil beast. He is called by many names: Tyruili, Bivib,\n");
- printf("and sometime simply the Great Dragon. But he goes by\n");
- printf("Quetzalcoatl, the ancient snake deity of the Aztecs.\n\n\n");
- printf("Quetzalcoatl nows reigns an army of evils. He has destroyed the city of\n");
- printf("Gildendor. BUT YOU have been chosen by the king himself to slay\n");
- printf("this foul beast. Beware, however. You never know what may\n");
- printf("hide in the depths of Veligima...\n\n\n");
- printf("PRESS ANY CHARACTER TO CONTINUE\n");
- c = getch();
- system("cls");
- printf("Are you starting a new game, or loading an old one?\n");
- printf("1. New Game. Previous progress will be lost.\n");
- printf("2. Load Game.\n");
- scanf(" %d", &choice);
- /* if (fptr == 0)
- {
- printf("FAILED TO CREATE/LOAD DATA.\n");
- printf("FIX: Make a txt file under the following path:\n");
- printf("C->Users->Public->Documents\n");
- printf("With name:\n");
- printf("avelaroarChOneViligimaData\n");
- printf("EXITING PROGRAM...\n");
- exit(0);
- } */
- if (choice == 1)
- {
- printf("\n\n");
- do
- {
- printf("What shall your class be?\n");
- printf("1. Warrior. +2 STR. +1 DEX.\n");
- printf("2. Magister. +2 POW. +1 ACR.\n");
- printf("3. Archer. +2 ACR. +1 DEX.\n");
- printf("4. Paladin. +2 DEX. +1 POW.\n");
- printf("5. Sorcerer. +3 POW.\n");
- printf("6. Brute. +3 STR.\n");
- printf("7. Adventurer. +1 STR. +1 DEX. +1 ACR.\n");
- scanf(" %d", &choice);
- if (choice == 1)
- {
- strength += 2;
- dexterity += 1;
- axe = 1;
- valid = 1;
- }
- else if (choice == 2)
- {
- power += 2;
- accuracy += 1;
- staff = 1;
- valid = 1;
- }
- else if (choice == 3)
- {
- accuracy += 2;
- power += 1;
- bow = 1;
- valid = 1;
- }
- else if (choice == 4)
- {
- dexterity += 2;
- power += 1;
- valid = 1;
- }
- else if (choice == 5)
- {
- power += 3;
- staff = 1;
- valid = 1;
- }
- else if (choice == 6)
- {
- strength += 3;
- axe = 1;
- valid = 1;
- }
- else if (choice == 7)
- {
- strength += 1;
- dexterity += 1;
- accuracy += 1;
- int randWeaponStart = (rand() % 2) + 1;
- if (randWeaponStart == 2)
- {
- axe = 1;
- }
- if (randWeaponStart == 3)
- {
- bow = 1;
- }
- valid = 1;
- }
- else
- {
- printf("INVALID INPUT.\n");
- valid = 0;
- }
- } while (valid == 0);
- printf("PRESS ANY CHARACTER TO CONTINUE\n");
- c = getch();
- printf("\nType your name (up to 12 characters)\n\n");
- fgets(playerName, 13, stdin);
- fgets(playerName, 13, stdin);
- //system("cls");
- printf("\n%s is your name? Good.\n", playerName);
- printf("You will now face hordes of enemies, soon to fight the GREAT DRAGON. \n \n");
- if (playerName[0] == '&')
- {
- progress = 28;
- sword = 40;
- dexterity = 10;
- playerHp = 999;
- playerMaxHp = 999;
- }
- fptr = fopen("avelaroarChOneViligimaData.txt", "w");
- putw(sword, fptr);
- putw(axe, fptr);
- putw(staff, fptr);
- putw(bow, fptr);
- putw(strength, fptr);
- putw(dexterity, fptr);
- putw(power, fptr);
- putw(accuracy, fptr);
- putw(playerHp, fptr);
- putw(playerMaxHp, fptr);
- putw(playerMp, fptr);
- putw(playerMaxMp, fptr);
- putw(playerLevel, fptr);
- putw(score, fptr);
- putw(progress, fptr);
- putw(arrowCount, fptr);
- putw(checkedForLoot, fptr);
- putw(checkedLetter, fptr);
- fputs(playerName, fptr);
- putw(-1, fptr);
- }
- else if (choice == 2)
- {
- fptr = fopen("avelaroarChOneViligimaData.txt", "r");
- //fseek(fptr, 0, SEEK_SET);
- sword = getw(fptr);
- if (sword <= 0)
- {
- printf("NON-VALID FILE: DEFAULT VALUE NOT FOUND.\n");
- printf("EXITING PROGRAM. RELOAD AND GO TO NEW GAME\n");
- exit(0);
- }
- else
- {
- printf("VALID\n");
- }
- axe = getw(fptr);
- staff = getw(fptr);
- bow = getw(fptr);
- strength = getw(fptr);
- dexterity = getw(fptr);
- power = getw(fptr);
- accuracy = getw(fptr);
- playerHp = getw(fptr);
- playerMaxHp = getw(fptr);
- playerMp = getw(fptr);
- playerMaxMp = getw(fptr);
- playerLevel = getw(fptr);
- score = getw(fptr);
- progress = getw(fptr);
- arrowCount = getw(fptr);
- checkedForLoot = getw(fptr);
- checkedLetter = getw(fptr);
- //playerName = fread(fptr, sizeof(playerName));
- int i;
- for (i = 0; i < sizeof(playerName); i++)
- {
- playerName[i] = fgetc(fptr);
- }
- }
- fclose(fptr);
- printf("PRESS ANY CHARACTER TO CONTINUE\n");
- c = getch();
- system("cls");
- do
- {
- getLocationName();
- do
- {
- printf("\n\n\n\n You are in %s \n", currentLocationName);
- printf("\nWhat shall you do now?\n");
- printf("1. Move Forward.\n");
- printf("2. Rest. \n");
- printf("3. Search Room for loot. \n");
- printf("4. Check Inventory and Status. \n");
- printf("5. Save Progress. \n");
- scanf(" %d", &choice);
- if (choice == 2)
- {
- playerHp = playerHp + 2;
- if (playerHp > playerMaxHp)
- {
- playerHp = playerMaxHp;
- }
- playerMp = playerMp + 2;
- if (playerMp > playerMaxMp)
- {
- playerMp = playerMaxMp;
- }
- system("cls");
- }
- if (choice == 3 && checkedForLoot == 0)
- {
- printf("Looking for loot... \n\n\n\n");
- getWeapon();
- checkedForLoot = 1;
- }
- else if (choice == 3 && checkedForLoot == 1)
- {
- printf("You already searched this room. \n");
- printf("PRESS ANY CHARACTER TO CONTINUE\n");
- c = getch();
- system("cls");
- }
- if (choice == 4)
- {
- printf("\n%s\n\nInventory: \n", playerName);
- printf("Lv. %d sword. \n", sword);
- if (bow > 0)
- {
- printf("Lv. %d bow. \n", bow);
- }
- if (arrowCount > 0)
- {
- printf("%d arrow(s). \n", arrowCount);
- }
- if (axe > 0)
- {
- printf("Lv. %d axe.\n", axe);
- }
- if (staff > 0)
- {
- printf("Lv. %d staff.\n", staff);
- }
- printf("\nYou are Level %d.", playerLevel);
- printf("\nYou have %d XP.", score);
- printf("\nHealth is at %d / %d.", playerHp, playerMaxHp);
- printf("\nMagic is at %d / %d.\n", playerMp, playerMaxMp);
- printf("You have cleared %d rooms.\n", progress - 1);
- printf("STR: %d. DEX: %d. POW: %d. ACR: %d.\n", strength, dexterity, power, accuracy);
- printf("PRESS ANY CHARACTER TO CONTINUE\n");
- c = getch();
- system("cls");
- }
- if (choice == 5)
- {
- fptr = fopen("avelaroarChOneViligimaData.txt", "w");
- putw(sword, fptr);
- putw(axe, fptr);
- putw(staff, fptr);
- putw(bow, fptr);
- putw(strength, fptr);
- putw(dexterity, fptr);
- putw(power, fptr);
- putw(accuracy, fptr);
- putw(playerHp, fptr);
- putw(playerMaxHp, fptr);
- putw(playerMp, fptr);
- putw(playerMaxMp, fptr);
- putw(playerLevel, fptr);
- putw(score, fptr);
- putw(progress, fptr);
- putw(arrowCount, fptr);
- putw(checkedForLoot, fptr);
- putw(checkedLetter, fptr);
- fputs(playerName, fptr);
- putw(-1, fptr);
- fclose(fptr);
- printf("SAVED DATA. PRESS ANY CHARACTER TO CONTINUE\n");
- c = getch();
- system("cls");
- }
- } while (choice != 1);
- printf("\n\n LOADING... \n\n");
- system("cls");
- battle();
- //----------------------------------------------------------------------------------------
- } while (playerHp > 0);
- return (0);
- }
- getLocationName()
- {
- locationID = (rand() % 9);
- strcpy(currentLocationName, locationNames[locationID]);
- }
- getWeapon()
- {
- int swordLootChance = (rand() % 24) + 1;
- if (swordLootChance >= 17)
- {
- int newSword = (rand() % progress) + 1;
- if (newSword > sword)
- {
- printf("You found a new, and deadlier sword!\n");
- sword = newSword;
- }
- else
- {
- printf("You found an old, rusted sword. You tossed that junk aside.\n");
- }
- }
- else
- {
- printf("No swords around here.\n");
- }
- int axeLootChance = (rand() % 24) + 1;
- if (axeLootChance >= 18)
- {
- int newAxe = (rand() % progress) + 1;
- if (newAxe > axe)
- {
- printf("You found a new, and deadlier axe!\n");
- axe = newAxe;
- }
- else
- {
- printf("You found an old, chipped axe. You tossed that junk aside.\n");
- }
- }
- else
- {
- printf("No axes around here.\n");
- }
- int staffLootChance = (rand() % 20) + 1;
- if (staffLootChance >= 18)
- {
- int newStaff = (rand() % progress) + 1;
- if (newStaff > staff)
- {
- printf("You found a new, powerful staff!\n");
- staff = newStaff;
- }
- else
- {
- printf("You found an old staff with a broke shaft. You tossed that junk aside.\n");
- }
- }
- else
- {
- printf("No staffs around here.\n");
- }
- int bowLootChance = (rand() % 22) + 1;
- if (bowLootChance >= 17)
- {
- int newBow = (rand() % progress) + 1;
- if (newBow > bow)
- {
- printf("You found a sturdy bow that will fair better than yours.\n");
- bow = newBow;
- }
- else
- {
- printf("You found an old, flimsy bow. You tossed that junk aside.\n");
- }
- }
- else
- {
- printf("No bows around here.\n");
- }
- int arrowLootChance = (rand() % 30) + 1;
- if (arrowLootChance >= 20)
- {
- int arrowLoot = (rand() % 9) + 3;
- printf("You found %d arrow(s).\n", arrowLoot);
- arrowCount = arrowCount + arrowLoot;
- }
- else
- {
- printf("No arrows around here.\n");
- }
- if (progress == 19)
- {
- printf("You found a note that reads:\n\n");
- printf("If you are sent by the King of Avelaroar, TURN BACK!\n");
- printf("The fool sent me here telling me I was chosen, but\n");
- printf("it was a lie!!! Up ahead are some Knights sent here\n");
- printf("first, years back. They are all insane and will kill\n");
- printf("you on site!!! One shot me in the knee with a bow, \n");
- printf("and now I can't run. Wait... I hear something...\n\n");
- printf("On the note is blood splatter, and you see a blood\n");
- printf("trail leading into the next room...\n");
- }
- if (progress == 37)
- {
- printf("You found a note that reads:\n\n");
- printf("I made it through the Rogue Knights and Warlords.\n");
- printf("Up ahead I hear dragons. I am unsure if I should or not.\n");
- printf("The King said I would make it back, that I am some\n");
- printf("chosen warrior to save the day. All I can say is, if\n");
- printf("you find this and I am dead, tell my beloved Elizibeth\n");
- printf("that Marcus loves her...\n\n");
- printf("On the note is tear stains and beside a heart-shaped necklace.\n");
- printf("Blood stains the door to the next room...\n");
- checkedLetter = 1;
- }
- if (progress == 38)
- {
- printf("You found a corpse with an engraved armband engraved MARCUS, 978.\n");
- printf("The corpse has a heart and arrow carved into it by a Wyvern.\n");
- if (checkedLetter == 1)
- {
- printf("You take the armband, in hopes of finding Elizibeth later...\n");
- }
- }
- if (progress == 49)
- {
- printf("You found a note that reads:\n\n");
- printf("I killed the Wyverns guarding this door...\n");
- printf("Up ahead I hear Quetzalcoatl laughing... it is\n");
- printf("like he know I was coming. Maybe the king was right\n");
- printf("and I am the Chosen! Still, my arm is cut pretty\n");
- printf("bad. I will rest here for a little while than move on\n");
- printf("ahead for that fiend Quetzalcoatl...\n\n");
- printf("Next to the note is a corpse that has been burnt\n");
- printf("and gashed into. The arms are almost disconnected\n");
- printf("and the belly is layed open...");
- }
- printf("PRESS ANY CHARACTER TO CONTINUE\n");
- c = getch();
- system("cls");
- }
- battle()
- {
- getEnemy();
- //intro
- printf("%s VERSUS %s!!!\n\n\n", playerName, currentEnemyName);
- printf("(Press ENTER to continue)\n");
- //loops until either the player or enemy dies
- do
- {
- //only loops so that the player can perform their turn.
- do
- {
- printf("\n\n\n%s HP: %d / %d.\n", playerName, playerHp, playerMaxHp);
- printf("%s HP: %d / %d. \n", currentEnemyName, enemyHp, enemyMaxHp);
- printf("\n\n\nWhat will you do?\n");
- printf("1. Slash at them with your sword.\n");
- if (bow > 0 && arrowCount > 0)
- {
- printf("2. Shoot them with your bow. %d Arrow(s) left. \n", arrowCount);
- }
- if (axe > 0)
- {
- printf("3. Cleave them with your axe.\n");
- }
- if (staff > 0)
- {
- printf("4. Shoot a Fire Ball with your staff. %d MP left.\n", playerMp);
- }
- scanf(" %d", &choice);
- if (choice == 2 && bow == 0)
- {
- printf("INVALID INPUT\n");
- valid = 0;
- }
- else if (choice == 2 && arrowCount == 0)
- {
- printf("INVALID INPUT\n");
- valid = 0;
- }
- else if (choice == 4 && staff == 0)
- {
- printf("INVALID INPUT\n");
- valid = 0;
- }
- else if (choice != 1 && choice != 2 && choice != 3 && choice != 4)
- {
- printf("INVALID INPUT\n");
- valid = 0;
- }
- else if (choice == 3 && axe == 0)
- {
- printf("INVALID INPUT\n");
- valid = 0;
- }
- else
- {
- valid = 1;
- }
- } while (valid == 0);
- if (choice == 1)
- {
- baseDMG = sword + dexterity;
- }
- if (choice == 2)
- {
- baseDMG = bow + accuracy;
- arrowCount = arrowCount - 1;
- }
- if (choice == 3)
- {
- baseDMG = axe + strength;
- }
- if (choice == 4)
- {
- baseDMG = staff + power;
- playerMp = playerMp - 1;
- }
- dmg = 0;
- damageCalc();
- enemyHp = enemyHp - dmg;
- printf("\nYou dealt %d points of damage.\n", dmg);
- dmg = 0;
- //if enemy is dead
- if (enemyHp <= 0 && enemyID != 9)
- {
- printf("You defeated the %s\n", currentEnemyName);
- score = score + enemyScoreGive;
- if (score >= 500 * playerLevel)
- {
- printf("You are now Level %d!\n", playerLevel + 1);
- printf("Max Health +5. Max Magic +5.\n");
- playerMaxHp = playerMaxHp + 5;
- playerMaxMp = playerMaxMp + 5;
- score = score - (500 * playerLevel);
- playerLevel = playerLevel + 1;
- do
- {
- printf("Which stat do you want to increase?\n");
- printf("1. STR.\n");
- printf("2. DEX.\n");
- printf("3. POW.\n");
- printf("4. ACR.\n");
- scanf(" %d", &choice);
- valid = 1;
- if (choice == 1)
- {
- strength += 1;
- }
- else if (choice == 2)
- {
- dexterity += 1;
- }
- else if (choice == 3)
- {
- power += 1;
- }
- else if (choice == 4)
- {
- accuracy += 1;
- }
- else
- {
- valid = 0;
- }
- } while (valid == 0);
- }
- progress = progress + 1;
- checkedForLoot = 0;
- printf("PRESS ANY CHARACTER TO CONTINUE\n");
- c = getch();
- system("cls");
- break;
- }
- if (enemyHp <= 0 && enemyID == 9)
- {
- printf("\n\n\nYou have defeated Quetzalcoatl!\n");
- printf("Your level was %d.\n", playerLevel);
- printf("You had a Lv. %d sword.\n", sword);
- printf("You had a Lv. %d axe.\n", axe);
- printf("You had a Lv. %d bow.\n", bow);
- printf("You had a Lv. %d staff.\n", staff);
- printf("You had %d Arrow(s).\n", arrowCount);
- printf("And your name was %s\n", playerName);
- printf("THE END...\n");
- exit(0);
- }
- baseDMG = enemyStrength;
- damageCalc();
- playerHp = playerHp - dmg;
- printf("\n\n\nYou received %d points of damage.\n", dmg);
- printf("PRESS ANY CHARACTER TO CONTINUE\n");
- c = getch();
- system("cls");
- } while (playerHp > 0 && enemyHp > 0);
- }
- damageCalc()
- {
- dmg = baseDMG + (rand() % 1) + 1;
- int critChance = (rand() % 49) + 1;
- if (critChance == 50)
- {
- printf("CRITICAL STRIKE\n");
- dmg = dmg * 2;
- }
- }
- getEnemy()
- {
- //gets the ID based on how far the player has progressed.
- if (progress > 0 && progress < 6)
- {
- enemyID = (rand() % 1) + 1;
- }
- else if (progress >= 6 && progress < 14)
- {
- enemyID = (rand() % 2) + 1;
- }
- else if (progress >= 14 && progress < 20)
- {
- enemyID = (rand() % 3) + 1;
- if (enemyID == 1)
- {
- enemyID += 1;
- }
- }
- else if (progress >= 20 && progress < 29)
- {
- enemyID = (rand() % 4) + 1;
- if (enemyID == 1 || enemyID == 2 || enemyID == 3)
- {
- enemyID = 4;
- }
- }
- else if (progress >= 29 && progress < 38)
- {
- enemyID = (rand() % 5) + 1;
- if (enemyID == 1 || enemyID == 2 || enemyID == 3)
- {
- enemyID = 6;
- }
- }
- else if (progress >= 38 && progress < 40)
- {
- enemyID = (rand() % 5) + 1;
- if (enemyID == 1 || enemyID == 2 || enemyID == 3 || enemyID == 4)
- {
- enemyID = 6;
- }
- }
- else if (progress >= 40 && progress < 50)
- {
- enemyID = (rand() % 7) + 1;
- if (enemyID == 1 || enemyID == 2 || enemyID == 3 || enemyID == 4 || enemyID == 5)
- {
- enemyID = 8;
- }
- }
- else if (progress == 50)
- {
- enemyID = 9;
- }
- if (enemyID == 1)
- {
- enemyHp = 8;
- enemyStrength = 1;
- enemyScoreGive = 100;
- strcpy(currentEnemyName, "Goblin");
- }
- if (enemyID == 2)
- {
- enemyHp = 20;
- enemyStrength = 2;
- enemyScoreGive = 150;
- strcpy(currentEnemyName, "Bandit");
- }
- if (enemyID == 3)
- {
- enemyHp = 29;
- enemyStrength = 3;
- enemyScoreGive = 250;
- strcpy(currentEnemyName, "Ogre");
- }
- if (enemyID == 4)
- {
- enemyHp = 50;
- enemyStrength = 6;
- enemyScoreGive = 300;
- strcpy(currentEnemyName, "Rogue Knight");
- }
- if (enemyID == 5)
- {
- enemyHp = 75;
- enemyStrength = 6;
- enemyScoreGive = 400;
- strcpy(currentEnemyName, "Warlord");
- }
- if (enemyID == 6)
- {
- enemyHp = 100;
- enemyStrength = 7;
- enemyScoreGive = 550;
- strcpy(currentEnemyName, "Lesser Wyvern");
- }
- if (enemyID == 7)
- {
- enemyHp = 120;
- enemyStrength = 6;
- enemyScoreGive = 650;
- strcpy(currentEnemyName, "Armored Wyvern");
- }
- if (enemyID == 8)
- {
- enemyHp = 120;
- enemyStrength = 8;
- enemyScoreGive = 750;
- strcpy(currentEnemyName, "Daemon");
- }
- if (enemyID == 9)
- {
- enemyHp = 225;
- enemyStrength = 10;
- enemyScoreGive = 7;
- strcpy(currentEnemyName, "Quetzalcoatl");
- }
- enemyMaxHp = enemyHp;
- }
Advertisement
Add Comment
Please, Sign In to add comment