![]() |
Portfolio
Below can be found two C++ programs that Stephen Fluin began making in 1998 in his spare time. . The concept behind the program was that it would practice interaction with a changeable file, while at the same time mimicking a single player text based role playing game known as a MUD. Also check out the Yahtzee game he designed, complete with high score tables and customizable themes. This project is also in the process of being ported into Flash. |
Troll_Attack.cpp
Rooms.txt
//Troll_Attack.cpp © Stephen Fluin 2002
//Modified Dec. 14, 2002
//Programmed by Stephen Fluin and areas written by Stephen Fluin.
//---------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream.h>
#include <conio.h>
int cur_room=1;
struct char_data { //information about the character
char prompt[60];
int hit, max_hit, xp;
int objects[30];
} ch;
struct room_data { //information about the rooms
char name[40], desc[256];
int east, up, down, west, north, south, ne, sw, se, nw, amtobj, objects[32];
} room[100];
struct object_data { //information about the objects
char name[40], longd[60], shortd[40];
int hp;
} object[100];
//soon to come: information about the mobs
void look_room(int cur_room=1);
void show_prompt();
void read_command(char arg[32]);
void do_score();
int times;
int main()
{
int a,location=0;
char command[40];
strcpy(ch.prompt,"&G<&R%h&G/&R%H&G-&z%x&G>
%T");
ch.hit=60;
ch.max_hit=60;
ch.xp=1;
strcpy(command,"");
#include "Rooms.txt"
textcolor(WHITE);
cprintf("Welcome to: _______ ______ _______ ___ ___ \n\r");
cprintf(" / / / __ / / __ // / / / \n\r");
cprintf(" /__ __/ / /_/ / / /_/ // / / / \n\r");
cprintf(" / / / __ / / // /____ / /____ \n\r");
cprintf(" /_/ /_/ \_\/______//_______//_______/ \n\r");
cprintf(" _ _______ _______ _ __ _ __ \n\r");
cprintf(" / \ / // // \ / _\ / \/ / \n\r");
cprintf(" / ^ \ /__ __//__ __// ^ \ | | / / \n\r");
cprintf(" / / \ \ / / / / / / \ \ | |_ / \\n\r");
cprintf(" /_/ \ \ /_/ /_/ /_/ \_\\__/ /__/\___\\n\r");
textcolor(GREEN);
cprintf(" [--Press Enter--]\n\r");
getch();
look_room(cur_room);
while(cur_room) //main loop
{ //
if(kbhit())
{
if(command[0]==' ')
show_prompt(); // prompt
a=getch();
switch (a) {
case 13: // get input
location=0;
strcpy(arg,command); // copy command into global var 'arg'
read_command(command);
break;
case 108:
command[location]='l';
cprintf("l");
location++;
break;
case 27:
strcpy(command,"quit");
break;
default:
command[location]=a;
cprintf("\n\rYour current command:%s, %d, in position %d.",command,
command[location],location);
location++;
break; // use the global 'arg' to do the command
}
}
times++;
} //
textcolor(LIGHTBLUE);
cprintf("\n\r\n\r[connection closed]\n\r");
getch();
return 0;
}
void look_room(int cur_room)
{
textcolor(WHITE);
cprintf("%s\n\r",room[cur_room].name);
textcolor(YELLOW);
cprintf("%s\n\r",room[cur_room].desc);
textcolor(WHITE);
cprintf("Exits: ");
int exits=0;
if (room[cur_room].east) { cprintf("East"); exits++; }
if (room[cur_room].west) { if (exits>0) cprintf(", ");cprintf("West");
exits++; }
if (room[cur_room].south) { if (exits>0) cprintf(", ");cprintf("South");
exits++; }
if (room[cur_room].north) { if (exits>0) cprintf(", ");cprintf("North");
exits++; }
if (room[cur_room].ne) { if (exits>0) cprintf(", ");cprintf("Northeast");
exits++; }
if (room[cur_room].sw) { if (exits>0) cprintf(", ");cprintf("Southwest");
exits++; }
if (room[cur_room].nw) { if (exits>0) cprintf(", ");cprintf("Northwest");
exits++; }
if (room[cur_room].se) { if (exits>0) cprintf(", ");cprintf("SouthEast");
exits++; }
if (room[cur_room].up) { if (exits>0) cprintf(", ");cprintf("Up");
exits++; }
if (room[cur_room].down) { if (exits>0) cprintf(", ");cprintf("Down");
exits++; }
cprintf("\n\r\n\r");
}
void show_prompt()
{
int i=0, n=0;
char stat;
int num_stat;
while(ch.prompt[i])
{
if(ch.prompt[i]=='%')
{
switch(ch.prompt[i+1]) {
case 'h':
cprintf("%d",ch.hit);
break;
case 'H':
cprintf("%d",ch.max_hit);
break;
case 'x':
cprintf("%d",ch.xp);
break;
case 'T':
cprintf("%d",times);
break;
}
i+=2;
}
else if(ch.prompt[i]=='&')
{
switch(ch.prompt[i+1]) {
case 'r':
textcolor(RED);
break;
case 'R':
textcolor(LIGHTRED);
break;
case 'g':
textcolor(GREEN);
break;
case 'G':
textcolor(LIGHTGREEN);
break;
case 'z':
textcolor(LIGHTGRAY);
break;
}
i+=2;
}
else
{
cprintf("%c",ch.prompt[i]);
n++;
i++;
}
}
textcolor(WHITE);
}
void read_command(char arg[32])
{
if(!strcmpi(arg,"quit")) cur_room=0;
else if(!strcmpi(arg,"south")||!strcmpi(arg,"s"))
{if(room[cur_room].south) {cur_room=room[cur_room].south;look_room(cur_room);}
else cprintf("Alas, you cannot go that way.");}
else if(!strcmpi(arg,"east")||!strcmpi(arg,"e")) {if(room[cur_room].east)
{cur_room=room[cur_room].east;look_room(cur_room);} else cprintf("Alas,
you cannot go that way."); }
else if(!strcmpi(arg,"north")||!strcmpi(arg,"n"))
{if(room[cur_room].north) {cur_room=room[cur_room].north;look_room(cur_room);}
else cprintf("Alas, you cannot go that way."); }
else if(!strcmpi(arg,"west")||!strcmpi(arg,"w")) {if(room[cur_room].west)
{cur_room=room[cur_room].west;look_room(cur_room);} else cprintf("Alas,
you cannot go that way."); }
else if(!strcmpi(arg,"look")||!strcmpi(arg,"l")) {look_room(cur_room);}
else if(!strcmpi(arg,"score")||!strcmpi(arg,"sc"))
{do_score();}
else if(!strcmpi(arg,"goto")) {int roomy;cprintf("Room:");cin>>roomy;cur_room=roomy;look_room(cur_room);}
else {textcolor(YELLOW);cprintf("Huh? \"%s\"\n\r",arg);}
strcpy(arg,"");
}
void do_score()
{
cprintf("Your players stats: %d/%d Hit Points, %d Experience.\n\r",ch.hit,ch.max_hit,ch.xp);
cprintf(" Prompt: %s"), ch.prompt;
}
//End of Troll_Attack.cpp programmed by Stephen Fluin
//BEGIN OF Rooms.txt
strcpy(room[1].name,"Welcome");
strcpy(room[1].desc,"As you enter the realm you have a strange feeling,
you can sense that these realms are not happy ones. A plague upon the
land. In the distance you see trolls, walking near the bodies of the dead.
The scent of evil trolls is in the air.");
room[1].south=2; //Stephen Fluin
room[1].amtobj=1;
room[1].objects[1]=1;
strcpy(room[2].name,"To The South");
strcpy(room[2].desc,"The surrounding bushes here are coated with
blood. Dismembered human carcasses remain on the floor.");
room[2].north=1;
room[2].east=4;
room[2].south=3;
room[2].amtobj=0;
strcpy(room[3].name,"Outside the Village");
strcpy(room[3].desc,"Numerous more carcasses litter the ground. You
see small foot prints in the dirt. These footprints lead south, into the
village.");
room[3].north=2;
room[3].east=5;
room[3].amtobj=0;
strcpy(room[4].name,"Small Cabin");
strcpy(room[4].desc,"The inside of this cabin is filled with furniture.
It is difficult to manuver from one end of the room to the other. The
unlucky previous owner's remains litter the room. Need a cabin?");
room[4].west=2;
room[4].amtobj=0;
strcpy(room[5].name,"North of The Village");
room[5].west=3;
room[5].east=6;
room[5].amtobj=0;
strcpy(room[6].name,"North of The Village");
room[6].west=5;
room[6].south=7;
room[6].amtobj=0;
strcpy(room[7].name,"Main Street");
room[7].north=6;
room[7].west=8;
room[7].south=10;
room[7].amtobj=0;
strcpy(room[8].name,"Main Street");
room[8].east=7;
room[8].south=9;
room[8].west=13;
room[8].amtobj=0;
strcpy(room[9].name,"The Baker's Emporium");
room[9].north=8;
room[9].amtobj=0;
strcpy(room[10].name,"The Candle Stick Maker's Emporium");
room[10].north=7;
room[10].amtobj=0;
strcpy(room[11].name,"Main Street");
room[11].west=7;
room[11].east=12;
room[11].amtobj=0;
strcpy(room[12].name,"Main Street");
room[12].west=11;
room[12].amtobj=0;
room[13].east=8;
room[13].amtobj=0;
strcpy(object[1].name,"Sword of Light");
strcpy(object[1].longd,"A brilliant white sword lies here.");
strcpy(object[1].shortd,"The Sword of Light");
object[1].hp=40; //Stephen Fluin
//END OF Rooms.txt WRITTEN BY STEPHEN FLUIN
© 2003-2012 MortalPowers, Inc.
