1
Name:
Anonymous
2010-06-29 14:04
The Challenge:
-Develop a turn based combat system that implements the following choices that occur during the player's turns:
--Fight (Straight Damage)
--Item (Use an object from a choice of your design)
--Ability (Use an ability from a choice of your design)
--Run (Flee the battle)
The Deadline:
- 2010-07-01 00:00
The rest is up to you.
19
Name:
Anonymous
2010-06-29 19:59
ehy [spolier]/prog/[spoiler] im drunk
#include <curses.h>
#include <stdlib.h>
char *commands[] =
{
"Fight",
"Item",
"Ability",
"Run"
};
char *comments[] =
{
"pew pew",
"Use items",
"Conjure the spirits with your spells",
"Run away like a little girl"
};
char *items[] =
{
"Wizard hat",
"SICP",
"cudder"
};
char *abilities[] =
{
"Summon /prog/snake",
"Read SICP"
};
int nabilities = 2;
int nitems = 3;
int ncommands = 4;
void print_menu(WINDOW *win, char **menu, int current, int number);
void print_submenu(char **choices, int nchoices);
void print_progsnake();
void read_sicp();
void print_menu(WINDOW *win, char **menu, int current, int number)
{
int i;
for(i=0; i<number; i++)
{
if(i==current) wattron(win, A_REVERSE);
mvwprintw(win, i+1, 2, menu[i]);
if(i==current) wattroff(win, A_REVERSE);
}
}
void print_submenu(char **choices, int nchoices)
{
WINDOW *sub_win;
int current = 0;
int c;
int i;
sub_win = newwin(nitems+2, 25, 3, 3);
box(sub_win, 0, 0);
refresh();
print_menu(sub_win, choices, current, nchoices);
wrefresh(sub_win);
while((c = getch()) != 'q')
{
switch(c)
{
case KEY_DOWN:
current = (current + 1) % nchoices;
print_menu(sub_win, choices, current, nchoices);
break;
case KEY_UP:
if(--current<0) current=nchoices-1;
print_menu(sub_win, choices, current, nchoices);
break;
case '\n':
if(strcmp(choices[current], abilities[0])==0)
print_progsnake();
if(strcmp(choices[current], abilities[1])==0)
read_sicp();
break;
default:
break;
}
refresh();
wrefresh(sub_win);
}
werase(sub_win);
}
void print_progsnake()
{
int i;
char *snake[] =
{
"_ ___.....___ ",
" `.__ ,-' ,-.`-, ",
" `''-------' ( p ) `._ ",
" `-' ( ",
" \\ ",
" . \\ ",
" \\---..,--' ",
"................._ --...--, ",
" `-.._ _.-' ",
" `'-----'' "
};
for(i=0; i<14; i++)
mvprintw(LINES - i, 0, " ");
for(i=0; i<10; i++)
mvprintw(LINES - 10+i, 0, "%s\n", snake[i]);
refresh();
}
void read_sicp()
{
int i;
char *sussman[] =
{
" . . ,.\".\".'\"\"\"..",
" . ,__\\.~~",
" . ;'``` '`` \\!\"",
" . `. \\~\"",
" .., ' ____________|'~\"",
" `. .__/ |_| |\\",
" `..' | = / | = ||",
" | \\___/ |\\___|\\/",
" | _| |",
" \\ __ |",
" \\ /__\\ ./",
" |`'._____.'|",
" /| /\\"
};
for(i=0; i<13; i++)
mvprintw(LINES - 13+i, 0, "%s\n", sussman[i]);
refresh();
}
int main()
{
WINDOW *menu_win, *comment_win, *alert_win;
int current_command = 0;
int c;
int i;
initscr();
cbreak();
noecho();
keypad(stdscr, 1);
curs_set(0);
menu_win = newwin(ncommands+2, 40, 1, 1);
comment_win = newwin(3, 40, 3+ncommands, 1);
alert_win = newwin(3, 20, 5, 10);
print_menu(menu_win, commands, current_command, ncommands);
box(menu_win, 0, 0);
box(comment_win, 0, 0);
mvwprintw(comment_win, 1, 1, "%s", comments[current_command]);
refresh();
wrefresh(comment_win);
wrefresh(menu_win);
keypad(menu_win, 1);
while((c = getch()) != 'q')
{
switch(c)
{
case KEY_DOWN:
current_command = (current_command+1) % ncommands;
print_menu(menu_win, commands, current_command, ncommands);
break;
case KEY_UP:
if(--current_command<0) current_command=ncommands-1;
print_menu(menu_win, commands, current_command, ncommands);
break;
case '\n':
switch(current_command)
{
case 0:
break;
case 1:
print_submenu(items, nitems);
break;
case 2:
print_submenu(abilities, nabilities);
break;
case 3:
box(alert_win, 0, 0);
mvwprintw(alert_win, 1, 1, "You can't escape!");
wrefresh(alert_win);
getch();
wclear(alert_win);
wrefresh(alert_win);
break;
}
print_menu(menu_win, commands, current_command, ncommands);
box(menu_win, 0, 0);
break;
case 'p':
print_progsnake();
break;
}
wclear(comment_win);
box(comment_win, 0, 0);
mvwprintw(comment_win, 1, 1, "%s", comments[current_command]);
refresh();
wrefresh(comment_win);
wrefresh(menu_win);
}
endwin();
}