I made an option selection program to use in my text game. It looks very simple, and it is (sort of), but expanding the options is extremely hard. I know it could be a lot better, so i came here.
I'll explain everything:
In my game, there are 2, 3 or 4 options to choose from to continue the game. In chapter 1, it's the main gameplay. It's always "Intro text" -> "ASCII image" -> "Outro text (sometimes)". So it's exactly what i did.
But, sometimes, when you have to test and investigate, some options dissapear when you already tried them. So i added a (very hard for me) way to completely ignore the option if you call the function with an option as "*". If you try to call it with 3 or 4 "*" options, it gives you an error. I added this feature just for fun.
So here are the arguments of the main function of the option selection:
void Main(bool IfNow, char Message1[99], char Message2[99], char Image[9999], char Op1[99], char Op2[99], char Op3[99], char Op4[99])
Boolean IfNow: If the function calling wants to show "now" in "What do you want to do"
Characterss Message1, 2 and Image: To know what to show when refreshing the screen.
Characters Op1, 2, 3 and 4: The options. As i explained, * makes it to ignore that option.
So again, I want to improve the way this works. Here is an example of what possibly can be greatly improved, the way the choosing works:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
Position=1;
Choice=getch();
if(Choice=='s' || Choice=='S'){Choice=Position; return;}
else if(Choice==72){ //Up arrow key
if(Position==1){ //Position 1
if(Op4[0]=='*'){
if(Op3[0]=='*'){Position=2;}
else{Position=3;}
}
else{Position=4;}
}
else if(Position==2){ //Position 2
if(Op1[0]=='*'){
if(Op4[0]=='*'){Position=3;}
else{Position=4;}
}
else{Position=1;}
}
else if(Position==3){ //Position 3
if(Op2[0]=='*'){
if(Op1[0]=='*'){Position=2;}
else{Position=1;}
}
else{Position=2;}
}
else if(Position==4){ //Position 4
if(Op3[0]=='*'){Position=4;}
else{Position=3;}
}
}
else if(Choice==80){ //Down arrow key
if(Position==1){ //Position 1
if(Op2[0]=='*'){
if(Op3[0]=='*'){Position=4;}
else{Position=3;}
}
else{Position=2;}
}
else if(Position==2){ //Position 2
if(Op3[0]=='*'){
if(Op4[0]=='*'){Position=1;}
else{Position=4;}
}
else{Position=3;}
}
else if(Position==3){ //Position 3
if(Op4[0]=='*'){
if(Op1[0]=='*'){Position=2;}
else{Position=1;}
}
else{Position=4;}
}
else if(Position==4){ //Position 4
if(Op1[1]=='*'){
if(Op2[0]=='*'){Position==3;}
else{Position==2;}
}
else{Position=1;}
}
}
|
The download link of the full code:
https://dl.dropbox.com/u/43721327/TCF/Working%20on/OptionSelection.cpp