Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. void TIM3_IRQHandler() {
  2. char key = key_scan();
  3. char input;
  4. if (phase == 0) {
  5. char result = getchar_irq();
  6. if (my_turn == 'Y') {
  7. if (key != '\0') {
  8. putchar_irq('Y');
  9. pc12out();
  10. my_turn = 'N';
  11. }
  12. }
  13. if (result == 'Y') {
  14. my_turn = 'Y';
  15. }
  16. }
  17. //printf("Hello");
  18. if (phase == 1) {
  19. phase1(key);
  20. }
  21. else if (phase == 2) {
  22. if (key != '\0') {
  23. phase2(key);
  24. }
  25. }
  26. else if (phase == 3) {
  27. if (opponent_ready == 'Y') {
  28. if (my_turn == 'Y') {
  29. if (key != '\0')
  30. phase3_attack(key);
  31. }
  32. else if (my_turn == 'N') {
  33. // printf("hello" );
  34. /* while(counter < 4) {
  35. printf("hello2" );
  36. if((USART1->ISR & USART_ISR_RXNE) == USART_ISR_RXNE) {
  37. insert_echo_char(USART1->RDR & 0xff);
  38. counter++;
  39. }
  40. } */
  41. // if (counter == 4) {
  42. //printf("Hello1");
  43. //insert_echo_char(USART1->RDR & 0xff);
  44. input = getchar_irq();
  45. // putchar_irq(input);
  46. if ((input) >= 48 && (input) <= 57) {
  47. //putchar_irq(input);
  48. if (count < 2) {
  49. X[count] = input;
  50. }
  51. else {
  52. Y[count-2] = input;
  53. }
  54. count++;
  55.  
  56. X[2] = '\0';
  57. Y[2] = '\0';
  58. //printf("%c",X[0]);
  59. // printf("%c",X[1]);
  60. counter = 0;
  61. if (count >= 4) {
  62. int X_coordinates = atoi(X);
  63. int Y_coordinates = atoi(Y);
  64. printf("%d",X_coordinates);
  65. printf("%d",Y_coordinates);
  66. if (ships[X_coordinates][Y_coordinates] == 1) {
  67. putchar_irq('H');
  68. ships[X_coordinates][Y_coordinates] = 0;
  69. opp_hit++;
  70. }
  71. else {
  72. putchar_irq('M');
  73. }
  74. count = count % 4;
  75. if (opp_hit == 17) {
  76. phase = 4;
  77. }
  78. my_turn = 'Y';
  79. }
  80.  
  81.  
  82. // if RECEIVED coordinates
  83. // TRANSMIT HIT OR MISS (Did opponent hit or miss)
  84. // if HIT
  85. // opp_hit++;
  86. // UPDATE "your" screen
  87.  
  88. }
  89. }
  90. //}
  91. }
  92. }
  93. else {
  94. if (win == 'Y') {
  95. // DISPLAY WIN
  96. }
  97. else {
  98. // DISPLAY LOSE
  99. }
  100. }
  101.  
  102. ack_tim3();
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement