Cpp.file
Code:
# include "curses.h"
# include "rocket.h"
#include <iostream>
using namespace std;
CRocket::CRocket()
{
initscr();
start_color();
init_pair(1, COLOR_CYAN, COLOR_BLACK);
init_pair(2, COLOR_RED, COLOR_BLACK);
mColorRise = 1;
mColorExplosion = 2;
curs_set(0); //hide cursor
}//Initialize
CRocket::~CRocket()
{
timeout(-1); // turn timeout off
printw("\n Press any key to exit \n");
refresh();
getch();
endwin();
//return ;
}
void CRocket::Rise(int TopDistance)
{
int row,col,i;
getmaxyx(stdscr,row,col);
attron(COLOR_PAIR(1));
for(i=row; i> EXPLOSION_LEVEL;i--)
{
mvprintw(i, col/2,"%c", '|');
refresh();
timeout(100); //hack to get a delay. We wait 100ms for user input
getch(); //then move on as the user does nothing
}
attroff(COLOR_PAIR(1));
}//Rise
void CRocket:: Explode(int ExplosionLevel)
{
int col,row, i;
attron(COLOR_PAIR(2));
getmaxyx(stdscr,row,col);
mvprintw(ExplosionLevel, col/2,"%c", 'X');
refresh();
for(i=0; i< 3;i++)
{
mvprintw(ExplosionLevel + i, col/2-i,"%c", 'X');
mvprintw(ExplosionLevel - i, col/2+i,"%c", 'X');
mvprintw(ExplosionLevel - i, col/2-i,"%c", 'X');
mvprintw(ExplosionLevel + i, col/2+i,"%c", 'X');
}
//mvprintw( ExplosionLevel -i, col/ 2+i ,"%c", 'X');
flash();
refresh();
timeout(1000); //hack to get a delay. We wait 100ms for user input
getch();
erase(); //then move on as the user does nothing
attroff(COLOR_PAIR(2));
}//Explode
Current code:
Code:
//fireworks demo application, spring of 2011
// more complex version of the assignment used in the first programming course
//uses a struct to keep rocket properties: add functions for initialization,
//rocket rise and explosion
#include <curses.h>
#include "fireworks.h"
int main()
{
rocket my_rockets[2];
int level;
int counter;
initscr();
Initialize(my_rockets, 2);
counter =0;
while(counter < 2)
{
level = Rise(&my_rockets[counter]);
Explode(&my_rockets[counter], level);
timeout(1000);
getch();
erase();
counter++;
}//while
timeout(-1); // turn timeout off
printw("\n Press any key to exit\n");
refresh();
getch();
endwin();
return 0;
}
void Initialize( rocket *init_rockets, int amount)
{
start_color();
// gör det med en loop enligt amount-variabeln
init_pair(1, COLOR_CYAN, COLOR_BLACK);
init_pair(2, COLOR_RED, COLOR_BLACK);
init_rockets -> color_explosion = 1;
init_rockets ->color_rise = 2;
init_rockets++;
init_rockets ->color_explosion = 2;
init_rockets ->color_rise = 1;
curs_set(0); //hide cursor
}//Initialize
int Rise(rocket *rising_rocket)
{
int row,col,i;
getmaxyx(stdscr,row,col); /* get the number of rows and columns */
attron(COLOR_PAIR(rising_rocket -> color_rise));
for(i=row; i> EXPLOSION_LEVEL;i--)
{
mvprintw(i, col/2,"%c", '|');
refresh();
timeout(100); //hack to get a delay. We wait 100ms for user input
getch(); //then move on as the user does nothing
}
attroff(COLOR_PAIR(rising_rocket ->color_rise));
return i;
}//Rise
void Explode(rocket *exploding_rocket,)
{
int col,row, i;
attron(COLOR_PAIR(exploding_rocket->color_explosion));
getmaxyx(stdscr,row,col);
mvprintw(level, col/2,"%c", 'X');
refresh();
for(i=0; i< 3;i++)
{
mvprintw(level - i, col/2+i,"%c", 'X');
mvprintw(level + i, col/2-i,"%c", 'X');
mvprintw(level + i, col/2-i,"%c", 'X');
mvprintw(level - i, col/2+i,"%c", 'X');
flash();
refresh();
timeout(100); //hack to get a delay. We wait 100ms for user input
getch(); //then move on as the user does nothing
}
attroff(COLOR_PAIR(exploding_rocket->color_explosion));
}//Explode
the header:
Code:
#ifndef ROCKET
# define ROCKET
#define EXPLOSION_LEVEL 4
class CRocket
{
private:
int mColorRise;
int mColorExplosion;
public:
void Rise(int TopDistance);
void Explode(int ExplosionLevel);
CRocket();
~CRocket();
};
#endif