/* Thanks go out to: (from the OiNK IRC channel):
german for helping me code the random monster name generator
macdonalder for helping me write the room description reader
the rest of the channel for periodic help and troubleshooting!
Whoever said IRC was useless never had to write a program :D
Program: DOS-RPG (Dungeons of Slaying - Rather Pathetic Game)
*/
/*
This program will generate a X x 3 dungeon map and allow the player
to traverse through it, fighting random monsters and leveling.
There is a final "boss" too :)
NOTE: I had to use Windows color commands because Microsoft has
apparently decided that the Windows prompt doesn't need to support
ANSI standards any more.
TO DO LIST:
Colors: Half-done, due to Windows, non-ANSI compliance :(
High Score list: DONE!
Items/Modifiers for character;
Game saving (probably won't ever happen);
More stats;
See if it is possible to manipulate math to have dynamic
width as well as height, if not, redesign room system;
Write more rooms and move the file pointer to main() so that
it can be passed to nameRoom() to generate another floor.
Make executable windows installer for sharing :)
if this gets done, bundle with (free) terminal emulator
so that ANSI colors can be done
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "gamefuncs.h"
int clearstdin(void)
{
while (getchar() != 0x0a) { }
}
typedef struct {
int level, hp, str, exp, maxhp;
} stats;
main() {
// declaring variables
char name[10], *monsterName, *weapon, choice, choice2, outs, c, **room;
int i, a, whatMonster, r=0, *p, roomNumber=1, disp=0;
p = &r;
// declare, point to, and fill structs
stats *player, *baddie;
stats play3r, baddi3;
player = &play3r;
baddie = &baddi3;
player->level =1, player->hp = 10, player->str = 4, player->exp =0, player->maxhp=10, player->exp=0;
// get the player's name and display the logo
printf("Welcome. What is your name? ");
scanf("%s",&name);
clearstdin();
system("clear");
logo();
//getchar();
printf("\n\n%s you are forever doomed! You will never escape The Tower!\n\n", name);
printf("press enter to continue");
getchar();
//system("pause"); - no worky on linux use getchar()
//clearstdin();
//getchar();
system("clear");
//system("color 07"); // go back to the normal coloring changed by logo() - no worky on linux
// the next loop keeps looping until the character has died.
while (player->hp > 0) { // the game runs on this loop!
system("clear"); // clears the screen after every iteration
// the next bit of code displays the room descriptions
room = malloc(9 * sizeof(void));
if (roomNumber == 0) //fixes a bug
roomNumber = 1;
if (roomNumber % 3 == 0) { // for rooms 3,6,9,12 etc.
if (roomNumber == ROOM_ROWS * 3)
disp = 5;
else if (roomNumber == (ROOM_ROWS * 3) + 3)
disp = 8;
else
disp = 2;
} // end of middle rooms-if
if (roomNumber % 3 == 2) { //Western rooms
if (roomNumber == ((ROOM_ROWS) * 3)-1)
disp = 4;
else {
if (roomNumber == ((ROOM_ROWS) * 3)+2)
disp = 7;
else
disp = 1;
}
} //end of western rooms-if
if (roomNumber % 3 == 1) { //Eastern rooms
if (roomNumber == 1) {
disp = 0; }
else if (roomNumber == ((ROOM_ROWS * 3)+1))
disp = 6;
else
disp = 3;
} //end of eastern rooms-if
room[disp] = nameRoom(disp);
// printf("ROOM NUMBER %i with a disp of %i",roomNumber,disp); //UNEDIT THIS LINE TO TROUBLESHOOT
printf("%s\n",room[disp]);
// the HUD on the screen
printf("Player name: %s\t\t\t\tLevel: %i\n",name,player->level);
printf("Strength: %i \t\t\t\t\tExperience: %i\n",player->str,player->exp);
printf("HP: %i of %i\n\n",player->hp,player->maxhp);
//decide if there is a monster or not
if (roomNumber != (ROOM_ROWS * 3) + 3)
whatMonster = ismonster();
else
whatMonster = 2;
if (whatMonster == 1)
printf("\nYou are alone in the room.\n\n");
else {
if (whatMonster == 2)
boss();
else { // else - there is a monster
monsterName = nameMonster(); // choose a monster
weapon = chooseWeapon(); // give him an arbitrary weapon
printf("You have been attacked by a %s with a %s!\n", monsterName, weapon);
// the next bit of code generates the monster based on the player's level
baddie->level = generateMonsterLvl(player->level);
baddie->hp = generateMonsterHP(baddie->level);
baddie->str = generateMonsterStr(baddie->level);
printf("He is a level %i with %i hp and %i strength! What do you want to do?\n",baddie->level, baddie->hp, baddie->str);
do {
system("color 0C");
printf("\nAttack[A] or Run[R]: "); // choices, choices!
a = 0; //re-initialized for safety
clearstdin();
//fflush(stdin); //flush that crap out of the toi..er... buffer
scanf("%c",&choice);
switch ( choice ) {
case 'a' : case 'A' :
printf("You have chosen to attack!"); //player fights back
*p = 0;
player->hp = battle(player->level, player->hp, player->str, baddie->level, baddie->hp, baddie->str,p);
if (player->hp >0 && *p == 0) { //winning the fight
printf("Congrats! You won!\n");
player->exp++;
level(&player->level, &player->exp, &player->hp, &player->maxhp, &player->str);
}// end of if
if (player->hp >0 && *p != 0) { // running away successfully
printf("Congratulations, you escaped.");
}//end of if
if (player->hp <1) { // running away, not quite so successfully
printf("You lose, better luck next time.\n");
} // end of if
a=1; // used to break do-while loop for the switch
break;
case 'r' : case 'R' :
printf("You are a coward"); // trash-talk!
i = run(player->level, baddie->level); //a function for running; how geeky.
if (i == 0) { // haha! the player gets caught and pwned
printf("!\nAs you turn and run, the monster chases you down and stabs you in the back. \nThanks for playing!\n");
player->hp=0;
}
else { // our valiant coward manages to escape!
printf(" but at least you can say that you are lucky enough to run \naway. successfully!\n");
printf("You DO manager to escape, but at a loss of experience.\n");
player->exp = (player->level - 2);
}
a=1; // used to break do-while loop for the switch
break;
default : printf("No conprendo!\n\n"); //made in mexico
break;
} // this is the end of the fight/run switch-case
} while (a != 1); //the end of the do-while that loops switch for a correct response
}// end of else(monster exists)
} // end of the whatmonster != 1 or 2 else
if (player->hp > 0) { // this line prevents dead users from accessing the following code
// the next block of code determines where legal exits are
system("color 07"); // reset color from battle
outs = (roomNumber % 3);
switch ( outs ) {
case 0 : printf("There are exits to the North, South, East, and West\n");
break;
case 1 : if (roomNumber == 1)
printf("You have no choice but to head North\n");
else {
if (roomNumber == (3*ROOM_ROWS+1))
printf("There are exits to the South and West\n");
else
printf("There are exits to the North, South, and Wast\n");
}
break;
case 2 : if (roomNumber == 2)
printf("There are exits to the North, and East\n");
else {
if (roomNumber ==(3*ROOM_ROWS-1))
printf("There are exits to the South and East\n");
else
printf("There are exits to the North, South, and East\n");
break;
}
}
//after telling the user where he can go, he is given the choice of what to do
printf("What would you like to do? [C]ontinue, [S]leep, [Q]uit: ");
//clearstdin();
//fflush(stdin);
scanf("%c",&choice2);
switch ( choice2 ) { //choose-action
case 'C' : case 'c' :
printf("What direction do you want to go in? [N, S, W, E]: ");
//fflush(stdin);
clearstdin();
scanf("%c",&c);
switch ( c ) { //choose-direction
case 'n' : case 'N' :
a = 1;
break;
case 'E' : case 'e' :
a = 2;
break;
case 'S' : case 's' :
a = 3;
break;
case 'W' : case 'w' :
a = 4;
break;
} // end of switch_choose-direction
roomNumber = roomNew(roomNumber, a); // go generate a new room, based on that there switch
break; // break case C, in case you forgot
case 'S' : case 's' :
player->hp = sleep(player->maxhp); //yep, sleep's got it's own function too!
break;
case 'Q' : case 'q' :
player->hp = 0; // easiest way to quit? break the loop thats governoring most of main()
break;
default : printf("You can't do that here!"); //hehe suggestive!
} // end of switch_choose-action
} // end of the if statement for the dead folks
getchar();
//system("pause");
} // end of while loop that governs life... "The God Loop"
highscore(name,player->level);
getchar();
//system("pause");
system ("color 07"); //reset the console to the correct color
} //end of main()