Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as C++ by snake ( 17 years ago )
#include <iostream>
//#include <stdio.h>
/* biblioteka ncurses automatycznie dolacza stdio.h i kilka innych */
#include <ncurses.h>
using namespace std;

void SleepMs(int ms) {
usleep(ms*1000); /*usleep jest funkcja do ktorej w odroznieniu do sleep
wprowadza sie mikrosekundy*/
return;
}
struct waz_charakterystyka {

int dlugosc;
int glowax;
int gloway;
int glowakierunek;
int *cialox;
int *cialoy; 
} waz;

void start()
{
initscr();
int kolumny = 0;
int rzedy = 0;
getmaxyx(stdscr, rzedy, kolumny);
 WINDOW *oknogry=newwin(rzedy-1,kolumny, 0, 0);
box(oknogry, 0, 0);
wrefresh(oknogry);
//def_prog_mode();
delwin(oknogry);
endwin();
waz.cialox = new int[waz.dlugosc-1 ];
waz.cialoy = new int[waz.dlugosc-1 ];
waz.dlugosc = 3;
waz.glowax = 4;
waz.gloway = 4;
waz.cialoy[0]=waz.cialoy[1]=waz.cialoy[2]=waz.gloway;
for (int i = 0; i < waz.dlugosc; ++i){
waz.cialox[i] = 4 -i;
}
waz.glowakierunek = KEY_RIGHT;
}


void ruch ()

{
initscr();
noecho();
waz.glowakierunek = getch(); 
if (waz.glowakierunek == KEY_LEFT)
 {
waz.glowax --;
}
if (waz.glowakierunek == KEY_RIGHT)
{
waz.glowax ++;
}
if (waz.glowakierunek == KEY_UP)
{
waz.gloway --;
}
if (waz.glowakierunek == KEY_DOWN)
{
waz.gloway ++;
}
endwin();
 }
void cialo()
{
int p1, p2;
p1 = waz.glowax;
for (int i = 0; i < waz.dlugosc; ++i) {
p2 = waz.cialox[i];
waz.cialox[i]= p1;
p1 = p2;
}

p1 = waz.gloway;
for (int i = 0; i < waz.dlugosc; ++i) {
p2 = waz.cialoy[i];
waz.cialoy[i]= p1;
p1 = p2;
}
initscr();
//reset_prog_mode();
//refresh();
mvprintw(waz.cialoy[0], waz.cialox[0], "@");
for (int i=1; i<waz.dlugosc; ++i) {
mvprintw(waz.cialoy[i],waz.cialox[i], "o" );
}
//wrefresh(stdscr);        
//wrefresh(oknogry);
refresh();
endwin();
}

void delcialo()
{
//reset_prog_mode();
//refresh();
initscr();
mvdelch(waz.cialoy[0], waz.cialox[0]);
for (int i=1; i<waz.dlugosc; ++i) {
mvdelch(waz.cialoy[i],waz.cialox[i]);
}
//wrefresh(stdscr);        
//wrefresh(oknogry);
refresh();
endwin();
}
void silnik ()
{
 while(1)
    {
         ruch ();
         cialo();
         SleepMs (50);
         delcialo();
//printf(" \033[2J");
}
}


int main()
{
start();
//cialo();
silnik();
return 0;
}

 

Revise this Paste

Your Name: Code Language: