print.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. #else
  12. # include <ncurses.h>
  13. # include <unistd.h>
  14. # define SLEEP(delay) usleep(delay)
  15. #endif
  16. #include <stdlib.h>
  17. #include <time.h>
  18. #include <string.h>
  19. #include "print.h"
  20. #include "pass.h"
  21. void slowPrint(char arr[], int line){
  22. for(int i=0; (unsigned long)i<strlen(arr); i++){
  23. /* Print the current character in the current position. */
  24. mvprintw(line,i,"%c",arr[i]);
  25. /* Move the cursor to the next position */
  26. move(line, i+1);
  27. refresh();
  28. /* If any keyboard input was recieved, go directly to pass(), otherwise continue */
  29. if(kbhit()){
  30. pass();
  31. }
  32. SLEEP(20000);
  33. }
  34. return;
  35. }
  36. void slowType(char arr[], int line){
  37. for(int i=0; (unsigned long)i<strlen(arr); i++){
  38. mvprintw(line,i+1,"%c",arr[i]);
  39. move(line, i+2);
  40. refresh();
  41. if(kbhit()){
  42. pass();
  43. }
  44. SLEEP(70000);
  45. }
  46. return;
  47. }
  48. void passPrint(char arr[], int line){
  49. for(int i=0; (unsigned long)i<strlen(arr); i++){
  50. mvprintw(line,i,"%c",arr[i]);
  51. move(line, i+1);
  52. refresh();
  53. SLEEP(20000);
  54. }
  55. }
  56. int kbhit(){
  57. /* Get the current char. */
  58. int ch = getch();
  59. /* Returns true if a key has been hit. False if it hasn't. */
  60. if (ch != ERR) {
  61. return 1;
  62. } else {
  63. return 0;
  64. }
  65. }
  66. void printChoices(int hex, char arr[], int line, int offset){
  67. mvprintw(line,offset,"0x%X", hex);
  68. for(int i=0; i<12; i++)
  69. mvprintw(line,7+offset+i,"%c",arr[i]);
  70. move(line, 20+offset);
  71. refresh();
  72. SLEEP(30000);
  73. }
  74. // end