![]() |
| | #1 |
| Registered User Join Date: Oct 2006
Posts: 13
| Code: #include <stdio.h>
/*Gets user's answer to a question*/
int get_chioce( void ){
int choice;
printf("?:: ");
scanf("%d", &choice);
return( choice );
}
void show_stats( hp, tired ){
printf("\n::Stats::\n|%d HP|\n|%d Awake|\n", hp, tired);
}
void adventure_begin( void ){
char name[10];
int choice;
int timeh = 8;
int timem = 0;
int timemm = 5;
char ampm[2];
ampm[1] = 'a';
ampm[2] = 'm';
printf("\nWhat is your name?\n?:");
scanf("%s", &name);
printf("Ok, your name is %s.\n", name);
printf("You are 25 and live by yourself in a 1 bedroom house\n");
printf("\n|%d:%d%d%s\n|Sunday\n|Bedroom\n|Sleeping...\n\n", timeh, timem, timemm, ampm);
printf("Adventure begins on a Sunday morning...\n");
printf("1.Get up\n");
get_chioce();
if( choice=1 ){
adventure_1( name );
}
}
int adventure_1( name ){
int timeh = 8;
int timem = 2;
int timemm = 5;
char ampm[2];
ampm[1] = 'a';
ampm[2] = 'm';
int choice;
int hp = 100;
int tired = 50;
printf("\nYou are feeling a bit hungry. You have some cereal in your pantry.\n");
printf("1.Korn Flayks\n2.Coco Pops\n3.All Bran\n4.Dont eat\n");
get_chioce();
switch( choice ){
case 1: tired = tired + 30;
break;
case 2: tired = tired + 20;
break;
case 3: tired = tired + 50;
break;
case 4: printf("\nThat could cause some problems later %s..\n", name);
break;
}
show_stats( hp, tired );
}
main()
{
int choice;
printf("\n\nWelcome to ASCII Adventure!\n\n1.Play\n2.Exit\n");
get_chioce();
/*Begin Adventure*/
switch( choice ){
case 1: adventure_begin();
break;
}
}
|
| aaron11193 is offline | |
| | #2 |
| MENTAL DETECTOR Join Date: Apr 2006 Location: United States
Posts: 3,295
| http://home.golden.net/~uberkermit/cprogramming/ In particular you'll want to look a page six in Functions to solve your problem, but I like the whole thing. |
| whiteflags is offline | |
| | #3 |
| Its hard... But im here Join Date: Apr 2005 Location: England
Posts: 1,467
| Are you getting errors warnings? What is it exactly they are not doing right, in this case it would be a logical error. Oh, and main() should return an int |
| swgh is offline | |
| | #4 |
| +++ OK NO CARRIER Join Date: Oct 2001
Posts: 10,642
| When you call get_choice, you don't actually store your return value in choice. You want something like: Code: choice = get_choice(); Code: switch( get_choice() ) Code: if( choice=1 ){
== is for equality. Remember: Assign one thing. Compare two. Nice and simple. Quzah.
__________________ Hundreds of thousands of dipshits can't be wrong. Are you up for the suck? Last edited by quzah; 10-27-2006 at 05:18 AM. |
| quzah is offline | |
| | #5 |
| and the hat of Jobseeking Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,705
| > int get_chioce( void ) Maybe spelling, but so long as you're consistent with your inconsistency, it's OK. > get_chioce(); You ignore the return result. Maybe something like choice = get_chioce(); > if( choice=1 ) Rookie mistake number 1, using = where == should be used. > void show_stats( hp, tired ) You should really have some types in here, like void show_stats( int hp, int tired ) This is in several places. > ampm[1] = 'a'; > ampm[2] = 'm'; > int choice; C doesn't allow mixed declarations and statements (though C99 does). Which compiler are you using? Are you compiling as C++ perhaps? > scanf("%s", &name); You don't need the & when using %s and a char array. |
| Salem is offline | |
| | #6 |
| Registered User Join Date: Aug 2005
Posts: 1,330
| In main you do call get_chioce() but you ignore the return-value. The following switch operates on an uninitialized variable. Kurt Edit: that was too slow. |
| ZuK is offline | |
| | #7 |
| Registered User Join Date: Oct 2006
Posts: 13
| hey thanks for all the help and tips its working fine now ![]() ill email anyone the finished product when i finish it if they want but you have to compile it yourself unless you use Linux aaron |
| aaron11193 is offline | |
| | #8 |
| Registered User Join Date: Oct 2006
Posts: 13
| can anyone help me with header files... i need to make this into a header file for the game Code: void show_time( timehh, timeh, timem, timemm ){
printf("\n|%d%d:%d%d|\n", timehh, timeh, timem, timemm );
}
void show_stats( hp, tired, cash, karma ){
printf("\n::Stats::\n|%d HP|\n|%d Awake|\n|$%d Cash|\n|Karma %d|\n", hp, tired, cash, karma);
}
int get_choice( void ){
int choice;
printf("?:: ");
scanf("%d", &choice);
return( choice );
}
thx Last edited by aaron11193; 10-27-2006 at 05:32 PM. |
| aaron11193 is offline | |
| | #9 |
| +++ OK NO CARRIER Join Date: Oct 2001
Posts: 10,642
| You don't usually put functions in a header file. You put them in their own file, and prototype them in a header file. Then you include that header wherever you need to call those functions. So in this case, we have 3 files. The file the code is in. The file the prototypes (and extern variables) are in (or referred to). The file using the stuff mentioned in the header. Quzah.
__________________ Hundreds of thousands of dipshits can't be wrong. Are you up for the suck? |
| quzah is offline | |
| | #10 |
| and the hat of Jobseeking Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,705
| > void show_stats( hp, tired, cash, karma ) It's really nice to see that people read replies |
| Salem is offline | |
| | #11 |
| Registered User Join Date: Oct 2006
Posts: 13
| this is my code now, in activity_battle the random numbers are always the same and theyre too big... Code: #include <stdio.h>
int get_choice( void ){
int choice;
printf("?:: ");
scanf("%d", &choice);
return( choice );
}
int show_stats( hp, tired, cash, karma ){
printf("\n\n::Stats::\n|%d HP|\n|%d Awake|\n|$%d Cash|\n|%d Karma|\n\n", hp, tired, cash, karma);
return 0;
}
int show_stats_menu( name, hp, tired, karma, cash, timehh, timeh, timem, timemm ){
printf("\n\n::Stats::\n|%d HP|\n|%d Awake|\n|$%d Cash|\n|%d Karma|\n\n", hp, tired, cash, karma);
menu( name, hp, tired, karma, cash, timehh, timeh, timem, timemm );
}
int show_time( timehh, timeh, timem, timemm ){
if( timeh >= 10 ){
timeh = timeh - 10;
timehh = timehh + 1;
}
printf("\n|%d%d:%d%d|\n", timehh, timeh, timem, timemm);
return 0;
}
int show_time_menu( name, hp, tired, karma, cash, timehh, timeh, timem, timemm ){
if( timeh >= 10 ){
timeh = timeh - 10;
timehh = timehh + 1;
}
printf("\n|%d%d:%d%d|\n", timehh, timeh, timem, timemm);
menu( name, hp, tired, karma, cash, timehh, timeh, timem, timemm );
}
int get_score( name, hp, tired, karma, cash, timehh, timeh, timem, timemm ){
int _score;
int _score1;
int _score2;
_score1 = cash * hp;
_score2 = tired - karma;
_score = _score1 + _score2;
printf("\nScore:: %d\n", _score);
menu( name, hp, tired, karma, cash, timehh, timeh, timem, timemm );
}
int menu( name, hp, tired, karma, cash, timehh, timeh, timem, timemm ){
printf("\n-|HOME|-\n1.Stats\n2.Time\n3.Activity\n4.Score\n5.Exit\n");
switch( get_choice() ){
case 1: show_stats_menu( name, hp, tired, karma, cash, timehh, timeh, timem, timemm );
break;
case 2: show_time_menu( name, hp, tired, karma, cash, timehh, timeh, timem, timemm );
break;
case 3: activities( name, hp, tired, karma, cash, timehh, timeh, timem, timemm );
break;
case 4: get_score( name, hp, tired, karma, cash, timehh, timeh, timem, timemm );
break;
case 5:
break;
}
}
int activities( name, hp, tired, karma, cash, timehh, timeh, timem, timemm ){
printf("\n\n-|Activities|-\n1.Go to Church\n2.Go for a walk\n3.Go to the shop\n4.Battle\n");
switch( get_choice() ){
case 1: place_church_menu( name, hp, tired, karma, cash, timehh, timeh, timem, timemm );
break;
case 2: activity_walk_menu( name, hp, tired, karma, cash, timehh, timeh, timem, timemm );
break;
case 3: place_shop_menu( name, hp, tired, karma, cash, timehh, timeh, timem, timemm );
break;
case 4: activity_battle( name, hp, tired, karma, cash, timehh, timeh, timem, timemm );
break;
}
}
int item_newspaper( void ){
printf("\n\n-|ASCII TIMES|-\nMISSING LINK FOUND!\nExperts at cambrige university\nhave found the missing\nlink to the mystery of evolution!\nThey say that we were once monkeys.\nAnd before monkeys we were dumb...\nBy Ben Dover\n\n");
}
int place_church( name, hp, tired, karma, cash, timehh, timeh, timem, timemm ){
printf("\n\nYou get into your car and drive to Church...\n-20 Karma\n\n");
karma = karma - 20;
printf("\nThe Church band starts to play a song that you like..\nYou don't usually sing but this is a long time favourite of yours...\n1.Sing\n2.Don't sing\n");
switch( get_choice() ){
case 1: printf("\n\nYou start to sing...\nYou don't know the words that well...\n-10 Karma\n-10 Awake\n");
break;
case 2: printf("You try not to sing...\nYou can't help but tap your feet...\n\n");
break;
}
printf("\nThere is about to be Holy Communion...\nWill you take it??\n1.Yes\n2.No\n");
switch( get_choice() ){
case 1: printf("\nYou go up and take Holy Communion...\n-20 Karma\n+20 HP\n-5 Awake\n\n");
break;
case 2: printf("\nYou stay seated and seem to be the odd one out...\n\n");
break;
}
timeh = timeh + 1;
if( timeh >= 10 ){
timeh = timeh - 10;
timehh = timehh + 1;
}
show_time( timehh, timeh, timem, timemm );
return( name, hp, tired, karma, cash, timehh, timeh, timem, timemm );
}
int place_church_menu( name, hp, tired, karma, cash, timehh, timeh, timem, timemm ){
printf("\n\nYou get into your car and drive to Church...\n-20 Karma\n\n");
karma = karma - 20;
printf("\nThe Church band starts to play a song that you like..\nYou don't usually sing but this is a long time favourite of yours...\n1.Sing\n2.Don't sing\n");
switch( get_choice() ){
case 1: printf("\n\nYou start to sing...\nYou don't know the words that well...\n-10 Karma\n-10 Awake\n");
break;
case 2: printf("You try not to sing...\nYou can't help but tap your feet...\n\n");
break;
}
printf("\nThere is about to be Holy Communion...\nWill you take it??\n1.Yes\n2.No\n");
switch( get_choice() ){
case 1: printf("\nYou go up and take Holy Communion...\n-20 Karma\n+20 HP\n-5 Awake\n\n");
break;
case 2: printf("\nYou stay seated and seem to be the odd one out...\n\n");
break;
}
timeh = timeh + 1;
if( timeh >= 10 ){
timeh = timeh - 10;
timehh = timehh + 1;
}
show_time( timehh, timeh, timem, timemm );
menu( name, hp, tired, karma, cash, timehh, timeh, timem, timemm );
}
int activity_walk( name, hp, tired, karma, cash, timehh, timeh, timem, timemm ){
int moneyfound;
int moneygive;
moneyfound = hp * (tired - karma);
moneygive = ( cash / 4 ) - karma;
printf("\n\nYou walk dow the footpath for a while and find $%d!\n\n", moneyfound);
printf("You walk a bit further and see a bum with a sign that says:\n'HUNGRY! NEED MUNY 4 FOOD!'\n1.Give money\n2.Don't give money\n");
switch( get_choice() ){
case 1: printf("\nYou give the bum $%d\n'THANK YOU!'", moneygive);
karma = karma - 10;
printf("\n-10 Karma\n");
break;
default: printf("\nHe'll be going hungry tonight...\n\n");
break;
}
timem = timem + 3;
if( timem >= 6 ){
timem = timem - 6;
timeh = timeh + 1;
}
return( name, hp, tired, karma, cash, timehh, timeh, timem, timemm );
}
int activity_walk_menu( name, hp, tired, karma, cash, timehh, timeh, timem, timemm ){
int moneyfound;
int moneygive;
moneyfound = hp * (tired - karma);
moneygive = ( cash / 4 ) - karma;
printf("\n\nYou walk dow the footpath for a while and find $%d!\n\n", moneyfound);
cash = cash + moneyfound;
printf("You walk a bit further and see a bum with a sign that says:\n'HUNGRY! NEED MUNY 4 FOOD!'\n1.Give money\n2.Don't give money\n");
switch( get_choice() ){
case 1: printf("\nYou give the bum $%d\n'THANK YOU!'", moneygive);
karma = karma - 10;
cash = cash - moneygive;
printf("\n-10 Karma\n");
break;
default: printf("\nHe'll be going hungry tonight...\n\n");
break;
}
timem = timem + 3;
if( timem >= 6 ){
timem = timem - 6;
timeh = timeh + 1;
}
menu( name, hp, tired, karma, cash, timehh, timeh, timem, timemm );
}
place_shop( name, hp, tired, karma, cash, timehh, timeh, timem, timemm ){
show_stats( hp, tired, cash, karma );
printf("\nWelcome to FoodMart\n\n");
printf("This is what we have in stock:\n1.Water $30\n2.Coke $100\n3.Pie $1000\n4.Mc........burger $2000\n");
switch( get_choice() ){
case 1: printf("\n\nBought water...\n+20 HP\n+20 Awake\n\n");
cash = cash - 30;
hp = hp + 20;
tired = tired + 20;
break;
case 2: printf("\n\nBought Coke...\n+30 HP\n+40 Awake\n\n");
cash = cash - 100;
hp = hp + 30;
tired = tired + 40;
break;
case 3: printf("\n\nBought Pie...\n+300 HP\n+300 Awake\n\n");
cash = cash - 1000;
hp = hp + 300;
tired = tired + 300;
break;
case 4: printf("\n\nBought Mc........burger\n+600 HP\n+200\n\n");
cash = cash - 2000;
hp = hp + 600;
tired = tired + 200;
break;
}
timem = timem + 3;
if( timem >= 6 ){
timem = timem - 6;
timeh = timeh + 1;
}
printf("Is that all?\n1.Yes\n2.No\n");
switch( get_choice() ){
case 1:
break;
case 2: place_shop( name, hp, tired, karma, cash, timehh, timeh, timem, timemm );
break;
}
}
place_shop_menu( name, hp, tired, karma, cash, timehh, timeh, timem, timemm ){
show_stats( hp, tired, cash, karma );
printf("\nWelcome to FoodMart\n\n");
printf("This is what we have in stock:\n1.Water $30\n2.Coke $100\n3.Pie $1000\n4.Mc........burger $2000\n");
switch( get_choice() ){
case 1: printf("\n\nBought water...\n+20 HP\n+20 Awake\n\n");
cash = cash - 30;
hp = hp + 20;
tired = tired + 20;
break;
case 2: printf("\n\nBought Coke...\n+30 HP\n+40 Awake\n\n");
cash = cash - 100;
hp = hp + 30;
tired = tired + 40;
break;
case 3: printf("\n\nBought Pie...\n+300 HP\n+300 Awake\n\n");
cash = cash - 1000;
hp = hp + 300;
tired = tired + 300;
break;
case 4: printf("\n\nBought Mc........burger\n+600 HP\n+200\n\n");
cash = cash - 2000;
hp = hp + 600;
tired = tired + 200;
break;
}
timem = timem + 3;
if( timem >= 6 ){
timem = timem - 6;
timeh = timeh + 1;
}
printf("Is that all?\n1.Yes\n2.No\n");
switch( get_choice() ){
case 1:
break;
case 2: place_shop( name, hp, tired, karma, cash, timehh, timeh, timem, timemm );
break;
}
menu( name, hp, tired, karma, cash, timehh, timeh, timem, timemm );
}
int activity_battle( name, hp, tired, karma, cash, timehh, timeh, timem, timemm ){
int youhit;
int gethit;
youhit = rand(10);
gethit = rand(10);
printf("%d-%d", youhit, gethit);
}
void adventure_begin( void ){
char name[10];
int timehh = 0;
int timeh = 8;
int timem = 0;
int timemm = 5;
printf("\nWhat is your name?\n?:");
scanf("%s", &name);
printf("\nOk, your name is %s.\n", name);
printf("You are 25 and live by yourself in a 1 bedroom house\n");
printf("\n|%d%d:%d%d\n|Sunday\n|Bedroom\n|Sleeping...\n\n", timehh, timeh, timem, timemm);
printf("Sunday morning...\n\n");
printf("1.Get up\n");
timem = timem + 2;
if( timem >= 6 ){
timem = timem - 6;
timeh = timeh + 1;
}
switch( get_choice() ){
case 1: adventure_1( name, timehh, timeh, timem, timemm );
break;
}
}
int adventure_1( name, timehh, timeh, timem, timemm ){
int hp = 50;
int tired = 50;
int cash = 100;
int karma = 0;
printf("\nYou are feeling a bit hungry. You have some cereal in your pantry.\n");
printf("1.Korn Flayks\n2.Coco Pops\n3.All Bran\n4.Dont eat\n");
switch( get_choice() ){
case 1: tired = tired + 30;
hp = hp + 30;
printf("\n+30 Awake\n+30 HP\n");
break;
case 2: tired = tired + 30;
hp = hp + 10;
printf("\n+30 Awake\n+10 HP\n");
break;
case 3: tired = tired + 10;
hp = hp + 50;
printf("\n+10 Awake\n+50 HP\n");
break;
case 4: printf("\nThat could cause some problems later %s..\n", name);
break;
}
timemm = timemm + 5;
if( timemm >= 10 ){
timemm = timemm - 10;
timem = timem + 1;
}
show_time( timehh, timeh, timem, timemm );
show_stats( hp, tired, cash, karma );
adventure_2( name, hp, tired, karma, cash, timehh, timeh, timem, timemm );
}
int adventure_2( name, hp, tired, karma, cash, timehh, timeh, timem, timemm ){
printf("You finish your breakfast and walk to the front door...\n");
printf("The paperboy rides past and throws you the paper...\n");
switch( tired ){
case 60: printf("You catch it one handed...\n\n");
break;
case 80: printf("You catch it one handed...\n\n");
break;
default: printf("You struggle to see it as it comes towards you...\nIt hits you in the forehead\n\n");
break;
}
printf("Would you like to read the newspaper??\n1.Read it\n2.Don't read it\n");
switch( get_choice() ){
case 1: item_newspaper();
break;
}
timemm = timemm + 5;
if( timemm >= 10 ){
timemm = timemm - 10;
timem = timem + 1;
}
show_time( timehh, timeh, timem, timemm );
printf("\n\nYou can't just do nothing all day..\nHere's what you can do at this morning:\n1.Go to Church\n2.Go for a walk\n3.Go to the shop\n");
switch( get_choice() ){
case 1: place_church( name, hp, tired, karma, cash, timehh, timeh, timem, timemm );
break;
case 2: activity_walk( name, hp, tired, karma, cash, timehh, timeh, timem, timemm );
break;
case 3: place_shop( name, hp, tired, karma, cash, timehh, timeh, timem, timemm );
break;
}
menu( name, hp, tired, karma, cash, timehh, timeh, timem, timemm );
}
main()
{
int choice;
printf("\n\nWelcome to ASCII RPG!\n\n1.Play\n2.Exit\n");
/*Begin Adventure*/
switch( get_choice() ){
case 1: adventure_begin();
break;
}
}
|
| aaron11193 is offline | |
| | #12 |
| Registered User Join Date: Aug 2005
Posts: 1,330
| Adding to salems comment. You should compile a little more often. The compiler would tell you that such things Code: int show_stats( hp, tired, cash, karma ){
Kurt |
| ZuK is offline | |
| | #13 |
| and the hat of Jobseeking Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,705
| He's probably compiling with some brain-dead fossil compiler like turbo-c which silently declares everything as int. Which was perfectly valid C - about 20 years ago! Just another "works for me" type who's happy so long as it works rather than actually bothering to learn how to do it properly. |
| Salem is offline | |
| | #14 |
| Registered User Join Date: Oct 2006
Posts: 13
| hey i tried putting types in the parameters and it gave me some errors about wrong types or something when i had char.. eg.. Code: int show_time_menu( char name, int hp, int tired, int karma, int cash, int timehh, int timeh, int timem, int timemm ){
if( timeh >= 10 ){
timeh = timeh - 10;
timehh = timehh + 1;
}
printf("\n|%d%d:%d%d|\n", timehh, timeh, timem, timemm);
menu( name, hp, tired, karma, cash, timehh, timeh, timem, timemm );
}
|
| aaron11193 is offline | |
| | #15 |
| Registered User Join Date: Oct 2006
Posts: 13
| BIG problem here.... i made a linux executable of the game and accidentally deleted the source file and the game still has a few bugs...... is there any way of extracting the source from the executable?? PLZ HELP!!! |
| aaron11193 is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| problem | ExDHaos | C++ Programming | 12 | 05-22-2009 04:50 AM |
| (dev) C++ Ascii Rpg | kevinawad | General Discussions | 11 | 08-10-2008 11:10 AM |
| No atoh() function in C ( Ascii To Hex )? - Well, Let's Create One | dedham_ma_man | C Programming | 11 | 03-24-2006 11:26 AM |
| Office access in C/C++ NOT VC++!! :) | skawky | C++ Programming | 1 | 05-26-2005 01:43 PM |
| ascii values for keys | acid45 | C Programming | 2 | 05-12-2003 07:13 AM |