Exemplo n.º 1
0
void GameStateFirstTime::draw()
{
	// BIG HACK
	//
	// Instead of drawing, we actually query the user for
	// a profile name
	//
	// NEED to remove this
	// Are you kidding me?
	// Direct ncurses calls?

	clear();

	mvaddstr(0, 0,
	         "Hello, there!\n"
	         "It seems this is your first time running yetris.\n"
	         "\n"
	         "Please enter a profile name.\n"
	         "It'll store all your settings, scores and game statistics.");

	attron(A_REVERSE);
	mvaddstr(7, 0, "Profile Name:");
	attroff(A_REVERSE);

	mvaddstr(8, 0,  "default:");
	mvaddstr(8, 9, Utils::File::getUser().c_str());

	mvaddstr(10, 0,
	         "It may not contain the following characters:\n"
	         "\\ / . ^ ; # = ~");

	refresh();

	// Making everything "right"
	nocbreak();
	curs_set(1);
	echo();
	nodelay(stdscr, FALSE);

	char name[256];
	std::memset(name, '\0', 256);

	mvgetnstr(7, 15, name, 255);

	if (Profile::isNameValid(name))
	{
		if (strlen(name) == 0)
			this->name = Utils::File::getUser();
		else
			this->name = name;
	}

	// Returning to ncurses' "wrong" mode
	nodelay(stdscr, TRUE);
	noecho();
	curs_set(0);
	cbreak();
}
Exemplo n.º 2
0
int main(){

	char name[9];
	int r;

	initscr();

	mvaddstr(4,10,"user : [        ]");
	r = mvgetnstr(4,18,name,8);

	mvprintw(7,10,"-->%s",name);
	refresh();

	getch();

	endwin();

	return 0;
}
Exemplo n.º 3
0
int main()
{   
	initscr();
	keypad(stdscr,TRUE);
	int y=1;
	while(1){
		char line[100]={0};
		move(0,0);
		clrtoeol(); //清空第一行输入部分
		
		mvgetnstr(0,0,line,sizeof(line));
		mvprintw(y++,0,"%-*s",COLS,line);   //输出特定长度的字符串
		refresh();
		if(y==LINES)
			y=1;
	}
	endwin();
	
	return 0;
}
Exemplo n.º 4
0
int
load_unit_ffile(interface_struct *p_inter_data)
{
  int x, y;
  int oy = (LINES - (*p_inter_data).maxy * 1) / 2;
  int ox = (COLS - (*p_inter_data).maxx * 2) / 2;
  char filename[40];
  char units_folder[60] = "units/";
  char line[100];
  char whait_t = 0;
  int max_lenght = 0;
  int lines = 0;
  int lenght = 0;
  int line_n = 0;
  int flag = 0;
  FILE *fp;

  curs_set(1);
  echo();
  init_pair(4, COLOR_WHITE, COLOR_BLUE);
  attron(COLOR_PAIR(4));
  mvprintw((*p_inter_data).maxy + oy, ox, "Load from file:         ");
  mvgetnstr((*p_inter_data).maxy + oy, ox + 16 , filename, 39);
  strcat(units_folder, filename);
  if(fp = fopen(units_folder, "r")) {
    while (fgets(line, 100, fp)) {
      lenght = (strlen(line)) - 1;
      if(lenght > max_lenght)
	max_lenght = lenght;
      lines++;
    }
    (*p_inter_data).lp_data.loaded_pattern = (char**) malloc(lines * sizeof(char*));

    for (x = 0; x < lines; x++) {
      (*p_inter_data).lp_data.loaded_pattern[x] = (char*) malloc(max_lenght * sizeof(char));
      if((*p_inter_data).lp_data.loaded_pattern[x] == NULL)
	exit (EXIT_FAILURE);
    }

    for (y = 0; y < lines; y++)
      for (x = 0; x < max_lenght; x++)
	(*p_inter_data).lp_data.loaded_pattern[y][x] = 0;

    rewind(fp);

    line_n = 0;
    while (fgets(line, 100, fp)) {
      lenght = strlen(line) - 1;
      for (x = 0; x < lenght; x++)
	if (line[x] == 'X')
	  (*p_inter_data).lp_data.loaded_pattern[line_n][x] = 1; 
      line_n++;
    }

    (*p_inter_data).lp_data.maxx = max_lenght;
    (*p_inter_data).lp_data.maxy = lines;

    whait_t = 0;
    flag = 1;
  } else {
  mvprintw((*p_inter_data).maxy + oy, ox, "File not found!                 ");
  whait_t = 1;
  }

  attroff(COLOR_PAIR(4));
  refresh();
  curs_set(0);
  sleep(whait_t);
  noecho();
  return flag;
}
Exemplo n.º 5
0
void login(){

    char name[20];
    char pass[20];


    int a = 0; // Alert
    int o = 0; // Dezactive while


    while ( o < 1 ) {

        if ( a != 3){ // For block screen

            wclear(stdscr);
            ramka(COLOR_WHITE, COLOR_CYAN,0);// Load ramka
            ramka2(COLOR_WHITE, COLOR_CYAN,0);// Load ramka
            boxinfo("Login panel.",13,5,20,COLOR_WHITE,COLOR_BLUE); // Load box info
            smallbox ("Login: "******"Login panel.",13,5,20,COLOR_WHITE,COLOR_BLUE);
                smallbox ("Login: "******"%s",name);

                attroff( COLOR_PAIR( 2 ) | A_BOLD );

                smallbox ("Password: "******"Logged in as: ",10,17,20,COLOR_WHITE,COLOR_GREEN); // Load box
                        start_color();
                        attron( COLOR_PAIR( 2 ) );
                        init_pair( 2, COLOR_WHITE, COLOR_GREEN );

                            mvprintw(19,44,name);

                        attroff( COLOR_PAIR( 2 ) );
                        wrefresh(stdscr);

                        Sleep(2000);
                        curs_set(1);
                        o = 1;

                    } else { // Wrong password

                        curs_set(0);
                        boxinfo ("You have entered a wrong password!",5,17,20,COLOR_WHITE,COLOR_RED);
                        wrefresh(stdscr);
                        Sleep(1000);
                        curs_set(1);
                        a++;
            }

            } else { // Wrong login

                curs_set(0);
                ramka(COLOR_WHITE, COLOR_CYAN,0);
                ramka2(COLOR_WHITE, COLOR_CYAN,0);// Load ramka
                boxinfo("Login panel.",13,5,20,COLOR_WHITE,COLOR_BLUE);
                smallbox ("Login: "******"%s",name);

                attroff( COLOR_PAIR( 2 ) | A_BOLD );

                boxinfo ("There is no such user.",10,17,20,COLOR_WHITE,COLOR_RED);
                wrefresh(stdscr);
                Sleep(1000);
                curs_set(1);
                a++;

            }
        } else { // Block screen with timer

            curs_set(0);
            wclear(stdscr);
            ramka(COLOR_WHITE, COLOR_CYAN,0);
            ramka2(COLOR_WHITE, COLOR_CYAN,0);// Load ramka
            boxinfo("Limited access to:",13,5,19,COLOR_WHITE,COLOR_RED);

            int time = 10; // wait time in second

            while ( time >= 0 ){

                boxinfo("",20,12,21,COLOR_YELLOW,COLOR_RED);

                start_color();
                attron( COLOR_PAIR( 2 ));
                init_pair( 2, COLOR_WHITE, COLOR_RED );

                mvprintw(14,38,"%d",time);
                printw(" second.");
                wrefresh(stdscr);
                time = time - 1;
                Sleep(1000);

            }

            attroff( COLOR_PAIR( 2 ));

            curs_set(1);
            a = 0;
            o = 0;

        }
    }
}
Exemplo n.º 6
0
// A function to create the "create new event" page.
// This function is the most crucial part in the program which is handling user inputs/data
void create_new_event(bool edit, int z_index ) {
	// This will enable the input to be shown to the user when type.
	resize_term(40, 80);
	echo();

	// Variables
	char rawday, rawname, rawloc, rawhour, rawminute;	// Raw variables used for pdcurses function
	int confirmation;
	bool eventloop = false;									// Indicator for the loop
	int n_day, n_hour, n_minute;							// Day variable which is to be selected by the user

	// Loop until get a data to be saved in data object
	while (eventloop == false) {
		// Empty the console, add titlebar and redraw all.
		erase();
		titlebar();
		refresh();
		raw();

		attron(COLOR_PAIR(3));
		if (edit == true) {
			mvprintw(2, 1, "Edit Event");
			mvprintw(3, 1, "----------");
		}
		else {
			mvprintw(2, 1, "Create New Event");
			mvprintw(3, 1, "----------------");
		}

		mvprintw(20, 1, "Date\t\t:");
		mvprintw(22, 1, "Time\t\t:");
		mvprintw(24, 1, "Event name\t:");
		mvprintw(26, 1, "Location\t:");
		//mvprintw(28, 1, "Description\t:");
		
		// Disabled due to BUG002
		// A small window for description to fit in the text in nice allignment.
		/*WINDOW *wdesc;
		wdesc = newwin(3, 60, 28, 18);
		wattron(wdesc, COLOR_PAIR(3));*/

		// Show calendar, without any inputs
		mvprintw(4, 36, "Calendar");
		show_calendar(false, 14, 6);

		// Show status window (used to deliver message to the user about error, etc.)
		statuswin();

		// Update text in status window
		update_status("Please select the day for the event...\n\nTo go back, press ESC and ENTER",6);
		//refresh();

		// Do this loop until the program obtained a valid day

		do {
			mvhline(20, 18, ' ', 3);											// Clear a small portion of the console
			mvprintw(20, 21, "%s %i", mon_name(selected_mon), selected_year);	// Print the month and year
			mvgetnstr(20, 18, &rawday, 2);										// User input of the day
			if (rawday == 27) menu();												// If user pressed esc and enter, the program will go back to main menu
			n_day = atoi(&rawday);
			//n_day = day;														// A C-function to convert char * to int
			if (n_day == 0 || n_day > max_day_in_month) { update_status("Invalid day. Please enter a valid DAY in the selected month.\n\nTo go back, press ESC and ENTER.",5); }			// Inform user if the day not valid
			refresh();															// Redraw
		} while (n_day == 0 || n_day > max_day_in_month);						// Check if the day valid or not

		// Got a nice and valid n_day and print again to the screen.
		mvhline(20, 18, ' ', 60);												// Refresh the line
		mvprintw(20, 18, "%i %s %i", n_day, mon_name(selected_mon), selected_year);

		// Update to the current status.
		update_status("Please enter the hour in 24 hours...\nIf you enter some string, the result will be 0.", 6);

		// A loop that handle the time input. Runs loop until it gets the valid time.
		do {

			mvhline(22, 18, ' ', 6);											// Clear the line
			mvgetnstr(22, 18, &rawhour, 2);										// Get hour from user
			if (rawhour == 27) menu();											// If user input is ESC then go back to menu
			n_hour = atoi(&rawhour);											// Convert from char to int
			if ( !(n_hour >= 0 && n_hour < 24) ) {								// Check for valid hour
				update_status("Invalid hour. Enter a number in between 0-23. Please try again...", 5);
				continue;
			}
			else {
				mvprintw(22, 20, ":");
				update_status("Please enter the minute...\nIf you enter some string, the result will be 0.", 6);
				do {
					mvhline(22, 21, ' ', 3);
					mvgetnstr(22, 21, &rawminute, 2);
					if (rawminute == 27) menu();
					n_minute = atoi(&rawminute);								// Convert from char to int
					if (!(n_minute >= 0 && n_minute < 60)) {					// Check for valid minutes
						update_status("Invalid minute. Type a number in between 0-59. Please try again...", 5);
						continue;
					}
					else break;
				} while (1);
				break;
			}
		} while (1);

		// Print the time nicely.
		mvhline(22, 18, ' ', 6);
		formatted_time(22, 18, n_hour, n_minute);		// Print time in formatted form xx:yy

		// Update the status
		update_status("Now fill the name, location and description of the event.");

		// Get event name, location and description		// BUG001
		mvgetnstr(24, 18, &rawname, 28);				// First program bug detected here (Read below for more)
		data.save_name(&rawname);						// This function is used to copy rawname char * to another variable in normal char type. It copy the data to a more reliable variable.
														// This is because to prevent memory leak or maybe something else that causes the data in other the pointer (this is bad due to it affect other variable as well) overwritten by the typed data. Approximate more than 11 characters will cause the memory leak -- TESTED)
		mvgetnstr(26, 18, &rawloc, 28);					// Also, to prevent this bug, this function data.save_*** is called right after the user input the data.
		data.save_loc(&rawloc);							// This problem maybe related to the pdcurses library bug that cause the memory leak which affect other variables too.

		//mvwgetnstr(wdesc, 0, 0, &rawdesc, 28);		// BUG002
		//data.save_desc(&rawdesc);						// The program will crash when number of characters more than 28 chars. The cause still unknown. To fix whether to create another custom function to handle input (which is long) or decrease the numbers of characters (which is the quickest way to solve).

		refresh();

		// Clear status
		werase(wstatus);
		wrefresh(wstatus);

		// User confirmation
		mvprintw(32, 1, "Are you sure? (Y/N): ");
		refresh();

		// A loop to check only y/Y/n/N are allowed as a user input
		while (1) {
			mvhline(32, 22, ' ', 1);
			confirmation = getch();
			if (confirmation == 780 || confirmation == 110 || confirmation == 121 || confirmation == 891) { break; }
		}

		// If user type y/Y, the the loop ends
		if (confirmation == 121 || confirmation == 891){
			eventloop = true;								// To ensure that this will break the loop and will not continue anymore
			data.day = n_day;								// Save user inputs
			data.year = selected_year;
			data.nmon = selected_mon;

			// LAB-2
			data.hour = n_hour;
			data.min = n_minute;

			if (edit == true) {
				myVector.erase(myVector.begin() + z_index);
				myVector.insert(myVector.begin() + z_index, data);
				list_events();
			}
			else {
				myVector.push_back(data);
				event_saved = true;								// Tells the program about the saved data
				break;
			}
		}
	}

	if (edit == false) menu();
}