main.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #ifdef _WIN32
  2. // Windows builds require curses.h for the PDcurses library.
  3. # include <curses.h>
  4. #else
  5. // Unix builds require ncurses.h for the Ncurses library.
  6. # include <ncurses.h>
  7. #endif
  8. #include <stdlib.h>
  9. #include <time.h> /* For making a random seed */
  10. #include <string.h> /* For strcmp, to identify argv[1] */
  11. #include "intro.h" /* To launch intro */
  12. #include "pass.h" /* To launch pass */
  13. #include "wordParse.h" /* To read the file */
  14. int main(int argc, char * argv[]){
  15. if(argc > 1 && !strcmp(argv[1], "--help")){
  16. printf("Usage: %s [--DIFFICULTY]\n\n[--DIFFICULTY] is an optional argument"
  17. " that uses built in words instead\nof words specifed in the config"
  18. " file. Options are:\n\n"
  19. "--veryEasy,\t10 words, 5 letters per word (default)\n\n"
  20. "--easy,\t\t11 words, 7 letters per word\n\n"
  21. "--average,\t14 words, 9 letters per word\n\n"
  22. "--hard,\t\t7 words, 11 letters per word\n\n"
  23. "--veryHard,\t13 words, 12 letters per word\n\n"
  24. "If no difficulty is provided, this program will read input "
  25. "from the FalloutTerminal.cfg file. If this file cannot be found "
  26. "or the configuration is invalid, it will default to Very Easy."
  27. , argv[0]);
  28. exit(0);
  29. }
  30. // Open the config file
  31. FILE *fp = NULL;
  32. fp = fopen("FalloutTerminal.cfg", "r");
  33. // Check if a difficulty arg was given
  34. if(argc > 1){
  35. if(!strcmp(argv[1], "--veryEasy")) {
  36. setVeryEasy();
  37. }
  38. if(!strcmp(argv[1], "--easy")) {
  39. setEasy();
  40. }
  41. else if(!strcmp(argv[1], "--average")) {
  42. setAverage();
  43. }
  44. else if(!strcmp(argv[1], "--hard")) {
  45. setHard();
  46. }
  47. else if(!strcmp(argv[1], "--veryHard")) {
  48. setVeryHard();
  49. }
  50. else {
  51. printf("Invalid command. Type \"%s --help\" for usage and a list of commands.\n", argv[0]);
  52. exit(EXIT_FAILURE);
  53. }
  54. }
  55. // Otherwise, read the file for words
  56. else {
  57. readWordsFromFile(fp);
  58. }
  59. // Read what should be launch on completion/victory
  60. readLaunches(fp);
  61. // Gen a random seed
  62. srand ( (unsigned)time(NULL) );
  63. // Begin curses
  64. initscr();
  65. noecho();
  66. refresh();
  67. attron(A_BOLD);
  68. nodelay(stdscr, 1);
  69. // Check for color support. Start color if it exists.
  70. if(has_colors() == 1){
  71. start_color();
  72. init_pair(1,COLOR_GREEN,COLOR_BLACK);
  73. attron(COLOR_PAIR(1));
  74. }
  75. // Run intro
  76. intro();
  77. // Run pass
  78. pass();
  79. // Close the config file
  80. fclose(fp);
  81. return EXIT_SUCCESS;
  82. }