print.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //
  2. // File: print.c
  3. // print.c handles printing of pre-game strings
  4. // @author Josh Bicking <josh1147582>
  5. // // // // // // // // // // // // // // // // // // // // // // //
  6. #define _BSD_SOURCE /* for unistd.h */
  7. #ifdef _WIN32
  8. # include <Windows.h>
  9. # include <curses.h>
  10. # define SLEEP(delay) Sleep(delay/1000)
  11. // Unix builds require ncurses.h for the Ncurses library.
  12. // Unix also requires unistd.h for usleep(microseconds).
  13. // usleep/1000 = Sleep
  14. #else
  15. # include <ncurses.h>
  16. # include <unistd.h>
  17. # define SLEEP(delay) usleep(delay)
  18. #endif
  19. #include <stdlib.h>
  20. #include <time.h>
  21. #include "print.h"
  22. #include "pass.h"
  23. void slowPrint(char arr[], int size, int line){
  24. for(int i=0; i<size; i++){
  25. /* Print the current character in the current position. */
  26. mvprintw(line,i,"%c",arr[i]);
  27. /* Move the cursor to the next position */
  28. move(line, i+1);
  29. refresh();
  30. /* If any keyboard input was recieved, go directly to pass(), otherwise continue */
  31. if(kbhit()){
  32. pass();
  33. }
  34. SLEEP(20000);
  35. }
  36. return;
  37. }
  38. void slowType(char arr[], int size, int line){
  39. for(int i=0; i<size; i++){
  40. mvprintw(line,i+1,"%c",arr[i]);
  41. move(line, i+2);
  42. refresh();
  43. if(kbhit()){
  44. pass();
  45. }
  46. SLEEP(70000);
  47. }
  48. return;
  49. }
  50. void passPrint(char arr[], int size, int line){
  51. int i;
  52. for(i=0; i<size; i++){
  53. mvprintw(line,i,"%c",arr[i]);
  54. move(line, i+1);
  55. refresh();
  56. SLEEP(20000);
  57. }
  58. }
  59. int kbhit(){
  60. /* Get the current char. */
  61. int ch = getch();
  62. /* Returns true if a key has been hit. False if it hasn't. */
  63. if (ch != ERR) {
  64. return 1;
  65. } else {
  66. return 0;
  67. }
  68. }
  69. void printChoices(int hex, char arr[], int line, int offset){
  70. mvprintw(line,offset,"0x%X", hex);
  71. for(int i=0; i<12; i++)
  72. mvprintw(line,7+offset+i,"%c",arr[i]);
  73. move(line, 20+offset);
  74. refresh();
  75. SLEEP(30000);
  76. }
  77. // end