Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ** main.cpp for in /home/thepatriot/thepatriotsrepo/perso/codingclub
- **
- ** Made by Alexis Bertholom
- ** Login bertho_d
- ** Email <alexis.bertholom@epitech.eu>
- **
- ** Started on Tue Jan 27 14:13:06 2015 Alexis Bertholom
- // Last update Fri Jan 19 23:44:18 2018 Lucas
- */
- #include <unistd.h>
- #include <iostream>
- #include <algorithm>
- #include "SDLDisplay.hpp"
- #include "Input.hpp"
- #include "Colors.hpp"
- #include "RNG.hpp"
- bool RNG::_initialized = false;
- SDLDisplay display("mega morpion", 600, 600);
- void afficher_plateau();
- void gestion_curseur();
- void afficher_curseur();
- void valider_coup();
- int main()
- {
- /* Gestion de la fenêtre */
- /* Gestion des touches */
- Input input;
- // Les déclarations de variables se font ici
- bool choix_global = false;
- int X =0;
- int Y=0;
- int y=0;
- int x=0;
- int tab[3][3][3][3]={};
- int plein[3][3]={0};
- bool joueur_rouge = true;
- while (!(input.shouldExit()) && !(input.getKeyState(SDL_SCANCODE_ESCAPE)))
- {
- display.clearScreen();
- /***************************************************/
- afficher_plateau;
- gestion_curseur;
- if (input.getKeyStateOnce(SDL_SCANCODE_RETURN)) {
- valider_coup();
- /***************************************************/
- display.refreshScreen();
- input.flushEvents();
- }
- }
- void afficher_plateau
- {
- for(int i = 0; i < 3; i++){
- for(int k = 0; k < 3; k++){
- display.putRect (10 + i * 200,10 + k * 200,180,180, Colors::Blue);
- for(int r = 0; r < 3; r++){
- for(int n = 0; n < 3; n++){
- display.putRect (15 + 200 * i + 60 * r, 15 + 200 * k + 60 * n, 50,50, Colors :: Black);
- switch(tab[i][k][r][n]) {
- case 1 :
- display.putRect (15 + 200 * i + 60 * r, 15 + 200 * k + 60 * n, 50,50, Colors :: Red);
- break;
- case 2 :
- display.putRect (15 + 200 * i + 60 * r, 15 + 200 * k + 60 * n, 50,50, Colors :: Green);
- break;
- case 0 :
- //for debug
- break;
- }
- }
- }
- }
- }
- }
- void gestion_curseur
- {
- {
- if (input.getKeyStateOnce(SDL_SCANCODE_RIGHT))
- x=x+1;
- if (input.getKeyStateOnce(SDL_SCANCODE_LEFT))
- x=x-1;
- if (input.getKeyStateOnce(SDL_SCANCODE_UP))
- y--;
- if (input.getKeyStateOnce(SDL_SCANCODE_DOWN))
- y++;
- } // deplacement w. fleches
- if (choix_global) {
- display.putRect(0,0,600,5,Colors::Yellow);
- display.putRect(0,0,5,600,Colors::Yellow);
- display.putRect(0,595,600,5,Colors::Yellow);
- display.putRect(595,0,5,600,Colors::Yellow);
- if (x < 0) {
- x=2;
- X--;
- }
- if (x > 2){
- x=0;
- X++;
- }
- if (y < 0) {
- y=2;
- Y--;
- }
- if ( y > 2) {
- y = 0;
- Y++;
- }
- if ( X < 0)
- X=2;
- if (Y < 0)
- Y=2;
- if ( X > 2)
- X = 0;
- if (Y > 2)
- Y=0;
- }
- else {
- display.putRect(10 + 200 * X, 10 + 200 * Y, 180, 5, Colors::Yellow);
- display.putRect(10 + 200 * X, 10 + 200 * Y, 5, 180, Colors::Yellow);
- display.putRect(185 + 200 * X, 10 + 200 * Y, 5, 180, Colors::Yellow);
- display.putRect(10+200*X,185 + 200*Y,180,5,Colors::Yellow);
- if (x < 0)
- x=2;
- if (y<0)
- y=2;
- if (x>2)
- x=0;
- if(y>2)
- y=0;
- }
- afficher_curseur();
- }
- void afficher_curseur
- {
- display.putRect (25 + 200 * X + 60 * x, 37 + 200 * Y + 60 * y, 30,6, Colors :: Yellow);
- display.putRect (37 + 200 * X + 60 * x, 25 + 200 * Y + 60 * y, 6,30, Colors :: Yellow);
- if (joueur_rouge) {
- display.putRect (27 + 200 * X + 60 * x, 39 + 200 * Y + 60 * y, 26,2, Colors :: Red);
- display.putRect (39 + 200 * X + 60 * x, 27 + 200 * Y + 60 * y, 2,26, Colors :: Red);
- }
- else {
- display.putRect (27 + 200 * X + 60 * x, 39 + 200 * Y + 60 * y, 26,2, Colors :: Green);
- display.putRect (39 + 200 * X + 60 * x, 27 + 200 * Y + 60 * y, 2,26, Colors :: Green);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement