void sync_send_test (int connection_key)
{
        x_endpoint_handle_t endpoint = x_get_endpoint(connection_key);
        int send_result, i;        
        char buf[512];
        for (i = 0; i < sizeof(buf); i++) {
          buf[i] = i & 0xFF;
        }
        x_sleep(6);
        x_set_task_status ("First send on %x",endpoint);
        send_result = x_sync_send(endpoint, buf, sizeof(buf));
        x_set_task_status ("First send result %d", send_result);
        x_sleep(3);
        x_set_task_status ("Second send");
        send_result = x_sync_send(endpoint, buf, sizeof(buf));
        x_set_task_status ("Second send result %d", send_result);
}
void sync_receive_test (int connection_key)
{
        x_endpoint_handle_t endpoint = x_get_endpoint(connection_key);
        int receive_result, i, failpos;        
        char buf[512];
        
        x_sleep(3);
        x_set_task_status ("First receive on %x",endpoint);
        for (i = 0; i < sizeof(buf); i++) {
          buf[i] = 0;          
        }
        receive_result = x_sync_receive(endpoint, buf, sizeof(buf));
        failpos = -1;
        for (i = 0; i < sizeof(buf); i++) {
          if (buf[i] != (i & 0xFF)) {
            failpos = i;
          } 
          buf[i] = 0;          
        }
        if (failpos >= 0) {
          x_set_task_status ("First transfer failed: mismatch at position %d",failpos);
          x_sleep(10);
        }                
        x_set_task_status ("First receive result %d", receive_result);
        x_sleep(6);
        x_set_task_status ("Second receive");
        failpos = -1;
        receive_result = x_sync_receive(endpoint, buf, sizeof(buf));
        for (i = 0; i < sizeof(buf); i++) {
          if (buf[i] != (i & 0xFF)) {
            failpos = i;
          } 
          buf[i] = 0;          
        }
        if (failpos >= 0) {
          x_set_task_status ("Second transfer failed: mismatch at position %d",failpos);
          x_sleep(10);
        }                
        x_set_task_status ("Second receive result %d", receive_result);
}
void sync_test (int connection_key)
{
        x_endpoint_handle_t endpoint = x_get_endpoint(connection_key);
        if (connection_key == X_TO_LEFT) {
          x_sleep(6);
          x_set_task_status ("First sync to left %x",endpoint);
          x_sync(endpoint);
          x_set_task_status ("First sync done");
          x_sleep(3);
          x_set_task_status ("Second sync to left");
          x_sync(endpoint);
          x_set_task_status ("Second sync done");
        }
        else if (connection_key == X_FROM_RIGHT) {
          x_sleep(3);
          x_set_task_status ("First sync from right %x",endpoint);
          x_sync(endpoint);
          x_set_task_status ("First sync done");
          x_sleep(6);
          x_set_task_status ("Second from right");
          x_sync(endpoint);
          x_set_task_status ("Second sync done");
        }
}
Example #4
0
int main(int argc, char *argv[])
{
	XRef<XSocket> pSocket = new XSocket;
	
	try
    {
		XSDK::XString host = "127.0.0.1";
		pSocket->Connect(host, 9080);
		
		oapi::DeviceList list;
		OAPIClient pClient(pSocket);
		
		pClient.DeviceListRequest(list);
    }
	catch( XSDK::XException& ex )
	{
		
	}
	
	x_sleep(10000);
}
int task_main(int argc, const char *argv[]) 
{
        e_coreid_t coreid;
        unsigned row, col;
        int wg_rows, wg_cols, my_row, my_col;
        coreid = e_get_coreid();
        e_coords_from_coreid (coreid, &row, &col);
        x_get_task_environment (&wg_rows, &wg_cols, &my_row, &my_col);
        x_set_task_status ("Hello from core 0x%03x (%d,%d) taskpos %d %d in %d %d", 
                           coreid, col, row, my_col, my_row, wg_cols, wg_rows);
        if (row == 1 && col == 1) {
          sync_send_test(X_TO_LEFT);
        }
        else if (row == 1 && col == 0) {
          sync_receive_test(X_FROM_RIGHT);      
        }
        else {
          x_sleep(30);
          x_set_task_status ("Goodbye from core 0x%03x (%d,%d) pid %d", 
                             coreid, col, row, my_col, my_row);
        }
        return X_SUCCESSFUL_TASK;
}
Example #6
0
void fightSmiley(chara *hero, int ind, int enN){

    char ene[1020] = "";
    char ename[20];
    chara bad;
    bad.xp = 0;

    enemy(ene, &bad, ename, enN);

    int hp = hero->hp;
    int enehp = (bad.hp)*ind;
    char f1 = 'X';
    char f2 = ' ';
    char f3 = ' ';
    char f4 = ' ';
    char texto[30];

    sprintf(texto, "an evil %s has appeared ", ename);

    int choice = 3;

    while(enehp > 0 && hp > 0){
        clear();
        refresh();
        printw("%s", ene);
        printw("|--------------------------------------------------------------------------|\n");
        printw("||                                       +---------------------------------|\n");
        printw("|| %s          | %c attack                      |-|\n", texto, f1);
        printw("|| hp = %2d                               | %c magic                       |-|\n", hp, f2);
        printw("|| enemy hp = %2d                         | %c healing magic               |-|\n", enehp, f3);
        printw("||                                       | %c guard                       |-|\n", f4);
        printw("||                                       +---------------------------------|\n");
        printw("|--------------------------------------------------------------------------|\n");
        printw("+--------------------------------------------------------------------------+\n");
        switch(arrkeys()){
            case 'x':
                endwin();
                exit(0);
                break;
            case 'u':
                choice = (choice+1)%4;
                break;
            case 'd':
                choice -= 1;
                if(choice < 0){
                    choice = 3;
                }
                break;
            case 'q':
                switch(choice){
                    case 3:
                        sprintf(texto, "you've attacked evil %s ", ename);
                        enehp-=(hero->st-(bad.def));
                        hp -= -(hero->def-(bad.st+rand()%5));
                        break;
                    case 2:
                        strcpy(texto, "you've used magic!          ");
                        enehp -= (hero->sp-(bad.sp+rand()%15));
                        hp -= -(hero->def-(bad.st+rand()%5));
                        break;
                    case 1:
                        sprintf(texto, "you used healing magic      ");
                        hp = hp + hero->sp/2;
                        hp -= -(hero->def-(bad.st+rand()%5));
                        break;
                    case 0:
                        strcpy(texto, "you  guard to reduce damage ");
                        hp -= -((hero->def*2)-(bad.st+rand()%5));
                        break;
                }
                break;
        }
        switch(choice){
            case 3:
                f1 = 'X';
                f2 = ' ';
                f3 = ' ';
                f4 = ' ';
                break;
            case 2:
                f1 = ' ';
                f2 = 'X';
                f3 = ' ';
                f4 = ' ';
                break;
            case 1:
                f1 =' ';
                f2 =' ';
                f3 ='X';
                f4 =' ';
                break;
            case 0:
                f1 =' ';
                f2 =' ';
                f3 =' ';
                f4 ='X';
                break;
        }

        if(hp > (hero->hp)){
            hp = hero->hp;
        }

    }

    if(hp <= 0){

        clear();
        refresh();

        printw("                                            \n");
        printw("  /$$$$$$   /$$$$$$  /$$      /$$ /$$$$$$$$ \n");
        printw(" /$$__  $$ /$$__  $$| $$$    /$$$| $$_____/ \n");
        printw("| $$  \\__/| $$  \\ $$| $$$$  /$$$$| $$       \n");
        printw("| $$ /$$$$| $$$$$$$$| $$ $$/$$ $$| $$$$$    \n");
        printw("| $$|_  $$| $$__  $$| $$  $$$| $$| $$__/    \n");
        printw("| $$  \\ $$| $$  | $$| $$\\  $ | $$| $$       \n");
        printw("|  $$$$$$/| $$  | $$| $$ \\/  | $$| $$$$$$$$ \n");
        printw(" \\______/ |__/  |__/|__/     |__/|________/ \n");
        printw("                                            \n");
        printw("                                            \n");

        x_sleep(100);
        refresh();

        printw("                                            \n");
        printw("  /$$$$$$  /$$    /$$ /$$$$$$$$ /$$$$$$$    \n");
        printw(" /$$__  $$| $$   | $$| $$_____/| $$__  $$   \n");
        printw("| $$  \\ $$| $$   | $$| $$      | $$  \\ $$   \n");
        printw("| $$  | $$|  $$ / $$/| $$$$$   | $$$$$$$/   \n");
        printw("| $$  | $$ \\  $$ $$/ | $$__/   | $$__  $$   \n");
        printw("| $$  | $$  \\  $$$/  | $$      | $$  \\ $$   \n");
        printw("|  $$$$$$/   \\  $/   | $$$$$$$$| $$  | $$   \n");
        printw(" \\______/     \\_/    |________/|__/  |__/   \n");
        printw("                                            \n");
        printw("                                            \n");
        printw("                                            \n");

        x_sleep(100);
        refresh();
        x_pause();
        endwin();
        exit(0);

    }

    else{

        hero->xp += (rand()%900)/hp;

        if (hero->xp >= 100){
            hero->hp += rand()%10;
            hero->st += rand()%3;
            hero->sp += rand()%4;
            hero->def += rand()%5;
            hero->xp = 0;
        }

        clear();
        refresh();

        printw("+--------------------------------------------------------------------------+\n");
        printw("|                                                                          |\n");
        printw("|                                                                          |\n");
        printw("|                                                                          |\n");
        printw("|                                                                          |\n");
        printw("|                                                                          |\n");
        printw("|                                                                          |\n");
        printw("|                                                                          |\n");
        printw("|                                                                          |\n");
        printw("|                                                                          |\n");
        printw("|                                                                          |\n");
        printw("|                                                                          |\n");
        printw("+--------------------------------------------------------------------------+\n");
        printw("                                                                            \n");
        printw("|--------------------------------------------------------------------------|\n");
        printw("||                                       +---------------------------------|\n");
        printw("|| you've defeated the evil %s       |                               |-|\n", ename);
        printw("|| CONGRATULATIONS!                      |                               |-|\n");
        printw("||                                       |                               |-|\n");
        printw("||                                       +---------------------------------|\n");
        printw("|--------------------------------------------------------------------------|\n");
        printw("+--------------------------------------------------------------------------+\n");

        refresh();
        x_pause();

        clear();
        refresh();

        printw("                                                                \n");
        printw("__/\\\\\\________/\\\\\\_______/\\\\\\\\\\_______/\\\\\\________/\\\\\\_         \n");
        printw(" _\\///\\\\\\____/\\\\\\/______/\\\\\\///\\\\\\____\\/\\\\\\_______\\/\\\\\\_        \n");
        printw("  ___\\///\\\\\\/\\\\\\/______/\\\\\\/__\\///\\\\\\__\\/\\\\\\_______\\/\\\\\\_       \n");
        printw("   _____\\///\\\\\\/_______/\\\\\\______\\//\\\\\\_\\/\\\\\\_______\\/\\\\\\_      \n");
        printw("    _______\\/\\\\\\_______\\/\\\\\\_______\\/\\\\\\_\\/\\\\\\_______\\/\\\\\\_     \n");
        printw("     _______\\/\\\\\\_______\\//\\\\\\______/\\\\\\__\\/\\\\\\_______\\/\\\\\\_    \n");
        printw("      _______\\/\\\\\\________\\///\\\\\\__/\\\\\\____\\//\\\\\\______/\\\\\\__   \n");
        printw("       _______\\/\\\\\\__________\\///\\\\\\\\\\/______\\///\\\\\\\\\\\\\\\\\\/___  \n");
        printw("        _______\\///_____________\\/////__________\\/////////_____ \n");

        x_sleep(100);
        refresh();

        printw("__/\\\\\\______________/\\\\\\__/\\\\\\\\\\\\\\\\\\\\\\__/\\\\\\\\\\_____/\\\\\\_        \n");
        printw(" _\\/\\\\\\_____________\\/\\\\\\_\\/////\\\\\\///__\\/\\\\\\\\\\\\___\\/\\\\\\_       \n");
        printw("  _\\/\\\\\\_____________\\/\\\\\\_____\\/\\\\\\_____\\/\\\\\\/\\\\\\__\\/\\\\\\_      \n");
        printw("   _\\//\\\\\\____/\\\\\\____/\\\\\\______\\/\\\\\\_____\\/\\\\\\//\\\\\\_\\/\\\\\\_     \n");
        printw("    __\\//\\\\\\__/\\\\\\\\\\__/\\\\\\_______\\/\\\\\\_____\\/\\\\\\\\//\\\\\\\\/\\\\\\_    \n");
        printw("     ___\\//\\\\\\/\\\\\\/\\\\\\/\\\\\\________\\/\\\\\\_____\\/\\\\\\_\\//\\\\\\/\\\\\\_   \n");
        printw("      ____\\//\\\\\\\\\\\\//\\\\\\\\\\_________\\/\\\\\\_____\\/\\\\\\__\\//\\\\\\\\\\\\_  \n");
        printw("       _____\\//\\\\\\__\\//\\\\\\_______/\\\\\\\\\\\\\\\\\\\\\\_\\/\\\\\\___\\//\\\\\\\\\\_ \n");
        printw("        ______\\///____\\///_______\\///////////__\\///_____\\/////__\n");
        printw("                                                                \n");
        printw("                                                                \n");

        x_sleep(100);
        refresh();
        x_pause();

    }

}
Example #7
0
int main (){

    srand(time(0));

    initscr();
    keypad(stdscr, TRUE);
    start_color();
    init_pair(1, COLOR_BLACK, COLOR_WHITE);
    init_pair(2, COLOR_YELLOW, COLOR_RED);
    init_pair(3, COLOR_CYAN, COLOR_MAGENTA);
    int ch;
    int ind = 0;
    int lvs = 2;
    int enN = 3;

    loadLv(&lvs, &enN);

    int map_size = MAX*MAX;

    pos you_are_here, wall_positions[map_size];
    pos goal;
    chara hero;

    hero.hp = 30;
    hero.st = 10;
    hero.sp = 20;
    hero.def = 7;
    hero.xp = 0;

    for(ind=0;ind<map_size;ind++){
        wall_positions[ind].x=-1;
        wall_positions[ind].y=-1;
    }

    ind =1;

    loadMap(&you_are_here, wall_positions, &goal, ind);

    ch=0;

    mapi(you_are_here, wall_positions, goal, map_size, hero);

    while ((ch = getch()) != 27){  /* 27 = Esc key */

        switch (ch){

            case 259:
                if(!checkli(you_are_here.x, you_are_here.y-1, wall_positions, map_size)){
                    if(you_are_here.y > 0){
                        you_are_here.y -= 1;
                    }
                    else if(!checkli(you_are_here.x, MAX-1, wall_positions, map_size)){
                        you_are_here.y = MAX-1;
                    }
                }
                break;

            case 261:
                if(!checkli(((you_are_here.x+1)%MAX), you_are_here.y, wall_positions, map_size)){
                    you_are_here.x = (you_are_here.x+1)%MAX;
                }
                break;
            case 260:
                if(!checkli(you_are_here.x-1, you_are_here.y, wall_positions, map_size)){
                    if(you_are_here.x > 0){
                        you_are_here.x -= 1;
                    }
                    else if(!checkli(MAX-1, you_are_here.y, wall_positions, map_size)){
                        you_are_here.x = MAX-1;
                    }
                }
                break;
            case 258:
                if(!checkli(you_are_here.x, (you_are_here.y+1)%MAX, wall_positions, map_size)){
                    you_are_here.y = (you_are_here.y+1)%MAX;
                }
                break;
        }

        clear();
        refresh();

        if(rand()%15==1){
            fightSmiley(&hero, ind, enN);
        }

        clear();
        refresh();

        mapi(you_are_here, wall_positions, goal, map_size, hero);

        if (you_are_here.x==goal.x&& you_are_here.y==goal.y){

            char lv[16];
            int pp=0;

            if (ind<lvs){
                ind++;
                loadMap(&you_are_here, wall_positions, &goal, ind);
                clear();
                refresh();


                sprintf(lv, "L E V E L   %d", ind);

                int pp=0;
                attron(COLOR_PAIR(1));
                for(pp=0;lv[pp]!='\0';pp++){
                    printw("%c", lv[pp]);
                    refresh();
                    x_sleep(100);
                }
                attroff(COLOR_PAIR(1));

            }
            else{
                clear();
                refresh();
                printw("\n\n\n\n\n\n\n\n\n");

                char end[107] = "congratulations you've escaped the castle of death \n and survived the evil smiley horde\n\n\n T H E   E N D";

                attron(COLOR_PAIR(1));
                for(pp=0;end[pp] != '\0';pp++){
                    printw("%c", end[pp]);
                    x_sleep(100);
                    refresh();
                }
                attroff(COLOR_PAIR(1));

                printw("\n\n");
                x_sleep(100);
                refresh();
                x_pause();

                endwin();
                exit(0);

            }
        }
        refresh();
    }

    printw("ESC %d\n", ch);
    endwin();
    return (0);
}