Пример #1
0
void print_tank_status(int y, int x, TankDesign *tank_type, int *position, int A){

	switch (A){
	case 0: attron(COLOR_PAIR(1) | A_BOLD); mvaddch(y + 3, x, 'N'); attroff(COLOR_PAIR(1) | A_BOLD); break;
	case 1: attron(COLOR_PAIR(1) | A_BOLD); mvaddch(y + 3, x, 'S'); attroff(COLOR_PAIR(1) | A_BOLD); break;
	}

	attron(COLOR_PAIR(tank_type[position[0]].paint));
	mvaddch(y - 1, x - 1, tank_type[position[0]].ch);

	attron(COLOR_PAIR(tank_type[position[1]].paint));
	mvaddch(y - 1, x, tank_type[position[1]].ch);

	attron(COLOR_PAIR(tank_type[position[2]].paint));
	mvaddch(y - 1, x + 1, tank_type[position[2]].ch);

	attron(COLOR_PAIR(tank_type[position[3]].paint));
	mvaddch(y, x - 1, tank_type[position[3]].ch);

	attron(COLOR_PAIR(tank_type[position[4]].paint));
	mvaddch(y, x, tank_type[position[4]].ch);

	attron(COLOR_PAIR(tank_type[position[5]].paint));
	mvaddch(y, x + 1, tank_type[position[5]].ch);

	attron(COLOR_PAIR(tank_type[position[6]].paint));
	mvaddch(y + 1, x - 1, tank_type[position[6]].ch);

	attron(COLOR_PAIR(tank_type[position[7]].paint));
	mvaddch(y + 1, x, tank_type[position[7]].ch);

	attron(COLOR_PAIR(tank_type[position[8]].paint));
	mvaddch(y + 1, x + 1, tank_type[position[8]].ch);

	refresh();
}
Пример #2
0
int main(int argc, char **argv)
{
	struct termios term, term_saved;
	file_t *file;
	
	if(argc > 2)
	{
		printf("ERROR: Invalid arguments!\n");
		return 1;
	}
	
	newfile();
	
	file = files[0];
	
	if(argc == 2)
	{
		/* filename given */
		strcpy(file->filename, argv[1]);
		loadfile(file, argv[1]);
	}
	else
		file->filename[0] = 0;
	
	file->saved = 1;
	
	current = 0;
	
	/* make sure we got something */
	if(!file->line_count)
		insertline(file, 0);
	
	file->cursor_x = 0;
	file->cursor_y = 0;
	
	tcgetattr(0, &term_saved);
	
	/* initialize curses */
	screen = initscr();
	cbreak();
	nonl();
	noecho();
	
	keypad(screen, TRUE);
	
	/* modify terminal settings */
	tcgetattr(0, &term);
	term.c_lflag &= ~(IEXTEN | ISIG);
	term.c_iflag &= ~IXON;
	term.c_oflag &= ~OPOST;	
	tcsetattr(0, TCSANOW, &term);
	
	/* setup colors */
	start_color();
	init_pair(1, COLOR_YELLOW, COLOR_BLACK);
	init_pair(2, COLOR_WHITE, COLOR_BLACK);
	init_pair(3, COLOR_WHITE, COLOR_BLUE);
	init_pair(4, COLOR_WHITE, COLOR_BLUE);
	init_pair(5, COLOR_GREEN, COLOR_BLACK);
	init_pair(6, COLOR_BLUE, COLOR_BLACK);
	init_pair(7, COLOR_BLACK, COLOR_BLACK);
	attron(COLOR_PAIR(2));
	
	getmaxyx(screen, h, w);
	
	drawmenu();	
	drawscreen();
	drawpos();
	
	setcursor();
	refresh();
	
	/* main loop */
	while(!editor_loop());
	
	endwin();
	
	/* revert terminal settings */
	tcsetattr(0, TCSANOW, &term_saved);
	
	return 0;
}
Пример #3
0
int main(){

	FILE *fp;
	Cidade *listaCidades = criaListaCidade();
	Gerador *listaGeradores = criaListaGerador();
	Interconexao *listaInterconexoes = criaListaInterconexao();
	Adaptador *listaAdaptadores = criaListaAdaptador();
	Relatorio relatorio;
	int i, tempoSimulacao = 2;
	char arquivo[100];

	char str[100]; //!< String auxiliar para obter registros

	printf("Rede de distribuicao\n");

	do{
	//! AE: o nome do arquivo nao eh valido

		printf("Digite o caminho para o arquivo (a partir de ./app/src):\n");
		scanf("%s",arquivo);
		getchar();

		fp = fopen(arquivo,"r");//!< Abre arquivo de entrada

	} while(fp == NULL);
	//! AE: o nome do arquivo eh valido

	printf("Digite o tempo desejado de simulacao\n");
	scanf("%d",&tempoSimulacao);

	do{
	//! AE: o arquivo nao chegou ao fim

		if(fgets(str,100,fp)!=NULL){
		//! AE: a linha (registro) obtido do arquivo possui conteudo

			switch (str[0]) {
				case 'C':
					//! AE: O registro obtido eh do tipo Cidade
					listaCidades = insereCidade(str,listaCidades);
					break;

				case 'G':
				//! AE: O registro obtido eh do tipo Gerador
					listaGeradores = insereGerador(str,listaGeradores);
					break;

				case 'I':
				//! AE: O registro obtido eh do tipo Interconexao
					listaInterconexoes = insereInterconexao(str,listaInterconexoes);
					break;

				case 'A':
				//! AE: O registro obtido eh do tipo Adaptador
					listaAdaptadores = insereAdaptador(str,listaAdaptadores);
					break;

				default:
					break;
			}
		}
		//! AS: a linha (registro) obtido do arquivo nao possui conteudo, ou seja, o arquivo chegou ao fim

	} while(!feof(fp));
	//! AS: o arquivo chegou ao fim

	fclose(fp);

	//! Comentarios de argumentacao
		/**
		*	Conectando e verificando as listas
		**/
	conecta(listaCidades,listaGeradores,listaInterconexoes,listaAdaptadores);
	verifica(listaCidades,listaGeradores,listaInterconexoes,listaAdaptadores);
	inicializa(listaGeradores,listaInterconexoes,listaAdaptadores,listaCidades);

	//! Comentarios de argumentacao
		/**
		*	Iniciando a interface
		**/
	mvprintw(0,0,"Pressione enter para comecar!");
	getch();
	mvprintw(0,0,"                             ");

	srand(1);

	for(i=0;i<tempoSimulacao;i++){
	// AE: tempo de simulacao nao chegou ao fim

		start_color();
	  init_pair(1, COLOR_GREEN, COLOR_BLACK);
		attron(COLOR_PAIR(1));
		mvprintw(1,100,"%d segundos", i);

		zerarCidades(listaCidades);
		zerarAdaptadores(listaAdaptadores);
		zerarInterconexoes(listaInterconexoes);

		gerenciaFalhas(listaInterconexoes);

		mandarRecursoProduzido(listaGeradores);
		defineDistribuicao(listaAdaptadores);
		mandarRecursoAdaptado(listaAdaptadores);
		gerenciaRecursoRecebido(listaCidades);

		atualizaCidades(listaCidades);
		atualizaInterconexoes(listaInterconexoes);
		atualizaGeradores(listaGeradores);
		atualizaAdaptadores(listaAdaptadores);

		getch();
	}
	// AS: tempo de simulacao chegou ao fim

	mvprintw(0,0,"                             ");
	mvprintw(1,0,"                             ");
	mvprintw(0,0,"Pressione enter para finalizar!");
	getch();
	endwin();
	//! Comentarios de argumentacao
		/**
		*	Finalizando a interface
		**/

	//! Comentarios de argumentacao
		/**
		*	Imprimindo as listas obtidas a partir do arquivo de entrada
		**/
	printf("\nLista de cidades:\n");imprimeListaCidade(listaCidades);
	printf("\nLista de geradores:\n");imprimeListaGerador(listaGeradores);
	printf("\nLista de interconexões:\n");imprimeListaInterconexao(listaInterconexoes);
	printf("\nLista de adaptadores:\n");imprimeListaAdaptador(listaAdaptadores);

	//! Comentarios de argumentacao
		/**
		*	Preenchimento do relatorio
		**/
	fp = fopen("../../RELATORIO.txt","w");//!< Abre arquivo de entrada
	fprintf(fp,"Relatório:\n\n");
	printf("Relatório:\n\n");

	relatorio.tempoTotalSimulacao = tempoSimulacao;
	fprintf(fp,"Tempo total da simulação: %d segundos\n", relatorio.tempoTotalSimulacao);
	printf("Tempo total da simulação: %d segundos\n", relatorio.tempoTotalSimulacao);

	relatorio.custoTotalSimulacao = custoGeradores(listaGeradores)*tempoSimulacao + custoGastoComConserto(listaInterconexoes);
	fprintf(fp,"Custo total na simulação: %d\n", relatorio.custoTotalSimulacao);
	printf("Custo total na simulação: %d\n", relatorio.custoTotalSimulacao);

	relatorio.totalGeradores = numeroGeradores(listaGeradores);
	fprintf(fp,"Total de geradores: %d\n", relatorio.totalGeradores);
	printf("Total de geradores: %d\n", relatorio.totalGeradores);

	relatorio.energiaTotalGerada = recursoProduzidoTotal(listaGeradores) * tempoSimulacao;
	fprintf(fp,"Energia total gerada: %d\n", relatorio.energiaTotalGerada);
	printf("Energia total gerada: %d\n", relatorio.energiaTotalGerada);

	relatorio.totalCidades = numeroCidades(listaCidades);
	fprintf(fp,"Total de cidades: %d\n", relatorio.totalCidades);
	printf("Total de cidades: %d\n", relatorio.totalCidades);

	relatorio.energiaGastaCidades = recursoGastoTotal(listaCidades);
	fprintf(fp,"Energia total gasta pelas cidades: %d\n", relatorio.energiaGastaCidades);
	printf("Energia total gasta pelas cidades: %d\n", relatorio.energiaGastaCidades);

	relatorio.tamanhoTotalInterconexoes = tamanhoTotalConexao(listaInterconexoes);
	fprintf(fp,"Tamanho total das interconexões: %.2f\n", relatorio.tamanhoTotalInterconexoes);
	printf("Tamanho total das interconexões: %.2f\n", relatorio.tamanhoTotalInterconexoes);

	relatorio.numeroFalhaInterconexoes = numeroTotalFalhas(listaInterconexoes);
	fprintf(fp,"Número de falhas nas interconexões: %d\n", relatorio.numeroFalhaInterconexoes);
	printf("Número de falhas nas interconexões: %d\n", relatorio.numeroFalhaInterconexoes);

	relatorio.numeroCidadesNegativadas = numeroCidadesNegativadas(listaCidades);
	fprintf(fp,"Número de cidades que ficaram com menos recurso que o necessário: %d\n",relatorio.numeroCidadesNegativadas);
	printf("Número de cidades que ficaram com menos recurso que o necessário: %d\n",relatorio.numeroCidadesNegativadas);

	relatorio.tempoSemRecurso =	tempoSemRecursoNecessario(listaCidades);
	fprintf(fp,"Tempo que ficaram sem recurso: %d\n",relatorio.tempoSemRecurso);
	printf("Tempo que ficaram sem recurso: %d\n",relatorio.tempoSemRecurso);

	relatorio.numeroCidadesNoVermelho = numeroCidadesNoVermelho(listaCidades);
	fprintf(fp,"Número de cidades que ficaram com menos de 30%% dos recursos: %d\n",relatorio.numeroCidadesNoVermelho);
	printf("Número de cidades que ficaram com menos de 30%% dos recursos: %d\n",relatorio.numeroCidadesNoVermelho);

	relatorio.tempoCidadesNoVermelho = tempoCidadesNoVermelho(listaCidades);
	fprintf(fp,"Tempo que ficaram com menos de 30%% dos recurso: %d\n", relatorio.tempoCidadesNoVermelho);
	printf("Tempo que ficaram com menos de 30%% dos recurso: %d\n", relatorio.tempoCidadesNoVermelho);

	fclose(fp);

	printf("\n\nRelatório gerado!\n\n");

	//! Comentarios de argumentacao
		/**
		*	Desalocando as listas obtidas
		**/
	liberaListaCidade(listaCidades);
	liberaListaGerador(listaGeradores);
	liberaListaInterconexao(listaInterconexoes);
	liberaListaAdaptador(listaAdaptadores);

	getchar();
	return 0;
}
Пример #4
0
int
io_list(field_t *f)
{
 int c = 0, i = -1, y = -1, max_x = 0, max_y = 0, top = 0, bot = 0;
 int index = 0, offset = 0, size = 0, j = 0, first = 1, k = 0;
 int n = 0, rows = 0, find_index = 0, value_count = 0, increase = 0;
 char *s = NULL, *p = NULL, s_v[2] = {'\0', '\0'};
 size_t *on = NULL;

 s_v[0] = value_separator;
 if ( BOOLEAN_T != f->type ) {
     if ( NULL == f->list ) {
         return (0);
     } else if ( access(f->list, X_OK) < 0 ) {
         return (-1);
     }
 }
 if ( ((BOOLEAN_T == f->type ) || (f->list)) && (0 == f->constant) ) { 
     if ( (list(f) < 0) || (0 == S_count) ) {
         return (0);  /*  XXX  */
     } else {
         if ( NULL == (on = calloc(S_count, sizeof(size_t))) ) {
             return (0); /*  XXX  */
         }
         for (;;) {
             getmaxyx(stdscr, max_y, max_x);
             if ( (max_y < MIN_Y) || (max_x < MIN_X) ) {
                 return (0);
             } else {
                 clear(); mvprintw(1, 30, "%s", f->label); bot = max_y-5;
                 if ( 1 == f->max_values ) {
                     top = 5;
                     mvaddstr(3,2,
                               "Move cursor to desired item and press Enter.");
                 } else {
                     top = 7;
                     mvaddstr(top-4, 2,
                                  "Move cursor to desired item and press F7.");
                     mvaddstr(top-3, 6, "ONE OR MORE items can be selected.");
                     mvaddstr(top-2, 2,
                                   "Press Enter AFTER making all selections.");
                 }
                 if ( S_count > max_y-12 ) {
                     top++; bot--;
                 }
             }
             LIST_LEGEND;
             if ( 1 == f->max_values ) {
                 rows = max_y-12;
             } else {
                 rows = max_y-14;
             }
             for (;;) {
                 for ( i = offset, y = top; i < S_count && y < bot; i++, y++) {
                     mvaddch(y, 2, on[i] ? '>' : ' ');
                     mvaddnstr(y, 4, S[i], max_x-6); clrtoeol();
                 }
                 attron(A_STANDOUT);
                 mvaddnstr(top+(index-offset), 4, S[index], max_x-6);
                 attroff(A_STANDOUT);
                 if ( S_count > max_y-12 ) {
                     if ( offset ) {
                         mvprintw(top-1, 2, "[MORE...%d]", offset); clrtoeol();
                     } else {
                         mvaddstr(top-1, 2, "[TOP]"); clrtoeol();
                     }
                     if ( S_count > offset+(bot-top) ) {
                         mvprintw(max_y-6, 2, "[MORE...%d]",
                                                   S_count-(offset+(bot-top)));
                         clrtoeol();
                     } else {
                         mvaddstr(max_y-6, 2, "[BOTTOM]"); clrtoeol();
                     }
                 }
                 (void)border('|', '|', '-', '-', '+', '+', '+', '+');
                 c = get_key(top+(index-offset), 3);
                 if ( KEY_DOWN == c ) {
                     if ( index < S_count-1 ) {
                         index++;
                         if ( (index-offset) > (bot-top-1) ) {
                             offset++;
                         }
                     }
                 } else if ( KEY_UP == c ) {
                     if ( index ) {
                         if ( index == offset ) {
                             offset--;
                         }
                         index--;
                     }
                 } else if ( KEY_PPAGE == c ) {
                     if ( offset > 0 ) {
                         if ( offset > rows ) {
                             offset -= rows; index -= rows;
                         } else {
                             index -= offset; offset = 0;
                         }
                     } else {
                         index = 0;
                     }
                 } else if ( KEY_NPAGE == c ) {
                     if ( offset < S_count-rows ) {
                         if ( offset < S_count-2*rows ) {
                             offset += rows; index += rows;
                         } else {
                             index  += S_count-offset-rows;
                             offset += S_count-offset-rows;
                         }
                     } else {
                         index = S_count-1;
                     } 
                 } else if ( (KEY_F(1) == c) || (KEY_F(10) == c)  ) {
                     return (c);
                 } else if ( KEY_F(3) == c ) {
                     return (KEY_F(2));
                 } else if ( (KEY_F(7) == c) || (' ' == c) ) {
                     if ( f->max_values > 1 ) {
                         if ( on[index] ) {
                             size -= on[index]; on[index] = 0; value_count--;
                         } else if ( value_count < f->max_values ) {
                             increase = strlen(S[index]);
                             if ( value_count ) {
                                 increase+=1;
                             }
                             if ( size+increase < f->width ) {
                                 on[index] = increase; value_count++;
                                 size+=increase;
                             }
                         } /*  XXX else ERROR  */
                     }
                 } else if ( KEY_F(8) == c ) {
                     if ( (KEY_F(1) == (k = image())) || (KEY_F(10) == k)  ) {
                         return (k);
                     } else if ( KEY_F(2) == k ) {
                         refresh();
                     }
                 } else if ( '/' == c ) {
                     find_index = find_text(index);
                     if ( FIND_CANCEL == find_index ) {
                         find_index = 0;  /*  No-op.  */
                     } else if ( FIND_EXIT == find_index ) {
                         free(srch_txt); srch_txt = NULL;
                         return ( KEY_F(10) );
                     } else if ( find_index > offset+rows-1 ) {
                         /* Forward find off page. */
                         index = find_index; offset = index-rows+1;
                     } else if ( find_index < offset ) {
                         /* Backward find off page. */
                         index = offset = find_index;
                     } else {
                         index = find_index;
                     }
                     LIST_LEGEND;
                 } else if ( 'n' == c ) {
                     find_index = find_next(index);
                     if ( find_index > offset+rows-1 ) {
                         index = find_index; offset = index-rows+1;
                     } else if ( find_index < offset ) {
                         index = offset = find_index;
                     } else {
                         index = find_index;
                     }
                 } else if ( (KEY_ENTER == c) || ('\r' == c) || ('\n' == c) ) {
                     if ( 1 == f->max_values ) {
                         for ( k = 0; k < S_count; k++ ) {
                             on[k] = 0;
                         }
                         on[index] = 1;
                     }
                     f->buf[0] = '\0';
                     for ( j = 0; j < S_count; j++ ) {
                         if ( on[j] ) {
                             if ( !first ) {
                                 strcat(f->buf, s_v);
                             }
                             strcat(f->buf, S[j]); first = 0;
                         }
                     }
                     for ( k = 0; k < S_count; k++ ) {
                         free(S[k]); S[k] = NULL;
                     }
                     free(S); S = NULL; free(on); S_count = 0; return (0);
                 }
             }
         }
     }
 }
 return (0);
}
Пример #5
0
int dungeon_print()
{
	// build sight map
	if (sight)
	{
		// clear old sight map
		int r, c;
		for(r=0;r<DUNGEON_H;r++)
		{
			for(c=0;c<DUNGEON_W;c++)
			{
				sightmap[r][c] = 0;
			}
		}
		int i;
		for(i = 0; i<nummon; i++)
		{
			int npcx, npcy, pcx, pcy;
			character_getLocation(npcs[i], &npcx, &npcy);
			character_getLocation( pc    , & pcx, & pcy);
			dungeon_lineOfSight(npcx, npcy, pcx, pcy);
		}
	}

	int r, c;
	for(r=0;r<DUNGEON_H;r++)
	{
		for(c=0;c<DUNGEON_W;c++)
		{
			int visible = dungeon_isVisible(c, r);

			if ((nofog || visible) && cmap[r][c])
			{
				int speed = character_getSpeed(cmap[r][c]);

				int color = 0;
				if (character_isPC(cmap[r][c])) // if it is PC
				{
					init_pair(color = 1, COLOR_RED, COLOR_YELLOW);
				}
				else if (100/speed >= 15)
					init_pair(color = 2, COLOR_WHITE, COLOR_BLACK);
				else if (100/speed >= 10)
					init_pair(color = 3, COLOR_GREEN, COLOR_BLACK);
				else if (100/speed >= 7)
					init_pair(color = 4, COLOR_CYAN, COLOR_BLACK);
				else if (100/speed >= 5)
					init_pair(color = 5, COLOR_MAGENTA, COLOR_BLACK);
				
				attron(COLOR_PAIR(color));
				
				// print character on the dungeon
				print(r, c, character_getSymbol(cmap[r][c]));
				attroff(COLOR_PAIR(color));
			}
			else if (sight && sightmap[r][c]) // only for debug
			{
				int color;
				if (sightmap[r][c] > 0)
				{	
					init_pair(color = 3, COLOR_GREEN, COLOR_BLACK);
					attron(COLOR_PAIR(color));
					print(r, c, 'o');
				}
				else
				{
					init_pair(color = 30, COLOR_RED, COLOR_BLACK);
					attron(COLOR_PAIR(color));
					print(r, c, 'x');
				}
				attroff(COLOR_PAIR(color));
			}
			else
			{
				// print dungeon cell on the dungeon
				char *seenDungeon = pc_getSeenDungeon();
				
				char ch = seenDungeon[r*DUNGEON_W + c];
				
				int color = 10;
				if (visible)
				{
					init_pair(color, COLOR_YELLOW, COLOR_BLACK);
					attron(COLOR_PAIR(color));
				}
				print(r, c, ch);
				attroff(COLOR_PAIR(color));

				if (nofog)
					print(r, c, dungeon[r][c]);
			}
		}
	}
	return 0;
}
Пример #6
0
void delete_qso(void)
{
    int x, rc;
    struct stat statbuf;
    int lfile;
    char logline[100];
    char call[15], bandmode[6];

    mvprintw(13, 29, "OK to delete last qso (y/n)?");
    x = key_get();

    if ((x == 'y') || (x == 'Y')) {

	if ((lfile = open(logfile, O_RDWR)) < 0) {

	    mvprintw(24, 0, "I can not find the logfile...");
	    refreshp();
	    sleep(2);
	} else {

	    fstat(lfile, &statbuf);

	    if (statbuf.st_size >= LOGLINELEN) {
	        if (qtcdirection > 0) {
		    // read band, mode and call from last QSO line
		    lseek(lfile, ((int)statbuf.st_size - LOGLINELEN), SEEK_SET);
		    rc = read(lfile, logline, LOGLINELEN-1);

		    g_strlcpy(bandmode, logline, 6);
		    g_strlcpy(call, logline+29, 15);
		    g_strchomp(call);

		    // delete QTC's for that combination of band, mode and call
		    delete_last_qtcs(call, bandmode);
                }
		rc = ftruncate(lfile, statbuf.st_size - LOGLINELEN);
	    }

	    fsync(lfile);
	    close(lfile);

	    if (qsos[nr_qsos][0] != ';') {
		band_score[bandinx]--;
		qsonum--;
		qsonr_to_str();
	    }

	    nr_qsos--;
	    qsos[nr_qsos][0] = '\0';
	}

	scroll_log();

    }

    attron(COLOR_PAIR(C_LOG) | A_STANDOUT);
    mvprintw(13, 29, "                            ");

    printcall();

    clear_display();
}
Пример #7
0
int matrix(struct matrix_conf *conf, WINDOW *mainwin)
{
	int r, c, i, j;
	struct column *cols;
	FILE *gfp;
	long filesize;

	if(conf->mode == MODE_FILE) {
		gfp = fopen(conf->filename, "r+");
		if(!gfp) {
			conf->mode = MODE_NUMBERS;
			printf("Failed to open %s\n", conf->filename);
			return 0;
		}
		fseek(gfp, 0, SEEK_END);
		filesize = ftell(gfp);
		fseek(gfp, 0, SEEK_SET);
	}


	get_term_size(&r, &c);
	start_color();
	init_pair(1, COLOR_WHITE, COLOR_BLACK);
	init_pair(2, COLOR_GREEN, COLOR_BLACK);

	wbkgd(mainwin, COLOR_PAIR(1));
	cols = malloc(sizeof(struct column) * c / 2);
	memset(cols, 0, sizeof(struct column) * c / 2);


repeat:
	wclear(mainwin);
	for(i = 0; i < c/2; i++) {
		int flag;
		struct column *col = &cols[i];

		if(!col->rows) {
			col->rows = (char *)malloc(r * sizeof(char));
			memset(col->rows, 0, r * sizeof(char));
			col->file_offset = random() % filesize;
		}

		memmove(col->rows + 1, col->rows, r - 1);
		if(col->rows[1] == 0) {
			/* The last row was disabled */
			if(prob(2)) {
				/* With 10% probability start a new streak */
				if(conf->mode == MODE_NUMBERS)
					col->rows[0] = get_random_num();
				else
					col->rows[0] = get_next_char(&gfp, &col->file_offset);
			}

		} else {
			/* The last row was disabled */
			if(prob(10)) {
				/* With 30% probability stop this streak */
				col->rows[0] = 0;
			} else {
				if(conf->mode == MODE_NUMBERS)
					col->rows[0] = get_random_num();
				else
					col->rows[0] = get_next_char(&gfp, &col->file_offset);
			}
		}

		flag = 0;
		attron(COLOR_PAIR(2));
		for(j = r - 1; j >= 0; j--) {
			if(col->rows[j] != 0) {

				if(prob(10))
					col->rows[j]++;

				if(flag && prob(40))
					col->rows[j]++;

				mvwaddch(mainwin, j, i * 2, col->rows[j]);
				if(flag) {
					attroff(COLOR_PAIR(1));
					flag = 0;
					attron(COLOR_PAIR(2));
				}
			} else {
				flag = 1;
				attroff(COLOR_PAIR(2));
				attron(COLOR_PAIR(1));
			}
		}
	}
	refresh();
	usleep(80000);
	goto repeat;

	sleep(5);
	return 0;
}
Пример #8
0
void print_tank(int y, int x, TankDesign *tank_type, int *position)
{
	if (matrix[y - 1 - y1b][x - 1 - x1b] == 'g') lst->curr->tankAll.tank.visit_grass[0][0] = 1;
	else{
		attron(COLOR_PAIR(tank_type[position[0]].paint));
		mvaddch(y - 1, x - 1, tank_type[position[0]].ch);
	}
	matrix[y - 1 - y1b][x - 1 - x1b] = 't';

	if (matrix[y - 1 - y1b][x - x1b] == 'g') lst->curr->tankAll.tank.visit_grass[0][1] = 1;
	else{
		attron(COLOR_PAIR(tank_type[position[1]].paint));
		mvaddch(y - 1, x, tank_type[position[1]].ch);
	}
	matrix[y - 1 - y1b][x - x1b] = 't';

	if (matrix[y - 1 - y1b][x + 1 - x1b] == 'g') lst->curr->tankAll.tank.visit_grass[0][2] = 1;
	else{
		attron(COLOR_PAIR(tank_type[position[2]].paint));
		mvaddch(y - 1, x + 1, tank_type[position[2]].ch);
	}
	matrix[y - 1 - y1b][x + 1 - x1b] = 't';

	if (matrix[y - y1b][x - 1 - x1b] == 'g') lst->curr->tankAll.tank.visit_grass[1][0] = 1;
	else{
		attron(COLOR_PAIR(tank_type[position[3]].paint));
		mvaddch(y, x - 1, tank_type[position[3]].ch);
	}
	matrix[y - y1b][x - 1 - x1b] = 't';

	if (matrix[y - y1b][x - x1b] == 'g') lst->curr->tankAll.tank.visit_grass[1][1] = 1;
	else{
		attron(COLOR_PAIR(tank_type[position[4]].paint));
		mvaddch(y, x, tank_type[position[4]].ch);
	}
	matrix[y - y1b][x - x1b] = 't';

	if (matrix[y - y1b][x + 1 - x1b] == 'g') lst->curr->tankAll.tank.visit_grass[1][2] = 1;
	else{
		attron(COLOR_PAIR(tank_type[position[5]].paint));
		mvaddch(y, x + 1, tank_type[position[5]].ch);
	}
	matrix[y - y1b][x + 1 - x1b] = 't';

	if (matrix[y + 1 - y1b][x - 1 - x1b] == 'g') lst->curr->tankAll.tank.visit_grass[2][0] = 1;
	else{
		attron(COLOR_PAIR(tank_type[position[6]].paint));
		mvaddch(y + 1, x - 1, tank_type[position[6]].ch);
	}
	matrix[y + 1 - y1b][x - 1 - x1b] = 't';

	if (matrix[y + 1 - y1b][x - x1b] == 'g') lst->curr->tankAll.tank.visit_grass[2][1] = 1;
	else{
		attron(COLOR_PAIR(tank_type[position[7]].paint));
		mvaddch(y + 1, x, tank_type[position[7]].ch);
	}
	matrix[y + 1 - y1b][x - x1b] = 't';

	if (matrix[y + 1 - y1b][x + 1 - x1b] == 'g') lst->curr->tankAll.tank.visit_grass[2][2] = 1;
	else{
		attron(COLOR_PAIR(tank_type[position[8]].paint));
		mvaddch(y + 1, x + 1, tank_type[position[8]].ch);
	}
	matrix[y + 1 - y1b][x + 1 - x1b] = 't';


	refresh();
}
Пример #9
0
static void draw_title_scene() {
  attron(COLOR_PAIR(TITLE_COLOR_PAIR));
  move(TITLE_POSITION_X, TITLE_POSITION_Y - strlen(TITLE_TEXT) / 2);
  addstr(TITLE_TEXT);
}
Пример #10
0
void print_white(int y, int x)
{
	attron(COLOR_PAIR(13));
	mvaddch(y, x, ACS_BOARD);
	matrix[y - y1b][x - x1b] = 'h';
}
Пример #11
0
void print_head(int y, int x)
{
	attron(COLOR_PAIR(6));
	mvaddch(y, x, ACS_BOARD | A_BOLD);
	matrix[y - y1b][x - x1b] = 'h';
}
Пример #12
0
void print_blanko(int y, int x){
	attron(COLOR_PAIR(6));
	mvaddch(y, x, ' ');
	matrix[y - y1b][x - x1b] = ' ';
}
Пример #13
0
void print_wall(int y, int x){
	attron(COLOR_PAIR(13));
	mvaddch(y, x, ACS_PLUS | A_BOLD);
	matrix[y - y1b][x - x1b] = 'c';
}
Пример #14
0
void print_water(int y, int x){
	attron(COLOR_PAIR(12));
	mvaddch(y, x, ACS_BOARD);
	matrix[y - y1b][x - x1b] = 'w';
}
Пример #15
0
static int
dialog_run (pinentry_t pinentry, const char *tty_name, const char *tty_type)
{
  struct dialog diag;
  FILE *ttyfi = NULL;
  FILE *ttyfo = NULL;
  SCREEN *screen = 0;
  int done = 0;
  char *pin_utf8;

  /* Open the desired terminal if necessary.  */
  if (tty_name)
    {
      ttyfi = fopen (tty_name, "r");
      if (!ttyfi)
	return -1;
      ttyfo = fopen (tty_name, "w");
      if (!ttyfo)
	{
	  int err = errno;
	  fclose (ttyfi);
	  errno = err;
	  return -1;
	}
      screen = newterm (tty_type, ttyfo, ttyfi);
      set_term (screen);
    }
  else
    {
      if (!init_screen)
	{
	  init_screen = 1;
	  initscr ();
	}
      else
	clear ();
    }
  
  keypad (stdscr, TRUE); /* Enable keyboard mapping.  */
  nonl ();		/* Tell curses not to do NL->CR/NL on output.  */
  cbreak ();		/* Take input chars one at a time, no wait for \n.  */
  noecho ();		/* Don't echo input - in color.  */

  if (has_colors ())
    {
      start_color ();
      use_default_colors ();

      if (pinentry->color_so == PINENTRY_COLOR_DEFAULT)
	{
	  pinentry->color_so = PINENTRY_COLOR_RED;
	  pinentry->color_so_bright = 1;
	}
      if (COLOR_PAIRS >= 2)
	{
	  init_pair (1, pinentry_color[pinentry->color_fg],
		     pinentry_color[pinentry->color_bg]);
	  init_pair (2, pinentry_color[pinentry->color_so],
		     pinentry_color[pinentry->color_bg]);

	  bkgd (COLOR_PAIR (1));
	  attron (COLOR_PAIR (1) | (pinentry->color_fg_bright ? A_BOLD : 0));
	}
    }
  refresh ();

  /* XXX */
  if (dialog_create (pinentry, &diag))
    return -2;
  dialog_switch_pos (&diag, diag.pin ? DIALOG_POS_PIN : DIALOG_POS_OK);

  do
    {
      int c;

      c = getch ();     /* Refresh, accept single keystroke of input.  */

      switch (c)
	{
	case KEY_LEFT:
	case KEY_UP:
	  switch (diag.pos)
	    {
	    case DIALOG_POS_OK:
	      if (diag.pin)
		dialog_switch_pos (&diag, DIALOG_POS_PIN);
	      break;
	    case DIALOG_POS_CANCEL:
	      dialog_switch_pos (&diag, DIALOG_POS_OK);
	      break;
	    default:
	      break;
	    }
	  break;

	case KEY_RIGHT:
	case KEY_DOWN:
	  switch (diag.pos)
	    {
	    case DIALOG_POS_PIN:
	      dialog_switch_pos (&diag, DIALOG_POS_OK);
	      break;
	    case DIALOG_POS_OK:
	      dialog_switch_pos (&diag, DIALOG_POS_CANCEL);
	      break;
	    default:
	      break;
	    }
	  break;

	case '\t':
	  switch (diag.pos)
	    {
	    case DIALOG_POS_PIN:
	      dialog_switch_pos (&diag, DIALOG_POS_OK);
	      break;
	    case DIALOG_POS_OK:
	      dialog_switch_pos (&diag, DIALOG_POS_CANCEL);
	      break;
	    case DIALOG_POS_CANCEL:
	      if (diag.pin)
		dialog_switch_pos (&diag, DIALOG_POS_PIN);
	      else
		dialog_switch_pos (&diag, DIALOG_POS_OK);
	      break;
	    default:
	      break;
	    }
	  break;
  
	case '\e':
	  done = -2;
	  break;

	case '\r':
	  switch (diag.pos)
	    {
	    case DIALOG_POS_PIN:
	    case DIALOG_POS_OK:
	      done = 1;
	      break;
	    case DIALOG_POS_CANCEL:
	      done = -2;
	      break;
            case DIALOG_POS_NONE:
              break;
	    }
	  break;

	default:
	  if (diag.pos == DIALOG_POS_PIN)
	    dialog_input (&diag, c);
	}
    }
  while (!done);

  set_cursor_state (1);
  endwin ();
  if (screen)
    delscreen (screen);

  if (ttyfi)
    fclose (ttyfi);
  if (ttyfo)
    fclose (ttyfo);
  /* XXX Factor out into dialog_release or something.  */
  free (diag.ok);
  free (diag.cancel);

  if (pinentry->pin)
    {
      pinentry->locale_err = 1;
      pin_utf8 = pinentry_local_to_utf8 (pinentry->lc_ctype, pinentry->pin, 1);
      if (pin_utf8)
	{
	  pinentry_setbufferlen (pinentry, strlen (pin_utf8) + 1);
	  if (pinentry->pin)
	    strcpy (pinentry->pin, pin_utf8);
	  secmem_free (pin_utf8);
	  pinentry->locale_err = 0;
	}
    }

  return diag.pin ? (done < 0 ? -1 : diag.pin_len) : (done < 0 ? 0 : 1);
}
Пример #16
0
static void draw_ingame_scene(struct invaders_game *game) {
  int i, j;

  /* Render the player jet */
  if (0 <= game->credit) {
    attron(COLOR_PAIR(PLAYER_JET_COLOR_PAIR));
    move(game->player_jet.position.x, game->player_jet.position.y + 1);
    addch(PLAYER_JET_RENDERING_CHAR);
    move(game->player_jet.position.x + 1, game->player_jet.position.y);
    addch(PLAYER_JET_RENDERING_CHAR);
    addch(PLAYER_JET_RENDERING_CHAR);
    addch(PLAYER_JET_RENDERING_CHAR);
  }

  /* Render the player bullet */
  if (game->player_bullet.active) {
    attron(COLOR_PAIR(PLAYER_BULLET_COLOR_PAIR));
    move(game->player_bullet.position.x, game->player_bullet.position.y);
    addch(PLAYER_BULLET_RENDERING_CHAR);
  }

  /* Render the tochcas */
  attron(COLOR_PAIR(TOCHCA_COLOR_PAIR));
  for (i = 0; i < N_ELEMENTS(game->tochcas); ++i) {
    for (j = 0; j < N_ELEMENTS(game->tochcas[i].block_standings); ++j) {
      if (game->tochcas[i].block_standings[j]) {
        move(game->tochcas[i].position.x + (j % N_TOCHCA_BLOCKS_LAYOUT_X),
             game->tochcas[i].position.y + (j / N_TOCHCA_BLOCKS_LAYOUT_X));
        addch(TOCHCA_RENDERING_CHAR);
      }
    }
  }

  /* Render the invaders */
  for (i = 0; i < N_ELEMENTS(game->invader_team.members); ++i) {
    draw_invader(&game->invader_team.members[i]);
  }
  draw_invader(&game->invader_team.commander);

  /* Render the invader bullets */
  for (i = 0; i < N_ELEMENTS(game->invader_bullets); ++i) {
    if (game->invader_bullets[i].active) {
      attron(COLOR_PAIR(INVADER_BULLET_COLOR_PAIR));
      move(game->invader_bullets[i].position.x,
           game->invader_bullets[i].position.y);
      addch(INVADER_BULLET_RENDERING_CHAR);
    }
  }

  /* Render score HUD */
  attron(COLOR_PAIR(SCORE_COLOR_PAIR));
  move(SCORE_POSITION_X,
       SCORE_POSITION_Y - 11/* the length of "SCORE: %04ld" */);
  printw("SCORE: %04ld", game->score);

  /* Render credit HUD */
  attron(COLOR_PAIR(CREDIT_COLOR_PAIR));
  move(CREDIT_POSITION_X, CREDIT_POSITION_Y);
  printw("CREDIT: %d", game->credit);

  /* Render caption HUD with blinking */
  if (game->event_caption.displaying
      && (EVENT_CAPTION_BLINKING_INTERVAL
          <= game->event_caption.timer.counter % 1000L)) {
    attron(COLOR_PAIR(EVENT_CAPTION_COLOR_PAIR));
    const char *caption_text =
        (GAME_CLEAR_EVENT == game->event) ?
        GAME_CLEAR_CAPTION_TEXT : GAME_OVER_CAPTION_TEXT;
    move(EVENT_CAPTION_POSITION_X,
         EVENT_CAPTION_POSITION_Y - strlen(caption_text) / 2);
    printw(caption_text);
  }
}
Пример #17
0
void
StockTicker::draw()
{
    int				x;
    int				y;
    int				yo;


    // 
    // Print all the stocks, starting from the top of the screen.
    y	= 0;
    yo	= 0;
    for( stock *s = stocks; s; s = s->next ) {
        s->draw( y + yo++, 20 );
    }

    //
    // Print the label of each holding.  Assume every player's holdings
    // are in the same order.
    y = ST_MODLIN - stockCount - 5;
    yo = 1;
    mvprintw( y + yo++, 0, "Net Worth:" );
    mvprintw( y + yo++, 0, "Cash/Loan:" );
    mvprintw( y + yo++, 0, "Margin:" );
    for ( stock *s = stocks; s; s = s->next ) {
	mvprintw( y + yo++, 0, "%s:", 
		 s->name );
    }

    // 
    // Now, print the players.
    x = ST_PLAYERWIDTH;
    for ( player *p = players; p; p = p->next ) {
	yo = 0;
	mvprintw( y + yo++, x, "%10.10s", p->name );
	if ( p->worth > 9999999 )
	    mvprintw( y + yo++, x, "%9.3g=", (double)p->worth );
	else
	    mvprintw( y + yo++, x, "%9d=", (int)p->worth );
	if ( p->cash < - p->margin() ) {
	    attron( A_REVERSE );
	    beep();
	} else if ( p->cash < - p->margin() * 90 / 100 ) {
	    attron( A_BLINK );
	}
	if ( p->cash > 9999999 || p->cash < -999999 )
	    mvprintw( y + yo++, x, "%9.3g$", (double)p->cash );
	else
	    mvprintw( y + yo++, x, "%9d$", (int)p->cash );
	attroff( A_BLINK );
	attroff( A_REVERSE );
	long long	margin	= p->margin();
	if ( margin > 9999999 )
	    mvprintw( y + yo++, x, "%9.3g$", (double)margin );
	else
	    mvprintw( y + yo++, x, "%9d$", (int)margin );
	for ( stock *s = stocks; s; s = s->next ) {
	    if ( p->holdings ) {
		holding *h = p->holdings->find( s->key );
		if ( h ) {
		    if ( h->key == p->bought
			 && p->cash < - p->margin() )
			attron( A_REVERSE );		// This is the one we'll try to sell first...
		    h->draw( y + yo++, x );
		    attroff( A_REVERSE );
		}
	    }
	}
	x += ST_PLAYERWIDTH;
    }
}
Пример #18
0
int main(int argc, char *argv[])
{
    int ch;

    initscr();
    start_color();
    cbreak();
    keypad(stdscr, TRUE);
    noecho();
    curs_set(0);
    init_pair(1, COLOR_CYAN, COLOR_BLACK);

    attron(COLOR_PAIR(1));
    //画边
    mvaddch(1, 0, '+');
    mvaddch(1, COLS-1, '+');
    mvaddch(LINES-1, COLS-1, '+');
    mvaddch(LINES-1, 0, '+');
    mvhline(1, 1, '-', COLS-1-1);
    mvhline(LINES-1, 1, '-', COLS-1-1);
    mvvline(2, 0, '|', LINES-2-1);
    mvvline(2, COLS-1, '|', LINES-2-1);

    refresh();
    attroff(COLOR_PAIR(1));

    // 来条蛇
    SNAKE snake;
    init_snake(&snake);
    draw_whole_snake(&snake);
    
    // 初始豆儿
    int *food;
    food = random_food(&snake);
    //mvaddch(food[1], food[0], '*');
    draw_food(food);

    int d;
    int i;
    now_time=0;
    while (1)
    {
        if(ioctl(0,FIONREAD,&i)<0)
        {
            printf("ioctl failed, error=%d\n ",errno);
            break;
        }
        if(!i)  // 小蛇自动跑部分
        {
            usleep(time_rate);
            now_time = now_time + time_rate;
            if (!(now_time < speed))
            {
                now_time = 0;
                if (snake_move(&snake, food))
                    break;
            }
            continue;
        }
        now_time = 0;
        ch = getch();
        if (ch < 258 || ch > 261)
            continue;
        if ( ch+snake.d != KEY_LEFT+KEY_UP )
        {
            d = ch - snake.d;
            if ( d == 1 || d == -1)
                continue;
        }
        snake.d = ch;

        if (snake_move(&snake, food))
            break;

    }
    getch();
    endwin();
    return 0;
}
Пример #19
0
void	Coffee::draw( void ) const {
	attron(COLOR_PAIR(2));
	mvaddstr(this->_row, this->_col, "♥");
	attron(COLOR_PAIR(4));
}
Пример #20
0
/**
 * Main function. Initializes and starts the game
 */
int spitm() {listP mao1,mao2,pl11,pl12,pl13,pl14,pl21,pl22,pl23,pl24;
    int stock1[stk],stock2[stk],baralho[(num*2)-2],pc1[sz],pc2[sz],pc3[sz];
    mao1=mao2=pl11=pl12=pl13=pl14=pl21=pl22=pl23=pl24=NULL;
    int vencedor=0,turno=1,o,d,i=0,n=0,x=(LINES/2),y=(COLS/2);

    initscr();
    cbreak();
    keypad(stdscr,TRUE);
    noecho();
    start_color();
    init_pair(1,COLOR_WHITE,COLOR_GREEN);
    init_pair(2,COLOR_RED,COLOR_GREEN);
    bkgd(COLOR_PAIR(1));
    attron(COLOR_PAIR(2));

    limpa(pc1,13);
    limpa(pc2,13);
    limpa(pc3,13);
    shuff(baralho);
    atoa(baralho,stock1,20);
    atoa(baralho,stock2,20);
    mao1=atod(baralho,mao1,5);
    mao2=atod(baralho,mao2,5);
    while(!i) {
        if(stock1[0] > stock2[0]) {
            turno=1;i++;
        };break;
	    if(stock1[0] < stock2[0]) {
            turno=2;
            i++;
        };break;
	    barStk(stock1,stk);
        barStk(stock2,stk);
	};
    
    while(vencedor==0) {
        while(elemN(mao1)<5)
            mao1=atod(baralho,mao1,1);
        while(turno==1)	{
            clear();
            mostrac(mao1,pl11, pl12,pl13, pl14, mao2, pl21, pl22, pl23,pl24, pc1, pc2, pc3, stock1, stock2,turno);
            echo();
            mvprintw(22,0,"Insira origem(1-10) e destino (1-7):__ __");
            mvscanw(22,36," %d %d",&o,&d);
            if(o>0 && o<6) {
                if(d==1) {
                    if (showi(mao1,elemN(mao1)-o) == topAr(pc1)+1) {
                        dtoa(mao1,elemN(mao1)-o,pc1);
                    };
                };
                if(d==2) {
                    if (showi(mao1,elemN(mao1)-o) == topAr(pc2)+1) {
                        dtoa(mao1,elemN(mao1)-o,pc2);
                    };
                };
			    if(d==3) {
                    if (showi(mao1,elemN(mao1)-o) == topAr(pc3)+1) {
                        dtoa(mao1,elemN(mao1)-o,pc3);
                    };
                };
    			if(d==4) {
                    pl11=poe(pl11,showi(mao1,elemN(mao1)-o));
                    if(elemN(mao1) == o) {
                        mao1=rmUlt(mao1);turno=2;
                    } else {
                        rmI(mao1,elemN(mao1)-(o));
                        turno=2;
                    };
                };
	
			    if(d==5) {
                    pl12=poe(pl12,showi(mao1,elemN(mao1)-o));
                    if(elemN(mao1) == o) {
                        mao1=rmUlt(mao1);
                        turno=2;
                    } else {
                        rmI(mao1,elemN(mao1)-(o));
                        turno=2;
                    };
                };
			    if(d==6) {
                    pl13=poe(pl13,showi(mao1,elemN(mao1)-o));
                    if(elemN(mao1) == o) {
                        mao1=rmUlt(mao1);
                        turno=2;
                    } else {
                        rmI(mao1,elemN(mao1)-(o));
                        turno=2;
                    };
                };
			    if(d==7) {
                    pl14=poe(pl14,showi(mao1,elemN(mao1)-o));
                    if(elemN(mao1) == o) {
                        mao1=rmUlt(mao1);
                        turno=2;
                    } else {
                        rmI(mao1,elemN(mao1)-(o));
                        turno=2;
                    };
                };
			}; //end if(o>0 && o<6)
            if(o==10) {
                if(d==1){
                    if (topAr(stock1) == topAr(pc1)+1) {
                        addAe(stock1,pc1);
                    };
                };
			    if(d==2) {
                    if (topAr(stock1) == topAr(pc2)+1) {
                        addAe(stock1,pc2);
                    };
                };
			    if(d==3) {
                    if (topAr(stock1) == topAr(pc3)+1) {
                        addAe(stock1,pc3);
                    };
                };
            };
            if(o>5 && o< 10) {
                if(o==6 && d==1 && (elemN(pl11)!=0)) {
                    if (showi(pl11,elemN(pl11)-o) == topAr(pc1)+1) {
                        dtoa(pl11,elemN(pl11)-1,pc1);
                    };
                };
			    if(o==7 && d==1 && (elemN(pl12)!=0)) {
                    if (showi(pl12,elemN(pl12)-o) == topAr(pc1)+1) {
                        dtoa(pl12,elemN(pl12)-1,pc1);
                    };
                };
			    if(o==8 && d==1 && (elemN(pl13)!=0)) {
                    if (showi(pl13,elemN(pl13)-o) == topAr(pc1)+1) {
                        dtoa(pl13,elemN(pl13)-1,pc1);
                    };
                };
                if(o==9 && d==1 && (elemN(pl14)!=0)) {
                    if (showi(pl14,elemN(pl14)-o) == topAr(pc1)+1) {
                        dtoa(pl14,elemN(pl14)-1,pc1);
                    };
                };
            
                if(o==6 && d==2 && (elemN(pl11)!=0)) {
                    if (showi(pl11,elemN(pl11)-o) == topAr(pc2)+1) {
                        dtoa(pl11,elemN(pl11)-1,pc2);
                    };
                };
                if(o==7 && d==2 && (elemN(pl12)!=0)) {
                    if (showi(pl12,elemN(pl12)-o) == topAr(pc2)+1) {
                        dtoa(pl12,elemN(pl12)-1,pc2);
                    };
                };
                if(o==8 && d==2 && (elemN(pl13)!=0)) {
                    if (showi(pl13,elemN(pl13)-o) == topAr(pc2)+1) {
                        dtoa(pl13,elemN(pl13)-1,pc2);
                    };
                };
                if(o==9 && d==2 && (elemN(pl14)!=0)) {
                    if (showi(pl14,elemN(pl14)-o) == topAr(pc2)+1) {
                        dtoa(pl14,elemN(pl14)-1,pc2);
                    };
                };

                if(o==6 && d==3 && (elemN(pl11)!=0)) {
                    if (showi(pl11,elemN(pl11)-o) == topAr(pc3)+1) {
                        dtoa(pl11,elemN(pl11)-1,pc3);
                    };
                };
                if(o==7 && d==3 && (elemN(pl12)!=0)) {
                    if (showi(pl12,elemN(pl12)-o) == topAr(pc3)+1) {
                        dtoa(pl12,elemN(pl12)-1,pc3);
                    };
                };
                if(o==8 && d==3 && (elemN(pl13)!=0)) {
                    if (showi(pl13,elemN(pl13)-o) == topAr(pc3)+1) {
                        dtoa(pl13,elemN(pl13)-1,pc3);
                    };
                };
                if(o==9 && d==3 && (elemN(pl14)!=0)) {
                    if (showi(pl14,elemN(pl14)-o) == topAr(pc3)+1) {
                        dtoa(pl14,elemN(pl14)-1,pc3);
                    };
                };
            };//end if(o>5 && o< 10)
        }; //end while(turno==1)

        n=0;
        while ((stock1[n]==0) && (n<stk)) {
            n++;
        };
        // Winner is player 1
        if (stock1[n] == 0) {
            vencedor=1;
            turno=1;
        }

        // Tie
        if(baralho[num*2-3]==0)	{
            vencedor=3;
        };

        // Clean central stack
        if(pc1[0]==13) {
            atoa(pc1,baralho,13);
        };
        if(pc2[0]==13) {
            atoa(pc2,baralho,13);
        };
        if(pc3[0]==13) {
            atoa(pc3,baralho,13);
        };

        // fill hand 2
        while(elemN(mao2)<5) {
            mao2=atod(baralho,mao2,1);
        };

        while(turno==2) {
            clear();
            mostrac(mao1,pl11, pl12,pl13, pl14, mao2, pl21, pl22, pl23,pl24, pc1, pc2, pc3, stock1, stock2,turno);
            echo();
            mvprintw(22,0,"Insira origem(1-10) e destino (1-7):__ __");
            mvscanw(22,36,"%d %d",&o,&d);
            if(o>0 && o<6) {
                if(d==1) {
                    if (showi(mao2,elemN(mao2)-o) == topAr(pc1)+1) {
                        dtoa(mao2,elemN(mao2)-o,pc1);};
                    };
                    if(d==2) {
                        if (showi(mao2,elemN(mao2)-o) == topAr(pc2)+1) {
                            dtoa(mao2,elemN(mao2)-o,pc2);
                        };
                    };
                    if(d==3) {
                        if (showi(mao2,elemN(mao2)-o) == topAr(pc3)+1) {
                            dtoa(mao2,elemN(mao2)-o,pc3);
                        };
                    };
                    if(d==4) {
                        pl21=poe(pl21,showi(mao2,elemN(mao2)-o));
                        if(elemN(mao2) == o) {
                            mao2=rmUlt(mao2);turno=1;
                        } else {
                            rmI(mao2,elemN(mao2)-(o));
                            turno=1;
                        };
                    };
                    if(d==5) {
                        pl22=poe(pl22,showi(mao2,elemN(mao2)-o));
                        if(elemN(mao2) == o) {
                            mao2=rmUlt(mao2);
                            turno=1;
                        } else {
                            rmI(mao2,elemN(mao2)-(o));
                            turno=1;
                        };
                    };
                    if(d==6) {
                        pl23=poe(pl23,showi(mao2,elemN(mao2)-o));
                        if(elemN(mao2) == o) {
                            mao2=rmUlt(mao2);
                            turno=1;
                        } else {
                            rmI(mao2,elemN(mao2)-(o));
                            turno=1;
                        };
                    };
                    if(d==7) {
                        pl24=poe(pl24,showi(mao2,elemN(mao2)-o));
                        if(elemN(mao2) == o) {
                            mao2=rmUlt(mao2);
                            turno=1;
                        } else {
                            rmI(mao2,elemN(mao2)-(o));
                            turno=1;
                        }
                    };
		        };
                if(o==10) {
                    if(d==1){
                        if (topAr(stock2) == topAr(pc1)+1) {
                            addAe(stock2,pc1);
                        };
			        };
		            if(d==2) {
                        if (topAr(stock2) == topAr(pc2)+1) {
                            addAe(stock2,pc2);
                        };
			        };
                    if(d==3) {
                        if (topAr(stock2) == topAr(pc3)+1)  {
                            addAe(stock2,pc3);
                        };
				    };
                };
                if(o>5 && o< 10) {
                    if(o==6 && d==1 && (elemN(pl21)!=0)) {
                        if (showi(pl21,elemN(pl21)-o) == topAr(pc1)+1) {
                            dtoa(pl21,elemN(pl21)-1,pc1);
                        };
                    };
                    if(o==7 && d==1 && (elemN(pl22)!=0)) {
                        if (showi(pl22,elemN(pl22)-o) == topAr(pc1)+1) {
                            dtoa(pl22,elemN(pl22)-1,pc1);
                        };
                    };
                if(o==8 && d==1 && (elemN(pl23)!=0)) {
                    if (showi(pl23,elemN(pl23)-o) == topAr(pc1)+1) {
                        dtoa(pl23,elemN(pl23)-1,pc1);
                    };
                };
                if(o==9 && d==1 && (elemN(pl24)!=0)) {
                    if (showi(pl24,elemN(pl24)-o) == topAr(pc1)+1) {
                        dtoa(pl24,elemN(pl24)-1,pc1);
                    };
                };
                if(o==6 && d==2 && (elemN(pl21)!=0)) {
                    if (showi(pl21,elemN(pl21)-o) == topAr(pc2)+1) {
                        dtoa(pl21,elemN(pl21)-1,pc2);
                    };
                };
                if(o==7 && d==2 && (elemN(pl22)!=0)) {
                    if (showi(pl22,elemN(pl22)-o) == topAr(pc2)+1) {
                        dtoa(pl22,elemN(pl22)-1,pc2);
                    };
			    };
                if(o==8 && d==2 && (elemN(pl23)!=0)) {
                    if (showi(pl23,elemN(pl23)-o) == topAr(pc2)+1) {
                         dtoa(pl23,elemN(pl23)-1,pc2);
                     };
                };
                if(o==9 && d==2 && (elemN(pl24)!=0)) {
                    if (showi(pl24,elemN(pl24)-o) == topAr(pc2)+1) {
                        dtoa(pl24,elemN(pl24)-1,pc2);
                    };
                };

                if(o==6 && d==3 && (elemN(pl21)!=0)) {
                    if (showi(pl21,elemN(pl21)-o) == topAr(pc3)+1) {
                        dtoa(pl21,elemN(pl21)-1,pc3);
                    };
                };
                if(o==7 && d==3 && (elemN(pl22)!=0)) {
                    if (showi(pl22,elemN(pl22)-o) == topAr(pc3)+1) {
                        dtoa(pl22,elemN(pl22)-1,pc3);
                    };
                };
                if(o==8 && d==3 && (elemN(pl23)!=0)) {
                    if (showi(pl23,elemN(pl23)-o) == topAr(pc3)+1) {
                        dtoa(pl23,elemN(pl23)-1,pc3);
                    };
                };
                if(o==9 && d==3 && (elemN(pl24)!=0)) {
                    if (showi(pl24,elemN(pl24)-o) == topAr(pc3)+1) {
                        dtoa(pl24,elemN(pl24)-1,pc3);
                    };
                };
             };
        };
        n=0;
        while ((stock2[n]==0) && (n<stk)) {
            n++;
        };
        // Winner is player 2
        if (stock2[n] == 0) {
            vencedor=1;
            turno=1;
        }

        // Tie
        if(baralho[num*2-3]==0) {
            vencedor=3;
        };

        // Clean central stack
        if(pc1[0]==13) {
            atoa(pc1,baralho,13);
        };
        if(pc2[0]==13) {
            atoa(pc2,baralho,13);
        };
        if(pc3[0]==13) {
            atoa(pc3,baralho,13);
        };
    };
    if((vencedor==1)||(vencedor==2)) {
        clear();
        mvprintw(x-1,y-10,"+------------------------------------+");
        mvprintw(x,y-10,"|O jogador %d vence!                 |",vencedor);
        mvprintw(x+1,y-10,"+------------------------------------+");
        getch();
    } else {
        clear();
        mvprintw(x-1,y-10,"+------------------------------------+");
        mvprintw(x,y-10,"|Empate, não há vencedores.          |");
        mvprintw(x+1,y-10,"+------------------------------------+");
        getch();
    };
    endwin();
    bkgd(COLOR_PAIR(2));
    return 0;
}
Пример #21
0
int
main(int argc, char *argv[])
{
	uint8_t		updb_all;
	int 		ch;
	struct stat	sb;
	const char	*chrootpath = NULL;

	setprogname(argv[0]);

	while ((ch = getopt(argc, argv, "fFgsv")) != -1) {
		switch (ch) {
		//case 'f':
		//	force_update = 1;
		//	break;
		//case 'F':
		//	force_reinstall = 1;
		//	break;
		case 'v':
			version();
			/* NOTREACHED */
		case 's':
			fullscreen = 1;
			break;
		case 'c':
			chrootpath = optarg;
			break;
		case 'g':
			colouring = 1;
			break;
		default:
			usage();
			/* NOTREACHED */
		}
	}
	argc -= optind;
	argv += optind;

	/* initializations */

	initscr();
	keypad(stdscr, TRUE);
	noecho();
	cbreak();

	/* Size will be overwritten by show_mainwin anyway. */
	mainwin = newwin(10, 10, 1, 2);
	keypad(mainwin, TRUE);

	if (colouring) {
		start_color();
		init_pair(1, COLOR_WHITE, COLOR_BLUE);
		attron(COLOR_PAIR(1));
		bkgd(COLOR_PAIR(1));
		wbkgd(mainwin, COLOR_PAIR(1));
		wattron(mainwin, COLOR_PAIR(1));
	}

	show_mainwin(1);
	for (;;) {
		if (do_menu(main_menu, sizeof(main_menu)/sizeof(struct menuoption), 0, "pkgui"))
			ask_exit();
	}

	attroff(COLOR_PAIR(1));
	endwin();
	exit(EXIT_SUCCESS);
}
Пример #22
0
int main()
{	WINDOW *my_wins[3];
	PANEL  *my_panels[3];
	PANEL_DATA panel_datas[3];
	PANEL_DATA *temp;
	int ch;

	/* Initialize curses */
	initscr();
	start_color();
	cbreak();
	noecho();
	keypad(stdscr, TRUE);

	/* Initialize all the colors */
	init_pair(1, COLOR_RED, COLOR_BLACK);
	init_pair(2, COLOR_GREEN, COLOR_BLACK);
	init_pair(3, COLOR_BLUE, COLOR_BLACK);
	init_pair(4, COLOR_CYAN, COLOR_BLACK);

	init_wins(my_wins, 3);
	
	/* Attach a panel to each window */ 	/* Order is bottom up */
	my_panels[0] = new_panel(my_wins[0]); 	/* Push 0, order: stdscr-0 */
	my_panels[1] = new_panel(my_wins[1]); 	/* Push 1, order: stdscr-0-1 */
	my_panels[2] = new_panel(my_wins[2]); 	/* Push 2, order: stdscr-0-1-2 */

	/* Initialize panel datas saying that nothing is hidden */
	panel_datas[0].hide = FALSE;
	panel_datas[1].hide = FALSE;
	panel_datas[2].hide = FALSE;

	set_panel_userptr(my_panels[0], &panel_datas[0]);
	set_panel_userptr(my_panels[1], &panel_datas[1]);
	set_panel_userptr(my_panels[2], &panel_datas[2]);

	/* Update the stacking order. 2nd panel will be on top */
	update_panels();

	/* Show it on the screen */
	attron(COLOR_PAIR(4));
	mvprintw(LINES - 3, 0, "Show or Hide a window with 'a'(first window)  'b'(Second Window)  'c'(Third Window)");
	mvprintw(LINES - 2, 0, "F1 to Exit");

	attroff(COLOR_PAIR(4));
	doupdate();
	
	while((ch = getch()) != KEY_F(1))
	{	switch(ch)
		{	case 'a':			
				temp = (PANEL_DATA *)panel_userptr(my_panels[0]);
				if(temp->hide == FALSE)
				{	hide_panel(my_panels[0]);
					temp->hide = TRUE;
				}
				else
				{	show_panel(my_panels[0]);
					temp->hide = FALSE;
				}
				break;
			case 'b':
				temp = (PANEL_DATA *)panel_userptr(my_panels[1]);
				if(temp->hide == FALSE)
				{	hide_panel(my_panels[1]);
					temp->hide = TRUE;
				}
				else
				{	show_panel(my_panels[1]);
					temp->hide = FALSE;
				}
				break;
			case 'c':
				temp = (PANEL_DATA *)panel_userptr(my_panels[2]);
				if(temp->hide == FALSE)
				{	hide_panel(my_panels[2]);
					temp->hide = TRUE;
				}
				else
				{	show_panel(my_panels[2]);
					temp->hide = FALSE;
				}
				break;
		}
		update_panels();
		doupdate();
	}
	endwin();
	return 0;
}
Пример #23
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);
}
Пример #24
0
EXT_MOD_ENGINE void set_color(int id)
{
	attron(COLOR_PAIR(id));
}
Пример #25
0
static void display_logo() {
  attron(COLOR_PAIR(COL_LOGO) | A_BOLD);
  printw("%s", " Whisper Shell ");
  attroff(COLOR_PAIR(COL_LOGO) | A_BOLD);
}
Пример #26
0
/** \brief logs one record to disk
 * Logs one record to disk which may come from different sources
 * (direct from tlf or from other instance via LAN)
 *
 * \param from_lan true - Log lanmessage, false - normal message
 */
int log_to_disk(int from_lan)
{
    extern char hiscall[];
    extern char comment[];
    extern char my_rst[];
    extern char his_rst[];
    extern char last_rst[4];
    extern char qsonrstr[5];
    extern char lan_logline[];
    extern int rit;
    extern int trx_control;
    extern int cqmode;
#ifdef HAVE_LIBHAMLIB
    extern freq_t outfreq;
#else
    extern int outfreq;
#endif
    extern int block_part;
    extern char lan_message[];
    extern char thisnode;
    extern int lan_mutex;
    extern int cqwwm2;
    extern int no_rst;

    pthread_mutex_lock(&disk_mutex);

    if (!from_lan) {		// qso from this node

	addcall();		/* add call to dupe list */

	makelogline();

	store_qso(logline4);

	// send qso to other nodes......
	send_lan_message(LOGENTRY, logline4);

	if (trx_control && (cqmode == S_P))
	    addspot();		/* add call to bandmap if in S&P and
				   no need to ask for frequency */

	hiscall[0] = '\0';	/* reset the call  string */
	comment[0] = '\0';	/* reset the comment  string */

	strncpy(last_rst, his_rst, sizeof(last_rst)); /* remember last report */
	his_rst[1] = '9';	/* restore RST to 599 */
	my_rst[1] = '9';

    } else {			// qso from lan

	strncpy(lan_logline, lan_message + 2, 87);
	strcat(lan_logline,
	       "                                                                              ");

	if (cqwwm2 == 1) {
	    if (lan_logline[0] != thisnode)
		lan_logline[79] = '*';
	}

	lan_logline[87] = '\0';

	total = total + score2(lan_logline);

	addcall2();

	store_qso(lan_logline);
    }


    if (from_lan)
	lan_mutex = 2;
    else
	lan_mutex = 1;

    scroll_log();

    lan_mutex = 0;

    attron(modify_attr(COLOR_PAIR(NORMCOLOR)));	/* erase comment  field */

    if (!from_lan)
	mvprintw(12, 54, "                          ");

    attron(COLOR_PAIR(C_LOG) | A_STANDOUT);
    if (!from_lan) {
	mvprintw(7, 0, logline0);
	mvprintw(8, 0, logline1);
	mvprintw(9, 0, logline2);
    }
    mvprintw(10, 0, logline3);
    mvprintw(11, 0, logline4);
    refreshp();

    attron(COLOR_PAIR(C_WINDOW));

    mvprintw(12, 23, qsonrstr);

    if (no_rst) {
	mvaddstr(12, 44, "---");
	mvaddstr(12, 49, "---");
    } else {
	mvaddstr(12, 44, his_rst);
	mvaddstr(12, 49, my_rst);
    }

    sync();

    if ((rit == 1) && (trx_control == 1))
	outfreq = RESETRIT;

    block_part = 0;		/* unblock use partials */

    pthread_mutex_unlock(&disk_mutex);

    return (0);
}
Пример #27
0
/* draw one line to screen */
void drawline(file_t *file, int y)
{
	char buf[256];
	int i, len, x, in_select, in_comment, in_string;
	line_t *line;
	
	if(!(current >= 0 && file == files[current])
	|| y < file->scroll_y || y >= file->scroll_y + h-1)
	{
		/* not visible */
		return;
	}
	
	move(y - file->scroll_y + 1, 0);
	
	/* line number */
	if(show_linenumbers)
	{
		printw("%5d", y+1);
		attron(A_BOLD);
		addch('|');
		attroff(A_BOLD);
	}
	
	/* selection from begin of line */
	if(file->selected && y > file->sel_begin_y && y <= file->sel_end_y)
		in_select = 1;
	else
		in_select = 0;
	
	/* TODO: proper highlighting system */
	
	in_comment = 0;
	in_string = 0;
	
	line = &file->lines[y];
	
	len = 0;
	x = 0;
	for(i=0; i<line->len; i++)
	{
		if((x >= w-7 && show_linenumbers) || (x >= w-1 && !show_linenumbers))
		{
			/* line too long */
			buf[len++] = '$';
			x++;
			break;
		}
		
		if(file->selected && !in_select
		&& i == file->sel_begin_x && y == file->sel_begin_y)
		{
			/* selection begin */
			
			/* flush buffer */
			
			if(in_comment)
			{
				attron(A_BOLD);
				attron(COLOR_PAIR(7));
			}
			else if(in_string)
			{
				attron(A_BOLD);
				attron(COLOR_PAIR(6));
			}
			else
				attron(COLOR_PAIR(2));
			
			buf[len] = 0;
			addstr(buf);
			len = 0;
			
			if(in_string || in_comment)
				attroff(A_BOLD);
			
			in_select = 1;
		}
		
		if(in_select && i == file->sel_end_x && y == file->sel_end_y)
		{
			/* selection end */
			
			/* flush select buffer */
			
			attron(COLOR_PAIR(4));
			
			buf[len] = 0;
			addstr(buf);
			len = 0;
			
			in_select = 0;
		}
		
		if(c_highlight && !in_comment && !in_string
			&& !memcmp(&line->buf[i], "/*", 2))
		{
			i++;
			/* begin comment */
			
			if(!in_select)
			{
				/* flush buffer */
				
				attron(COLOR_PAIR(2));
				
				buf[len] = 0;
				addstr(buf);
				len = 0;
			}
			
			memcpy(&buf[len], "/*", 2);
			len += 2;
			x += 2;
			
			in_comment = 1;
		}
		else if(c_highlight && in_comment && !memcmp(&line->buf[i], "*/", 2))
		{
			i++;
			/* end comment */
			
			memcpy(&buf[len], "*/", 2);
			len += 2;
			x += 2;
			
			in_comment = 0;
			
			if(!in_select)
			{
				/* flush comment buffer */
				
				attron(A_BOLD);
				attron(COLOR_PAIR(7));
				
				buf[len] = 0;
				addstr(buf);
				len = 0;
				
				attroff(A_BOLD);
			}
		}
		else if(c_highlight && !in_comment && line->buf[i] == '"')
		{
			if(in_string)
			{
				/* string end */
				
				buf[len++] = '"';
				x++;
			}
			
			if(!in_select)
			{
				if(in_string)
				{
					/* flush string buffer */
					attron(A_BOLD);
					attron(COLOR_PAIR(6));
				}
				else
				{
					/* flush buffer */
					attron(COLOR_PAIR(2));
				}
				
				buf[len] = 0;
				addstr(buf);
				len = 0;
				
				if(in_string)
					attroff(A_BOLD);
			}
			
			in_string = !in_string;
			
			if(in_string)
			{
				/* string begin */
				
				buf[len++] = '"';
				x++;
			}
		}
		else if(c_highlight && (line->buf[i] == '(' || line->buf[i] == ')'
			|| line->buf[i] == '{' || line->buf[i] == '}'
			|| line->buf[i] == ';' || line->buf[i] == ',')
			&& !in_select && !in_comment && !in_string)
		{
			attron(COLOR_PAIR(2));
			
			/* flush line buffer */
			buf[len] = 0;
			addstr(buf);
			len = 0;
			
			attron(COLOR_PAIR(1));
			attron(A_BOLD);
			
			addch(line->buf[i]);
			x++;
			
			attroff(A_BOLD);
		}
		else if(c_highlight && isdigit(line->buf[i])
			&& !in_select && !in_comment && !in_string)
		{
			attron(COLOR_PAIR(2));
			
			/* flush line buffer */
			buf[len] = 0;
			addstr(buf);
			len = 0;
			
			attron(COLOR_PAIR(5));
			attron(A_BOLD);
			
			addch(line->buf[i]);
			x++;
			
			attroff(A_BOLD);
		}
		else if(line->buf[i] == '\t')
		{
			/* handle tab */
			int skip;
			if(tab_size)
				skip = (x / 4 + 1)*4 - x;
			else
				skip = (x / 8 + 1)*8 - x;
			memset(&buf[len], ' ', skip);
			len += skip;
			x += skip;
		}
		else
		{
			buf[len++] = line->buf[i];
			x++;
		}
	}
	
	/* flush buffer */
	if(in_select)
		attron(COLOR_PAIR(4));
	else if(in_comment)
	{
		attron(A_BOLD);
		attron(COLOR_PAIR(7));
	}
	else if(in_string)
	{
		attron(A_BOLD);
		attron(COLOR_PAIR(6));
	}
	else
		attron(COLOR_PAIR(2));
	
	buf[len] = 0;
	addstr(buf);
	
	/* color off */
	attroff(A_BOLD);
	attron(COLOR_PAIR(2));
	
	if((x < w-6 && show_linenumbers) || (x < w && !show_linenumbers))
		clrtoeol();
}
Пример #28
0
static int
dialog_create (pinentry_t pinentry, dialog_t dialog)
{
  int err = 0;
  int size_y;
  int size_x;
  int y;
  int x;
  int ypos;
  int xpos;
  int description_x = 0;
  int error_x = 0;
  char *description = NULL;
  char *error = NULL;
  char *prompt = NULL;

#define COPY_OUT(what)							\
  do									\
    if (pinentry->what)							\
      {									\
        what = pinentry_utf8_to_local (pinentry->lc_ctype,		\
				       pinentry->what);			\
        if (!what)							\
	  {								\
	    err = 1;							\
	    goto out;							\
	  }								\
      }									\
  while (0)
    
  COPY_OUT (description);
  COPY_OUT (error);
  COPY_OUT (prompt);

#define MAKE_BUTTON(which,default)					\
  do									\
    {									\
      char *new = NULL;							\
      if (pinentry->which)						\
        {								\
          int len = strlen (pinentry->which);				\
          new = malloc (len + 3);				       	\
	  if (!new)							\
	    {								\
	      err = 1;							\
	      goto out;							\
	    }								\
	  new[0] = '<';							\
	  memcpy (&new[1], pinentry->which, len);			\
          new[len + 1] = '>';						\
	  new[len + 2] = '\0';						\
        }								\
      dialog->which = pinentry_utf8_to_local (pinentry->lc_ctype,	\
					      new ? new : default);	\
      if (!dialog->which)						\
        {								\
	  err = 1;							\
	  goto out;							\
	}								\
    }									\
  while (0)

  MAKE_BUTTON (ok, STRING_OK);
  if (!pinentry->one_button)
    MAKE_BUTTON (cancel, STRING_CANCEL);
  else
    dialog->cancel = NULL;

  getmaxyx (stdscr, size_y, size_x);

  /* Check if all required lines fit on the screen.  */
  y = 1;		/* Top frame.  */
  if (description)
    {
      char *start = description;
      int len = 0;

      do
	{
	  collect_line (size_x - 4, &start, &len);
	  if (len > description_x)
	    description_x = len;
	  y++;
	}
      while (start[len - 1]);
      y++;
    }
      
  if (pinentry->pin)
    {
      if (error)
	{
	  char *p = error;
	  int err_x = 0;

	  while (*p)
	    {
	      if (*(p++) == '\n')
		{
		  if (err_x > error_x)
		    error_x = err_x;
		  y++;
		  err_x = 0;
		}
	      else
		err_x++;
	    }
	  if (err_x > error_x)
	    error_x = err_x;
	  y += 2;	/* Error message.  */
	}
      y += 2;		/* Pin entry field.  */
    }
  y += 2;		/* OK/Cancel and bottom frame.  */
  
  if (y > size_y)
    {
      err = 1;
      goto out;
    }

  /* Check if all required columns fit on the screen.  */
  x = 0;
  if (description)
    {
      int new_x = description_x;
      if (new_x > size_x - 4)
	new_x = size_x - 4;
      if (new_x > x)
	x = new_x;
    }
  if (pinentry->pin)
    {
#define MIN_PINENTRY_LENGTH 40
      int new_x;

      if (error)
	{
	  new_x = error_x;
	  if (new_x > size_x - 4)
	    new_x = size_x - 4;
	  if (new_x > x)
	    x = new_x;
	}

      new_x = MIN_PINENTRY_LENGTH;
      if (prompt)
	new_x += strlen (prompt) + 1;	/* One space after prompt.  */
      if (new_x > size_x - 4)
	new_x = size_x - 4;
      if (new_x > x)
	x = new_x;
    }
  /* We position the buttons after the first and second third of the
     width.  Account for rounding.  */
  if (x < 2 * strlen (dialog->ok))
    x = 2 * strlen (dialog->ok);
  if (dialog->cancel)
    if (x < 2 * strlen (dialog->cancel))
      x = 2 * strlen (dialog->cancel);

  /* Add the frame.  */
  x += 4;

  if (x > size_x)
    {
      err = 1;
      goto out;
    }

  dialog->pos = DIALOG_POS_NONE;
  dialog->pin = pinentry->pin;
  dialog->pin_max = pinentry->pin_len;
  dialog->pin_loc = 0;
  dialog->pin_len = 0;
  ypos = (size_y - y) / 2;
  xpos = (size_x - x) / 2;
  move (ypos, xpos);
  addch (ACS_ULCORNER);
  hline (0, x - 2);
  move (ypos, xpos + x - 1);
  addch (ACS_URCORNER);
  move (ypos + 1, xpos + x - 1);
  vline (0, y - 2);
  move (ypos + y - 1, xpos);
  addch (ACS_LLCORNER);
  hline (0, x - 2);
  move (ypos + y - 1, xpos + x - 1);
  addch (ACS_LRCORNER);
  ypos++;
  if (description)
    {
      char *start = description;
      int len = 0;

      do
	{
	  int i;

	  move (ypos, xpos);
	  addch (ACS_VLINE);
	  addch (' ');
	  collect_line (size_x - 4, &start, &len);
	  for (i = 0; i < len - 1; i++)
	    addch ((unsigned char) start[i]);
	  if (start[len - 1] && start[len - 1] != '\n')
	    addch ((unsigned char) start[len - 1]);
	  ypos++;
	}
      while (start[len - 1]);
      move (ypos, xpos);
      addch (ACS_VLINE);
      ypos++;
    }
  if (pinentry->pin)
    {
      int i;

      if (error)
	{
	  char *p = error;
	  i = 0;

	  while (*p)
	    {
	      move (ypos, xpos);
	      addch (ACS_VLINE);
	      addch (' ');
	      if (USE_COLORS && pinentry->color_so != PINENTRY_COLOR_NONE)
		{
		  attroff (COLOR_PAIR (1) | (pinentry->color_fg_bright ? A_BOLD : 0));
		  attron (COLOR_PAIR (2) | (pinentry->color_so_bright ? A_BOLD : 0));
		}
	      else
		standout ();
	      for (;*p && *p != '\n'; p++)
		if (i < x - 4)
		  {
		    i++;
		    addch ((unsigned char) *p);
		  }
	      if (USE_COLORS && pinentry->color_so != PINENTRY_COLOR_NONE)
		{
		  attroff (COLOR_PAIR (2) | (pinentry->color_so_bright ? A_BOLD : 0));
		  attron (COLOR_PAIR (1) | (pinentry->color_fg_bright ? A_BOLD : 0));
		}
	      else
		standend ();
	      if (*p == '\n')
		p++;
	      i = 0;
	      ypos++;
	    }
	  move (ypos, xpos);
	  addch (ACS_VLINE);
	  ypos++;
	}

      move (ypos, xpos);
      addch (ACS_VLINE);
      addch (' ');

      dialog->pin_y = ypos;
      dialog->pin_x = xpos + 2;
      dialog->pin_size = x - 4;
      if (prompt)
	{
	  char *p = prompt;
	  i = strlen (prompt);
	  if (i > x - 4 - MIN_PINENTRY_LENGTH)
	    i = x - 4 - MIN_PINENTRY_LENGTH;
	  dialog->pin_x += i + 1;
	  dialog->pin_size -= i + 1;
	  while (i-- > 0)
	    addch ((unsigned char) *(p++));
	  addch (' ');
	}
      for (i = 0; i < dialog->pin_size; i++)
	addch ('_');
      ypos++;
      move (ypos, xpos);
      addch (ACS_VLINE);
      ypos++;
    }
  move (ypos, xpos);
  addch (ACS_VLINE);

  if (dialog->cancel)
    {
      dialog->ok_y = ypos;
      /* Calculating the left edge of the left button, rounding down.  */
      dialog->ok_x = xpos + 2 + ((x - 4) / 2 - strlen (dialog->ok)) / 2;
      move (dialog->ok_y, dialog->ok_x);
      addstr (dialog->ok);

      dialog->cancel_y = ypos;
      /* Calculating the left edge of the right button, rounding up.  */
      dialog->cancel_x = xpos + x - 2 - ((x - 4) / 2 + strlen (dialog->cancel)) / 2;
      move (dialog->cancel_y, dialog->cancel_x);
      addstr (dialog->cancel);
    }
  else
    {
      dialog->ok_y = ypos;
      /* Calculating the left edge of the OK button, rounding down.  */
      dialog->ok_x = xpos + x / 2 - strlen (dialog->ok) / 2;
      move (dialog->ok_y, dialog->ok_x);
      addstr (dialog->ok);
    }

 out:
  if (description)
    free (description);
  if (error)
    free (error);
  if (prompt)
    free (prompt);
  return err;
}
Пример #29
0
void Graphics_Set_Draw_Color(Graphics *self)
{
	attroff(self->erase_colour_palate);
	attron(self->draw_colour_palate);
}
Пример #30
0
void print_grass(int y, int x){
	attron(COLOR_PAIR(2));
	mvaddch(y, x, ACS_BOARD);
	matrix[y - y1b][x - x1b] = 'g';
}