📄 poa.cpp
字号:
} while(exitGame != 0);
return 0;
}
// Display and Manipulator Function Definitions
void FullScreen(){
keybd_event(VK_MENU, 0x38, 0, 0);
keybd_event(VK_RETURN, 0x1c, 0, 0);
keybd_event(VK_RETURN, 0x1c, KEYEVENTF_KEYUP, 0);
keybd_event(VK_MENU, 0x38, KEYEVENTF_KEYUP, 0);
return;
}
void SizeWindow(){
HANDLE hOut;
CONSOLE_SCREEN_BUFFER_INFO SBInfo;
SMALL_RECT DisplayArea = {0, 0, 0, 0};
int x;
int y;
hOut = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hOut, &SBInfo);
x = SBInfo.srWindow.Bottom;
y = SBInfo.srWindow.Right;
DisplayArea.Bottom = TOTALROW - 1;
DisplayArea.Right = COLSIZE - 1;
if(x == DisplayArea.Bottom){
x = x; //Do nothing, all is good
}
else if(x > DisplayArea.Bottom){
while(x != TOTALROW - 1){
x--;
DisplayArea.Bottom = x;
SetConsoleWindowInfo(hOut, TRUE, &DisplayArea);
Sleep(25);
}
}
else{
while(x != TOTALROW - 1){
x++;
DisplayArea.Bottom = x;
SetConsoleWindowInfo(hOut, TRUE, &DisplayArea);
Sleep(25);
}
}
if(y == DisplayArea.Right){
y = y; //Do nothing, all is good
}
else if(y > DisplayArea.Right){
while(y != COLSIZE){
y--;
DisplayArea.Right = y;
SetConsoleWindowInfo(hOut, TRUE, &DisplayArea);
Sleep(25);
}
}
else{
while(y != COLSIZE){
y++;
DisplayArea.Right = y;
SetConsoleWindowInfo(hOut, TRUE, &DisplayArea);
Sleep(25);
}
}
}
void arrows(char *string, int cent, int y, int xmin, int xmax){
if(cent == 0){
char newString[strlen(string) + 2];
newString[0] = char(16);
newString[1] = '\0';
strcat(newString, string);
newString[strlen(string) + 1] = char(17);
newString[strlen(string) + 2] = '\0';
centerText(newString, y, xmin, xmax, GOLD);
}
else{
cout<<(char)16<<string<<(char)17<<flush;
}
}
void wordwrap(char text[], int maxlength, char replacement[]){
char display[maxlength + 1];
int index;
char editedText[strlen(text) + ((strlen(replacement) + 1) * 3)];
int totalSize = 0;
int readSize = 0;
int counter;
int counter1 = 0;
for(index = 0; index < strlen(text); index++){
if(text[index] != '%'){
editedText[index + ((strlen(replacement) - 1) * counter1)] = text[index];
editedText[index + ((strlen(replacement) - 1) * counter1) + 1] = '\0';
}
else{
strncat(editedText, replacement, strlen(replacement));
counter1++;
}
}
totalSize = strlen(editedText);
char rearrangedText[totalSize];
for(strncpy(display, editedText, maxlength); readSize <= totalSize; strncpy(display, editedText, maxlength)){
display[maxlength] = '\0';
readSize = readSize + maxlength;
counter = maxlength - 1;
if(display[maxlength] != ' '){
do{
counter--;
strncpy(display, editedText, counter);
} while(display[counter] != ' ');
strncpy(display, editedText, counter);
display[counter] = '\0';
cout<<display<<endl;
}
else{
cout<<display<<endl;
}
strcpy(rearrangedText, editedText);
for(index = 0; index <= totalSize - counter; index++){
rearrangedText[index] = editedText[index + counter];
}
strcpy(editedText, rearrangedText);
}
cout<<display<<endl;
}
// Random Number Generators
int randomNum(int min, int max){
int range;
int num;
range = max - min;
range++;
num = rand()%range;
num += min;
return(num);
}
int randomLvl(int minlvl, int maxlvl, char type[]){
int range;
int num;
int minlvlid;
int maxlvlid;
int index;
if(strcmp(type, "Monster") == 0){
if(minlvl >= MAXMONSTERLVL){
minlvlid = TOTALMONSTERS;
maxlvlid = TOTALMONSTERS;
}
else if(maxlvl >= MAXMONSTERLVL){
minlvlid = searchforid("Monsterslvl", minlvl);
maxlvlid = TOTALMONSTERS;
}
else{
minlvlid = searchforid("Monsterslvl", minlvl);
maxlvlid = searchforid("Monsterslvl", maxlvl + 1);
}
}
else if(strcmp(type, "Item") == 0){
if(minlvl >= MAXITEMLVL){
minlvlid = TOTALITEMS;
maxlvlid = TOTALITEMS;
}
else if(maxlvl >= MAXITEMLVL){
minlvlid = searchforid("Itemslvl", minlvl);
maxlvlid = TOTALITEMS;
}
else{
minlvlid = searchforid("Itemslvl", minlvl);
maxlvlid = searchforid("Itemslvl", maxlvl + 1);
}
}
else if(strcmp(type, "Spell") == 0){
if(minlvl >= MAXSPELLLVL){
minlvlid = TOTALSPELLS;
maxlvlid = TOTALSPELLS;
}
else if(maxlvl >= MAXSPELLLVL){
minlvlid = searchforid("Spellslvl", minlvl);
maxlvlid = TOTALSPELLS;
}
else{
minlvlid = searchforid("Spellslvl", minlvl);
maxlvlid = searchforid("Spellslvl", maxlvl + 1);
}
}
else{
Error("Error: randomLvl: type Not Found!");
}
range = maxlvlid - minlvlid;
num = rand()%range;
num += minlvlid;
return(num);
}
// Menu Function Definitions
int menu(int starty, int startx, int max, ...){
// A negative value for startx will shift the menu stuff to the left, a positve value will shift it to the right
// For Example:
// If startx = -20, then the menu information will be centered between 0 and +20
// If startx = 20, then the menu information will be centered between 20 and COLSIZE
int move;
int arrowmove;
int loop = 1;
int choice = 1;
char* strs[max];
int counter = 0;
va_list strings;
va_start(strings, max);
for(int x = 0; x < max; x++)
strs[counter++] = va_arg(strings, char*);
va_end(strings);
while(loop != 0){
if(choice == max + 1)
choice = 1;
else if(choice == 0)
choice = max;
for(int index = 0; index < max; index++){
gotoxy(starty + index, startx);
if(index + 1 == choice){
if(startx >= 0)
arrows(strs[index], 0, starty + index, startx);
else
arrows(strs[index], 0, starty + index, 0, -startx);
}
else{
if(startx >= 0)
centerText(strs[index], starty + index, startx, COLSIZE);
else
centerText(strs[index], starty + index, 0, -startx);
cout<<" "; // To get rid of arrow that may be appended from when
// the arrow was pointed here
}
}
gotoxy(0, 0); cout<<flush;
move = getch();
switch(move){
case 224:
arrowmove = getch();
switch(arrowmove){
case 72: // Up Arrow Pressed
choice -= 1;
break;
case 80: // Down Arrow Pressed
choice += 1;
break;
default:
break;
}
break;
case 13: // Enter Pressed
loop = 0;
break;
default:
break;
}
}
return(choice);
}
int charactermenu(int starty, int startx, int max, ...){
int move;
int arrowmove;
int test = 1;
int choice = 1;
char* strs[max];
int counter = 0;
CCharacter tempchar;
int temppot_id[] = {1, 7, 0, 0, 0, 0};
int tempspell_id[] = {0, 0, 0, 0, 0};
int tempinv_id[] = {0, 0, 0, 0};
va_list strings;
va_start(strings, max);
for(int x = 0; x < max; x++)
strs[counter++] = va_arg(strings, char*);
va_end(strings);
centerText("STARTING STATS ARE SHOWN BELOW", 28, startx);
while(test != 0){
if(choice == max + 1)
choice = 1;
else if(choice == 0)
choice = max;
for(int index = 0; index < max; index++){
gotoxy(starty + index, startx);
if(index + 1 == choice){
arrows(strs[index], 0, starty + index);
switch(choice){
case 1:
temppot_id[0] = 1;
temppot_id[1] = 7;
tempchar.assembleChar("Unknown", "Barbarian", 0, 100, 1, 100, 100, 20, 20, 11, 6, 11, 2, 1, 0, 0, 0, tempspell_id, tempinv_id, temppot_id, 0, 0);
break;
case 2:
tempspell_id[0] = 0;
tempspell_id[1] = 0;
tempchar.assembleChar("Unknown", "Knight", 0, 100, 1, 75, 75, 50, 50, 8, 8, 8, 6, 2, 0, 0, 0, tempspell_id, tempinv_id, temppot_id, 0, 0);
break;
case 3:
tempspell_id[0] = 1;
tempspell_id[1] = 2;
tempchar.assembleChar("Unknown", "Sorcerer", 0, 100, 1, 50, 50, 100, 100, 6, 8, 6, 10, 3, 0, 0, 0, tempspell_id, tempinv_id, temppot_id, 0, 0);
break;
case 4:
tempspell_id[0] = 0;
tempspell_id[1] = 0;
temppot_id[0] = 1;
temppot_id[1] = 7;
tempchar.assembleChar("Unknown", "Elf", 0, 100, 1, 60, 60, 75, 75, 6, 10, 7, 7, 4, 0, 0, 0, tempspell_id, tempinv_id, temppot_id, 0, 0);
break;
case 5:
temppot_id[0] = 0;
temppot_id[1] = 0;
tempchar.assembleChar("Unknown", "Unknown", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, tempspell_id, tempinv_id, temppot_id, 0, 0);
break;
default:
Error("Error: charactermenu: Unknown choice (choice = ", 2, IntStr(choice).str, ")");
}
clrnon_border(1, 1, 0, 0, 0);
tempchar.displayinfo(1, 0, 0, 0);
}
else{
centerText(strs[index], starty + index, startx);
cout<<" "; // To get rid of arrow that may be appended from when
// the arrow was pointer here
}
}
gotoxy(0, 0);
cout<<flush;
move = getch();
switch(move){
case 224:
arrowmove = getch();
switch(arrowmove){
case 72: // Up Arrow Pressed
choice -= 1;
break;
case 80: // Down Arrow Pressed
choice += 1;
break;
default:
break;
}
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -