Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.67 KB | None | 0 0
  1. /*
  2. ** main.cpp for in /home/thepatriot/thepatriotsrepo/perso/codingclub
  3. **
  4. ** Made by Alexis Bertholom
  5. ** Login bertho_d
  6. ** Email <alexis.bertholom@epitech.eu>
  7. **
  8. ** Started on Tue Jan 27 14:13:06 2015 Alexis Bertholom
  9. // Last update Fri Jan 19 23:44:18 2018 Lucas
  10. */
  11.  
  12. #include <unistd.h>
  13. #include <iostream>
  14. #include <algorithm>
  15. #include "SDLDisplay.hpp"
  16. #include "Input.hpp"
  17. #include "Colors.hpp"
  18. #include "RNG.hpp"
  19. bool RNG::_initialized = false;
  20. SDLDisplay display("mega morpion", 600, 600);
  21.  
  22. void afficher_plateau();
  23. void gestion_curseur();
  24. void afficher_curseur();
  25. void valider_coup();
  26.  
  27.  
  28. int main()
  29. {
  30. /* Gestion de la fenêtre */
  31.  
  32. /* Gestion des touches */
  33. Input input;
  34.  
  35. // Les déclarations de variables se font ici
  36. bool choix_global = false;
  37. int X =0;
  38. int Y=0;
  39. int y=0;
  40. int x=0;
  41. int tab[3][3][3][3]={};
  42. int plein[3][3]={0};
  43. bool joueur_rouge = true;
  44.  
  45. while (!(input.shouldExit()) && !(input.getKeyState(SDL_SCANCODE_ESCAPE)))
  46. {
  47.  
  48. display.clearScreen();
  49. /***************************************************/
  50. afficher_plateau;
  51. gestion_curseur;
  52. if (input.getKeyStateOnce(SDL_SCANCODE_RETURN)) {
  53. valider_coup();
  54.  
  55.  
  56.  
  57. /***************************************************/
  58. display.refreshScreen();
  59. input.flushEvents();
  60.  
  61. }
  62. }
  63.  
  64.  
  65. void afficher_plateau
  66. {
  67. for(int i = 0; i < 3; i++){
  68.  
  69. for(int k = 0; k < 3; k++){
  70.  
  71. display.putRect (10 + i * 200,10 + k * 200,180,180, Colors::Blue);
  72.  
  73.  
  74. for(int r = 0; r < 3; r++){
  75.  
  76. for(int n = 0; n < 3; n++){
  77.  
  78. display.putRect (15 + 200 * i + 60 * r, 15 + 200 * k + 60 * n, 50,50, Colors :: Black);
  79.  
  80. switch(tab[i][k][r][n]) {
  81. case 1 :
  82. display.putRect (15 + 200 * i + 60 * r, 15 + 200 * k + 60 * n, 50,50, Colors :: Red);
  83. break;
  84. case 2 :
  85. display.putRect (15 + 200 * i + 60 * r, 15 + 200 * k + 60 * n, 50,50, Colors :: Green);
  86. break;
  87. case 0 :
  88. //for debug
  89. break;
  90.  
  91. }
  92. }
  93. }
  94. }
  95.  
  96. }
  97.  
  98.  
  99. }
  100.  
  101. void gestion_curseur
  102. {
  103. {
  104. if (input.getKeyStateOnce(SDL_SCANCODE_RIGHT))
  105. x=x+1;
  106. if (input.getKeyStateOnce(SDL_SCANCODE_LEFT))
  107. x=x-1;
  108. if (input.getKeyStateOnce(SDL_SCANCODE_UP))
  109. y--;
  110. if (input.getKeyStateOnce(SDL_SCANCODE_DOWN))
  111. y++;
  112. } // deplacement w. fleches
  113.  
  114. if (choix_global) {
  115. display.putRect(0,0,600,5,Colors::Yellow);
  116. display.putRect(0,0,5,600,Colors::Yellow);
  117. display.putRect(0,595,600,5,Colors::Yellow);
  118. display.putRect(595,0,5,600,Colors::Yellow);
  119. if (x < 0) {
  120. x=2;
  121. X--;
  122. }
  123. if (x > 2){
  124. x=0;
  125. X++;
  126. }
  127. if (y < 0) {
  128. y=2;
  129. Y--;
  130. }
  131. if ( y > 2) {
  132. y = 0;
  133. Y++;
  134. }
  135.  
  136. if ( X < 0)
  137. X=2;
  138.  
  139. if (Y < 0)
  140. Y=2;
  141.  
  142. if ( X > 2)
  143. X = 0;
  144.  
  145. if (Y > 2)
  146. Y=0;
  147.  
  148.  
  149. }
  150. else {
  151. display.putRect(10 + 200 * X, 10 + 200 * Y, 180, 5, Colors::Yellow);
  152. display.putRect(10 + 200 * X, 10 + 200 * Y, 5, 180, Colors::Yellow);
  153. display.putRect(185 + 200 * X, 10 + 200 * Y, 5, 180, Colors::Yellow);
  154. display.putRect(10+200*X,185 + 200*Y,180,5,Colors::Yellow);
  155. if (x < 0)
  156. x=2;
  157. if (y<0)
  158. y=2;
  159. if (x>2)
  160. x=0;
  161. if(y>2)
  162. y=0;
  163. }
  164. afficher_curseur();
  165. }
  166.  
  167. void afficher_curseur
  168. {
  169.  
  170. display.putRect (25 + 200 * X + 60 * x, 37 + 200 * Y + 60 * y, 30,6, Colors :: Yellow);
  171. display.putRect (37 + 200 * X + 60 * x, 25 + 200 * Y + 60 * y, 6,30, Colors :: Yellow);
  172. if (joueur_rouge) {
  173. display.putRect (27 + 200 * X + 60 * x, 39 + 200 * Y + 60 * y, 26,2, Colors :: Red);
  174. display.putRect (39 + 200 * X + 60 * x, 27 + 200 * Y + 60 * y, 2,26, Colors :: Red);
  175. }
  176. else {
  177. display.putRect (27 + 200 * X + 60 * x, 39 + 200 * Y + 60 * y, 26,2, Colors :: Green);
  178. display.putRect (39 + 200 * X + 60 * x, 27 + 200 * Y + 60 * y, 2,26, Colors :: Green);
  179. }
  180.  
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement