Project showcase

TIC TAC DUINO © LGPL

arduino tic-tac-toe. mini game

  • 1,415 views
  • 1 comment
  • 3 respects

Components and supplies

Apps and online services

About this project

I bought a tft screen for arduino, looking for projects. I found many that did not work with the driver of my tft screen. including the game of tic-tac-toe .. I gave myself the task of making my own game from 0 and this is the result of a couple of days of work .. the game works with the 7783 driver. I do not think there is problem other than working with other drivers.

español:

adquirí una pantalla tft para arduino, buscando proyectos. encontre muchos que no funcionaron con el driver de mi pantalla tft. entre ellos el juego de tic-tac-toe .. me di a la tarea de hacer mi propio juego desde 0 y este es el resultado de un par de dias de trabajo.. el juego funciona con el driver 7783. no creo que haya problema àra que trabaje con otros drivers.

Code

TICTACDUINOArduino
//==============================================
//======= CODIGO X MAURICIO BARUCH CHAVEZ ======
//==============================================
//============ INCLUDES  =======================
#include "TFTLCD.h"
#include "TouchScreen.h"
//==============================================
//======= configuracion ========================
//==============================================
#define YP A2
#define XM A1
#define YM 6
#define XP 7
//==============================================
#define TS_MINX 150
#define TS_MINY 120
#define TS_MAXX 920
#define TS_MAXY 940
//==============================================
#define MINPRESSURE 10
#define MAXPRESSURE 1000
//============ COLORES =========================
#define BLACK           0x0000
#define BLUE            0x001F
#define RED             0xF800
#define GREEN           0x07E0
#define CYAN            0x07FF
#define MAGENTA         0xF81F
#define YELLOW          0xFFE0
#define WHITE           0xFFFF
#define MARINO          0x000F      /*   0,   0, 128 */
#define VERDE_O         0x03E0      /*   0, 128,   0 */
#define AZUL_O          0x03EF      /*   0, 128, 128 */
#define Maroon          0x7800      /* 128,   0,   0 */
#define MORADO          0x780F      /* 128,   0, 128 */
#define Olive           0x7BE0      /* 128, 128,   0 */
#define GRISCLARO       0xC618      /* 192, 192, 192 */
#define GRIS            0x7BEF      /* 128, 128, 128 */
#define NARANJA         0xFD20      /* 255, 165,   0 */
#define VERDE_AM        0xAFE5      /* 173, 255,  47 */
#define ROSA            0xF81F
//============ OBJETOS   =======================
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 600);
//==============================================
#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4
TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);

//==============================================

//=======================================
int currentcolor;
int x, y;
int turno = 0;
int RESET = 0;
int game  = 0;
int mensaje = 0;
int mensaje2 = 0;
int tablero = 0;
int juego   = 0;

//=======================================
int L11 = 0, L12 = 0, L13 = 0;
int L21 = 0, L22 = 0, L23 = 0;
int L31 = 0, L32 = 0, L33 = 0;
//=======================================
#define LIN1 55
#define LIN2 120
#define LIN3 185
#define UNO 130
#define DOS 196
#define TRES 265
#define DIAM 24
#define BOTON 66
#define TEXTCOLOR WHITE
#define colorP1  GREEN
#define colorP2  VERDE_O
//==============================================
//============ SUB_RUTINAS VOID ================
//==============================================
void softReset(){
//asm volatile ("  jmp 100");
turno = 0;
RESET = 0;
game  = 0;
mensaje = 0;
mensaje2 = 0;
tablero = 0;
juego   = 0;
//=======================================
L11 = 0, L12 = 0, L13 = 0;
L21 = 0, L22 = 0, L23 = 0;
L31 = 0, L32 = 0, L33 = 0;

   tft.fillRoundRect(86,10,230,228,14,BLACK);
   tft.drawRoundRect(86,10,224,218,14,VERDE_O); 
     tft.drawString(95,40,"<- 2 PLAYER",WHITE,2);
  tft.drawString(95,110,"<- 1 PLAYER",WHITE,2);
RESET=0;

 loop();
}
//== 1 =========================================
void turno2() 
{
 if (juego==2){
    if (turno == 1){delay(10);turno = 0;
  
  tft.drawString(25,180,"TURNO",VERDE_O,1);
  tft.drawString(20,200,"AZUL",VERDE_O,1);
  delay(300);
  tft.drawString(25,180,"TURNO",WHITE,1);
  tft.drawString(20,200,"ARDUINO",WHITE,1);}
 
  else if (turno == 0){delay(10); turno = 1;
  tft.drawString(25,180,"TURNO",VERDE_O,1);
  tft.drawString(20,200,"ARDUINO",VERDE_O,1);
  delay(300);
  tft.drawString(25,180,"TURNO",WHITE,1);
  tft.drawString(20,200,"AZUL",WHITE,1);}
  
  }
if (juego==1){
  
  if (turno == 0){delay(10);turno = 1;
  
  tft.drawString(15,180,"TURNO",VERDE_O,1);
  tft.drawString(15,200,"AZUL",VERDE_O,1);
  delay(300);
  tft.drawString(15,180,"TURNO",WHITE,1);
  tft.drawString(15,200,"ROJO",WHITE,1);}
 
  else if (turno == 1){delay(10); turno = 0;
  tft.drawString(15,180,"TURNO",VERDE_O,1);
  tft.drawString(15,200,"ROJO",VERDE_O,1);
  delay(300);
  tft.drawString(15,180,"TURNO",WHITE,1);
  tft.drawString(15,200,"AZUL",WHITE,1);}
}
}
//== 2 =========================================
void ganaRojo () 
{
delay(4000);
tft.drawHorizontalLine(98,88,200,BLACK);
tft.drawHorizontalLine(98,154,200,BLACK);
tft.drawVerticalLine(164,18,200,BLACK);
tft.drawVerticalLine(230,18,200,BLACK);
tft.fillRoundRect(86,10,224,218,14,BLACK);
tft.drawRoundRect(86,10,224,218,14,VERDE_O);  
tft.drawString(120,50,"  GANA",WHITE,3);
tft.drawString(120,100,"ARDUINO",WHITE,3);
L11 = 1; 
L12 = 1; 
L13 = 1;
L21 = 1; 
L22 = 1; 
L23 = 1;
L31 = 1; 
L32 = 1; 
L33 = 1;
delay(3000);
RESET=1;
softReset();
}
//== 3 =========================================
void ganaVerde () { 
delay(4000);
tft.drawHorizontalLine(98,88,200,BLACK);
tft.drawHorizontalLine(98,154,200,BLACK);
tft.drawVerticalLine(164,18,200,BLACK);
tft.drawVerticalLine(230,18,200,BLACK);
tft.fillRoundRect(86,10,224,218,14,BLACK);
tft.drawRoundRect(86,10,224,218,14,VERDE_O);  
tft.drawString(120,50,"  GANA",WHITE,3);
tft.drawString(120,100,"PLAYER 2",WHITE,3);
L11 = 1; 
L12 = 1; 
L13 = 1;
L21 = 1; 
L22 = 1; 
L23 = 1;
L31 = 1; 
L32 = 1; 
L33 = 1;
delay(3000);
RESET=1;
softReset();
}
//== 3 =========================================
//== 4 =========================================
//=========RUTINA DIBUJA ARDUINO===============

void ARDU11(){ tft.fillCircle(UNO,LIN1,DIAM,VERDE_O); L11=4; turno2();
tft.drawString(UNO-17,LIN1-4,"- +",WHITE,2);
tft.drawCircle(UNO-11,LIN1+2,11,WHITE);
tft.drawCircle(UNO-11,LIN1+2,10,WHITE);
tft.drawCircle(UNO+11,LIN1+2,11,WHITE);
tft.drawCircle(UNO+11,LIN1+2,10,WHITE); 

}
void ARDU12(){ tft.fillCircle(DOS,LIN1,DIAM,VERDE_O); L12=4; turno2();
tft.drawString(DOS-17,LIN1-4,"- +",WHITE,2);
tft.drawCircle(DOS-11,LIN1+2,11,WHITE);
tft.drawCircle(DOS-11,LIN1+2,10,WHITE);
tft.drawCircle(DOS+11,LIN1+2,11,WHITE);
tft.drawCircle(DOS+11,LIN1+2,10,WHITE); 

}

void ARDU13(){ tft.fillCircle(TRES,LIN1,DIAM,VERDE_O); L13=4; turno2();
tft.drawString(TRES-17,LIN1-4,"- +",WHITE,2);
tft.drawCircle(TRES-11,LIN1+2,11,WHITE);
tft.drawCircle(TRES-11,LIN1+2,10,WHITE);
tft.drawCircle(TRES+11,LIN1+2,11,WHITE);
tft.drawCircle(TRES+11,LIN1+2,10,WHITE); 
}

void ARDU21(){ tft.fillCircle(UNO,LIN2,DIAM,VERDE_O); L21=4; turno2();
tft.drawString(UNO-17,LIN2-4,"- +",WHITE,2);
tft.drawCircle(UNO-11,LIN2+2,11,WHITE);
tft.drawCircle(UNO-11,LIN2+2,10,WHITE);
tft.drawCircle(UNO+11,LIN2+2,11,WHITE);
tft.drawCircle(UNO+11,LIN2+2,10,WHITE); 
}
void ARDU22(){ tft.fillCircle(DOS,LIN2,DIAM,VERDE_O); L22=4; turno2();
tft.drawString(DOS-17,LIN2-4,"- +",WHITE,2);
tft.drawCircle(DOS-11,LIN2+2,11,WHITE);
tft.drawCircle(DOS-11,LIN2+2,10,WHITE);
tft.drawCircle(DOS+11,LIN2+2,11,WHITE);
tft.drawCircle(DOS+11,LIN2+2,10,WHITE); 
}
void ARDU23(){ tft.fillCircle(TRES,LIN2,DIAM,VERDE_O);L23=4; turno2();
tft.drawString(TRES-17,LIN2-4,"- +",WHITE,2);
tft.drawCircle(TRES-11,LIN2+2,11,WHITE);
tft.drawCircle(TRES-11,LIN2+2,10,WHITE);
tft.drawCircle(TRES+11,LIN2+2,11,WHITE);
tft.drawCircle(TRES+11,LIN2+2,10,WHITE);
}

void ARDU31(){ tft.fillCircle(UNO,LIN3,DIAM,VERDE_O); L31=4; turno2();
tft.drawString(UNO-17,LIN3-4,"- +",WHITE,2);
tft.drawCircle(UNO-11,LIN3+2,11,WHITE);
tft.drawCircle(UNO-11,LIN3+2,10,WHITE);
tft.drawCircle(UNO+11,LIN3+2,11,WHITE);
tft.drawCircle(UNO+11,LIN3+2,10,WHITE);
}


void ARDU32(){ tft.fillCircle(DOS,LIN3,DIAM,VERDE_O); L32=4; turno2();
tft.drawString(DOS-17,LIN3-4,"- +",WHITE,2);
tft.drawCircle(DOS-11,LIN3+2,11,WHITE);
tft.drawCircle(DOS-11,LIN3+2,10,WHITE);
tft.drawCircle(DOS+11,LIN3+2,11,WHITE);
tft.drawCircle(DOS+11,LIN3+2,10,WHITE); }

void ARDU33(){tft.fillCircle(TRES,LIN3,DIAM,VERDE_O); L33=4; turno2();
tft.drawString(TRES-17,LIN3-4,"- +",WHITE,2);
tft.drawCircle(TRES-11,LIN3+2,11,WHITE);
tft.drawCircle(TRES-11,LIN3+2,10,WHITE);
tft.drawCircle(TRES+11,LIN3+2,11,WHITE);
tft.drawCircle(TRES+11,LIN3+2,10,WHITE);
}

//== 5 ====RUTINA DIBUJA CIRCULOS===============

void RL11(){ tft.fillCircle(UNO,LIN1,DIAM,RED); L11=4; turno2();}
void RL12(){ tft.fillCircle(DOS,LIN1,DIAM,RED); L12=4; turno2();}
void RL13(){ tft.fillCircle(TRES,LIN1,DIAM,RED); L13=4; turno2();}

void RL21(){ tft.fillCircle(UNO,LIN2,DIAM,RED); L21=4; turno2();}
void RL22(){ tft.fillCircle(DOS,LIN2,DIAM,RED); L22=4; turno2();}
void RL23(){ tft.fillCircle(TRES,LIN2,DIAM,RED);L23=4; turno2();}

void RL31(){ tft.fillCircle(UNO,LIN3,DIAM,RED); L31=4; turno2();}
void RL32(){ tft.fillCircle(DOS,LIN3,DIAM,RED); L32=4; turno2();}
void RL33(){tft.fillCircle(TRES,LIN3,DIAM,RED); L33=4; turno2();}
//---------------------------------------------------------------------------
void VL11(){ tft.fillCircle(UNO,LIN1,DIAM,BLUE); L11=3; turno2();}
void VL12(){ tft.fillCircle(DOS,LIN1,DIAM,BLUE); L12=3; turno2();}
void VL13(){ tft.fillCircle(TRES,LIN1,DIAM,BLUE); L13=3; turno2();}

void VL21(){ tft.fillCircle(UNO,LIN2,DIAM,BLUE); L21=3; turno2();}
void VL22(){ tft.fillCircle(DOS,LIN2,DIAM,BLUE); L22=3; turno2();}
void VL23(){ tft.fillCircle(TRES,LIN2,DIAM,BLUE);L23=3; turno2();}

void VL31(){ tft.fillCircle(UNO,LIN3,DIAM,BLUE); L31=3; turno2();}
void VL32(){ tft.fillCircle(DOS,LIN3,DIAM,BLUE); L32=3; turno2();}
void VL33(){tft.fillCircle(TRES,LIN3,DIAM,BLUE); L33=3; turno2();}

//== 6 ============ SELECTOR =============================
void selector(){

if (x > 10 && x < 66 && y >  10 && y < 66)     //H
{game=1;mensaje=1;}

if (x > 76 && x < 142 && y >  10 && y < 66)     //H
{ game=1;mensaje=2;}

//if (x > 152 && x < 218 && y >  10 && y < 66)     //H
//{ tft.drawString(200,100,"H1",YELLOW,5);}
 
  }
void juego1(){
//=========================================================================================  
//==========  BOTONERIA OK =================================================================  
//=========================================================================================   

  
if (turno== 1){
  
      if (x > 0 && x < 88 && y >  98 && y < 164)     // BOTON 11 //OK
      { if (L11 == 0) {RL11(); tft.drawString(UNO-10,LIN1-5,"P2",TEXTCOLOR,2);} }

     else if (x > 0 && x < 88 && y > 164 && y < 230)     // BOTON 11 //OK
      { if (L12 == 0) {RL12(); tft.drawString(DOS-10,LIN1-5,"P2",TEXTCOLOR,2);}}

        else if (x > 0 && x < 88 && y > 230 && y < 296)     // BOTON 11 //OK
      { if (L13 == 0) {RL13(); tft.drawString(TRES-10,LIN1-5,"P2",TEXTCOLOR,2);}}
//-----------------------------------------------------------------------------------------

     else if (x > 88 && x < 154 && y >  98 && y < 164)     // BOTON 11 //OK
      { if (L21 == 0) {RL21(); tft.drawString(UNO-10,LIN2-5,"P2",TEXTCOLOR,2);}}

     else if (x > 88 && x < 154 && y > 164 && y < 230)     // BOTON 11 //OK
      { if (L22 == 0) {RL22(); tft.drawString(DOS-10,LIN2-5,"P2",TEXTCOLOR,2);}}

      else if (x > 88 && x < 154 && y > 230 && y < 296)     // BOTON 11 //OK
      { if (L23 == 0) {RL23(); tft.drawString(TRES-10,LIN2-5,"P2",TEXTCOLOR,2);}}

//-----------------------------------------------------------------------------------------

      else if (x > 154 && x < 220 && y >  98 && y < 164)     // BOTON 11 //OK
      { if (L31 == 0) {RL31(); tft.drawString(UNO-10,LIN3-5,"P2",TEXTCOLOR,2);}}

      else if (x > 154 && x < 220 && y > 164 && y < 230)     // BOTON 11 //OK
      { if (L32 == 0) {RL32(); tft.drawString(DOS-10,LIN3-5,"P2",TEXTCOLOR,2);}}

      else if (x > 154 && x < 220 && y > 230 && y < 296)     // BOTON 11 //OK
      { if (L33 == 0) {RL33(); tft.drawString(TRES-10,LIN3-5,"P2",TEXTCOLOR,2);}}
}

//=========================================================================================  
//==========  BOTONERIA OK =================================================================  
//=========================================================================================     
if (turno== 0){
  
    if (x > 0 && x < 88 && y >  98 && y < 164)     // BOTON 11 //OK
      { if (L11 == 0) {VL11(); tft.drawString(UNO-10,LIN1-5,"P1",TEXTCOLOR,2);}}

      else if (x > 0 && x < 88 && y > 164 && y < 230)     // BOTON 11 //OK
      { if (L12 == 0) {VL12(); tft.drawString(DOS-10,LIN1-5,"P1",TEXTCOLOR,2);}}

       else if (x > 0 && x < 88 && y > 230 && y < 296)     // BOTON 11 //OK
      { if (L13 == 0) {VL13(); tft.drawString(TRES-10,LIN1-5,"P1",TEXTCOLOR,2);}}
//-----------------------------------------------------------------------------------------

      else if (x > 88 && x < 154 && y >  98 && y < 164)     // BOTON 11 //OK
      { if (L21 == 0) {VL21(); tft.drawString(UNO-10,LIN2-5,"P1",TEXTCOLOR,2);}}

      else if (x > 88 && x < 154 && y > 164 && y < 230)     // BOTON 11 //OK
      { if (L22 == 0) {VL22(); tft.drawString(DOS-10,LIN2-5,"P1",TEXTCOLOR,2);}}

      else if (x > 88 && x < 154 && y > 230 && y < 296)     // BOTON 11 //OK
      { if (L23 == 0) {VL23(); tft.drawString(TRES-10,LIN2-5,"P1",TEXTCOLOR,2);}}

//-----------------------------------------------------------------------------------------

     else if (x > 154 && x < 220 && y >  98 && y < 164)     // BOTON 11 //OK
      { if (L31 == 0) {VL31(); tft.drawString(UNO-10,LIN3-5,"P1",TEXTCOLOR,2);}}

     else if (x > 154 && x < 220 && y > 164 && y < 230)     // BOTON 11 //OK
      { if (L32 == 0) {VL32(); tft.drawString(DOS-10,LIN3-5,"P1",TEXTCOLOR,2);}}

    else  if (x > 154 && x < 220 && y > 230 && y < 296)     // BOTON 11 //OK
      { if (L33 == 0) {VL33(); tft.drawString(TRES-10,LIN3-5,"P1",TEXTCOLOR,2);}}
}
  }
void borrar(){

   tft.fillRoundRect(86,10,230,228,14,BLACK);
   tft.drawRoundRect(86,10,224,218,14,VERDE_O); 
     tft.drawString(95,40,"<- 2 PLAYER",WHITE,2);
  tft.drawString(95,110,"<- 1 PLAYER",WHITE,2);
RESET=0;
  }
void gato(){
tft.fillRoundRect(86,10,230,228,14,BLACK);
tft.drawRoundRect(86,10,224,218,14,VERDE_O);
tft.drawString(100,100,"!!GATOOO!!",YELLOW,3);
}
void gana(){

//===================== LINEA 1 ==================================
if (L11+L12+L13 == 12){
//tft.fillRect(95,50,200,6,YELLOW);
  tft.fillCircle(UNO, LIN2, DIAM, BLACK);
  tft.fillCircle(DOS, LIN2, DIAM, BLACK);
  tft.fillCircle(TRES, LIN2, DIAM, BLACK);
  tft.fillCircle(UNO, LIN3, DIAM, BLACK);
  tft.fillCircle(DOS, LIN3, DIAM, BLACK);
  tft.fillCircle(TRES, LIN3, DIAM, BLACK);
  ganaRojo();}
  
else if (L11+L12+L13 == 9){
  //tft.fillRect(96,50,200,4,YELLOW);
  tft.fillCircle(UNO, LIN2, DIAM, BLACK);
  tft.fillCircle(DOS, LIN2, DIAM, BLACK);
  tft.fillCircle(TRES, LIN2, DIAM, BLACK);
  tft.fillCircle(UNO, LIN3, DIAM, BLACK);
  tft.fillCircle(DOS, LIN3, DIAM, BLACK);
  tft.fillCircle(TRES, LIN3, DIAM, BLACK);
  ganaVerde();}
//====================== LINEA 2 =================================
else if (L21+L22+L23 == 12){
  //tft.fillRect(95,120,200,4,BLUE);
  tft.fillCircle(UNO, LIN1, DIAM, BLACK);
  tft.fillCircle(DOS, LIN1, DIAM, BLACK);
  tft.fillCircle(TRES, LIN1, DIAM, BLACK);
  tft.fillCircle(UNO, LIN3, DIAM, BLACK);
  tft.fillCircle(DOS, LIN3, DIAM, BLACK);
  tft.fillCircle(TRES, LIN3, DIAM, BLACK);
  ganaRojo();}
else if (L21+L22+L23 == 9){
  //tft.fillRect(95,120,200,4,YELLOW);
    tft.fillCircle(UNO, LIN1, DIAM, BLACK);
  tft.fillCircle(DOS, LIN1, DIAM, BLACK);
  tft.fillCircle(TRES, LIN1, DIAM, BLACK);
  tft.fillCircle(UNO, LIN3, DIAM, BLACK);
  tft.fillCircle(DOS, LIN3, DIAM, BLACK);
  tft.fillCircle(TRES, LIN3, DIAM, BLACK);
  ganaVerde();}
//======================= LINEA 3 =================================  
else if (L31+L32+L33 == 12){
  //tft.fillRect(95,190,200,4,YELLOW);
    tft.fillCircle(UNO, LIN1, DIAM, BLACK);
  tft.fillCircle(DOS, LIN1, DIAM, BLACK);
  tft.fillCircle(TRES, LIN1, DIAM, BLACK);
  tft.fillCircle(UNO, LIN2, DIAM, BLACK);
  tft.fillCircle(DOS, LIN2, DIAM, BLACK);
  tft.fillCircle(TRES, LIN2, DIAM, BLACK);
  ganaRojo();}
else if (L31+L32+L33 == 9){
  //tft.fillRect(95,190,200,4,YELLOW);
  tft.fillCircle(UNO, LIN1, DIAM, BLACK);
  tft.fillCircle(DOS, LIN1, DIAM, BLACK);
  tft.fillCircle(TRES, LIN1, DIAM, BLACK);
  tft.fillCircle(UNO, LIN2, DIAM, BLACK);
  tft.fillCircle(DOS, LIN2, DIAM, BLACK);
  tft.fillCircle(TRES, LIN2, DIAM, BLACK);
  ganaVerde();}

//=======================HORIZONTAL 1================================  

else if (L11+L21+L31 == 12){
  //tft.fillRect(125,20,4,200,MAGENTA);
  tft.fillCircle(DOS, LIN1, DIAM, BLACK);
  tft.fillCircle(DOS, LIN2, DIAM, BLACK);
  tft.fillCircle(DOS, LIN3, DIAM, BLACK);
  tft.fillCircle(TRES, LIN1, DIAM, BLACK);
  tft.fillCircle(TRES, LIN2, DIAM, BLACK);
  tft.fillCircle(TRES, LIN3, DIAM, BLACK);
  ganaRojo();}
else if (L11+L21+L31 == 9){
  //tft.fillRect(125,20,4,200,MAGENTA);
    tft.fillCircle(DOS, LIN1, DIAM, BLACK);
  tft.fillCircle(DOS, LIN2, DIAM, BLACK);
  tft.fillCircle(DOS, LIN3, DIAM, BLACK);
  tft.fillCircle(TRES, LIN1, DIAM, BLACK);
  tft.fillCircle(TRES, LIN2, DIAM, BLACK);
  tft.fillCircle(TRES, LIN3, DIAM, BLACK);
  ganaVerde();}
  //=======================HORIZONTAL 2================================
  else if (L12+L22+L32 == 12){
  //tft.fillRect(120,20,4,200,YELLOW);
  tft.fillCircle(UNO, LIN1, DIAM, BLACK);
  tft.fillCircle(UNO, LIN2, DIAM, BLACK);
  tft.fillCircle(UNO, LIN3, DIAM, BLACK);
  tft.fillCircle(TRES, LIN1, DIAM, BLACK);
  tft.fillCircle(TRES, LIN2, DIAM, BLACK);
  tft.fillCircle(TRES, LIN3, DIAM, BLACK);
  ganaRojo();}
  else if (L12+L22+L32 == 9){
  //tft.fillRect(195,20,4,200,YELLOW);
    tft.fillCircle(UNO, LIN1, DIAM, BLACK);
  tft.fillCircle(UNO, LIN2, DIAM, BLACK);
  tft.fillCircle(UNO, LIN3, DIAM, BLACK);
  tft.fillCircle(TRES, LIN1, DIAM, BLACK);
  tft.fillCircle(TRES, LIN2, DIAM, BLACK);
  tft.fillCircle(TRES, LIN3, DIAM, BLACK);
  ganaVerde();}
//=======================HORIZONTAL 3================================
  else if (L13+L23+L33 == 12){
  //tft.fillRect(265,20,200,4,YELLOW);
  tft.fillCircle(UNO, LIN1, DIAM, BLACK);
  tft.fillCircle(UNO, LIN2, DIAM, BLACK);
  tft.fillCircle(UNO, LIN3, DIAM, BLACK);
  tft.fillCircle(DOS, LIN1, DIAM, BLACK);
  tft.fillCircle(DOS, LIN2, DIAM, BLACK);
  tft.fillCircle(DOS, LIN3, DIAM, BLACK);
  ganaRojo();}
  else if (L13+L23+L33 == 9){
  //tft.fillRect(265,20,4,200,YELLOW);
  tft.fillCircle(UNO, LIN1, DIAM, BLACK);
  tft.fillCircle(UNO, LIN2, DIAM, BLACK);
  tft.fillCircle(UNO, LIN3, DIAM, BLACK);
  tft.fillCircle(DOS, LIN1, DIAM, BLACK);
  tft.fillCircle(DOS, LIN2, DIAM, BLACK);
  tft.fillCircle(DOS, LIN3, DIAM, BLACK);
  ganaVerde();}
//=======================X 2================================  
  
//-----------------------------
else if (L11+L22+L33 == 12){
  //tft.drawLine(10,100,20,100,YELLOW);
  tft.fillCircle(DOS, LIN1, DIAM, BLACK);
  tft.fillCircle(TRES, LIN1, DIAM, BLACK);
  tft.fillCircle(UNO, LIN2, DIAM, BLACK);
  tft.fillCircle(TRES, LIN2, DIAM, BLACK);
  tft.fillCircle(UNO, LIN3, DIAM, BLACK);
  tft.fillCircle(DOS, LIN3, DIAM, BLACK);
  ganaRojo();}
  else if (L11+L22+L33 == 9){
  //tft.drawLine(10,100,20,100,YELLOW);
  tft.fillCircle(DOS, LIN1, DIAM, BLACK);
  tft.fillCircle(TRES, LIN1, DIAM, BLACK);
  tft.fillCircle(UNO, LIN2, DIAM, BLACK);
  tft.fillCircle(TRES, LIN2, DIAM, BLACK);
  tft.fillCircle(UNO, LIN3, DIAM, BLACK);
  tft.fillCircle(DOS, LIN3, DIAM, BLACK);
  ganaVerde();}

else if (L31+L22+L13 == 12){
  //tft.drawLine(10,100,20,100,YELLOW);
  tft.fillCircle(DOS, LIN1, DIAM, BLACK);
  tft.fillCircle(UNO, LIN1, DIAM, BLACK);
  tft.fillCircle(UNO, LIN2, DIAM, BLACK);
  tft.fillCircle(TRES, LIN2, DIAM, BLACK);
  tft.fillCircle(TRES, LIN3, DIAM, BLACK);
  tft.fillCircle(DOS, LIN3, DIAM, BLACK);
  ganaRojo();}
else if (L31+L22+L13 == 9){
  //            L   a  l   a
  //tft.drawVerticalLine(125,190,200,RED);
  tft.fillCircle(DOS, LIN1, DIAM, BLACK);
  tft.fillCircle(UNO, LIN1, DIAM, BLACK);
  tft.fillCircle(UNO, LIN2, DIAM, BLACK);
  tft.fillCircle(TRES, LIN2, DIAM, BLACK);
  tft.fillCircle(TRES, LIN3, DIAM, BLACK);
  tft.fillCircle(DOS, LIN3, DIAM, BLACK);
  ganaVerde();}
//======================================

if (L11+L12+L13+L21+L22+L23+L31+L32+L33>31) {delay(500); gato(); delay(5000); softReset();}

  }
  void mensajes(){
  tft.drawString(95,40,"<- 2 PLAYER",BLACK,2);
  tft.drawString(95,110,"<- 1 PLAYER",BLACK,2);
  
  tft.drawString(120,50,"JUGADOR 1",WHITE,3);
  tft.drawString(120,100,"   VS",WHITE,3);
  tft.drawString(120,150,"JUGADOR 2",WHITE,3);
  delay(4000);
  tft.drawString(120,50,"JUGADOR 1",BLACK,3);
  tft.drawString(120,100,"   VS",BLACK,3);
  tft.drawString(120,150,"JUGADOR 2",BLACK,3);
  delay(1000);
  game=1;mensaje=0;tablero=1;juego=1;
  }
  void mensajes2(){
  tft.drawString(95,40,"<- 2 PLAYER",BLACK,2);
  tft.drawString(95,110,"<- 1 PLAYER",BLACK,2);
  
  tft.drawString(140,50,"JUGADOR",WHITE,3);
  tft.drawString(140,100,"  VS",WHITE,3);
  tft.drawString(140,150,"ARDUINO",WHITE,3);
  delay(4000);
  tft.drawString(140,50,"JUGADOR 1",BLACK,3);
  tft.drawString(140,100,"  VS",BLACK,3);
  tft.drawString(140,150,"ARDUINO",BLACK,3);
  delay(1000);
  game=1;mensaje=0;tablero=1;juego=2;
  }
void tablero1(){
  delay(1000);
tft.drawHorizontalLine(98,88,200,WHITE);
tft.drawHorizontalLine(98,154,200,WHITE);
tft.drawVerticalLine(164,18,200,WHITE);
tft.drawVerticalLine(230,18,200,WHITE);
game=1;mensaje=0;tablero=0;

  }
  void juego2(){
  //=========================================================================================  
//==========  BOTONERIA OK =================================================================  
//=========================================================================================    
tablero=0; 
if (turno==1){
  
    if (x > 0 && x < 88 && y >  98 && y < 164)     // BOTON 11 //OK
      { if (L11 == 0) {VL11();} tft.drawString(UNO-10,LIN1-5,"P2",TEXTCOLOR,2);}

      else if (x > 0 && x < 88 && y > 164 && y < 230)     // BOTON 11 //OK
      { if (L12 == 0) {VL12();} tft.drawString(DOS-10,LIN1-5,"P2",TEXTCOLOR,2);}

       else if (x > 0 && x < 88 && y > 230 && y < 296)     // BOTON 11 //OK
      { if (L13 == 0) {VL13();} tft.drawString(TRES-10,LIN1-5,"P2",TEXTCOLOR,2);}
//-----------------------------------------------------------------------------------------

      else if (x > 88 && x < 154 && y >  98 && y < 164)     // BOTON 11 //OK
      { if (L21 == 0) {VL21();} tft.drawString(UNO-10,LIN2-5,"P2",TEXTCOLOR,2);}

      else if (x > 88 && x < 154 && y > 164 && y < 230)     // BOTON 11 //OK
      { if (L22 == 0) {VL22();} tft.drawString(DOS-10,LIN2-5,"P2",TEXTCOLOR,2);}

      else if (x > 88 && x < 154 && y > 230 && y < 296)     // BOTON 11 //OK
      { if (L23 == 0) {VL23();} tft.drawString(TRES-10,LIN2-5,"P2",TEXTCOLOR,2);}

//-----------------------------------------------------------------------------------------

     else if (x > 154 && x < 220 && y >  98 && y < 164)     // BOTON 11 //OK
      { if (L31 == 0) {VL31();} tft.drawString(UNO-10,LIN3-5,"P2",TEXTCOLOR,2);}

     else if (x > 154 && x < 220 && y > 164 && y < 230)     // BOTON 11 //OK
      { if (L32 == 0) {VL32();} tft.drawString(DOS-10,LIN3-5,"P2",TEXTCOLOR,2);}

    else  if (x > 154 && x < 220 && y > 230 && y < 296)     // BOTON 11 //OK
      { if (L33 == 0) {VL33();} tft.drawString(TRES-10,LIN3-5,"P2",TEXTCOLOR,2);}
} 
  }
void inteligencia(){
 
if (turno==0){   
        
        if (L12 == 3 && L22 == 3 ){if (L32==0) {ARDU32();}}
        if (L22 == 3 && L23 == 3 ){if (L21==0) {ARDU21();}}
//-----------------------------------  
    
        if (L11 == 4 && L13 == 4 ){if (L12==0) {ARDU12();}}

        if (L13 == 4 && L33 == 4 ){if (L23==0) {ARDU23();}}
    
        if (L33 == 4 && L31 == 4 ){if (L32==0) {ARDU32();}}  

        if (L31 == 4 && L11 == 4 ){if (L21==0) {ARDU21();}}

        if (L11 == 4 && L33 == 4 ){if (L22==0) {ARDU22();}}
        
        if (L31 == 4 && L13 == 4 ){if (L22==0) {ARDU22();}}

//------------------------------------
        

        if (L13 == 3 && L33 == 3 ){if (L23==0) {ARDU23();}}
    
        if (L33 == 3 && L31 == 3 ){if (L32==0) {ARDU32();}}  

        if (L31 == 3 && L11 == 3 ){if (L21==0) {ARDU21();}}

        if (L11 == 3 && L33 == 3 ){if (L22==0) {ARDU22();}}
        
        if (L31 == 3 && L13 == 3 ){if (L22==0) {ARDU22();}}





//-----------------------------------  
    
     if (turno+L11 == 0){ARDU11();} 
else if (turno+L13 == 0){ARDU13();} 
else if (turno+L33 == 0){ARDU33();} 
else if (turno+L31 == 0){ARDU31();}

else if (turno+L21 == 0){ARDU21();}
else if (turno+L22 == 0){ARDU22();}
else if (turno+L32 == 0){ARDU32();}
else if (turno+L23 == 0){ARDU23();}
else if (turno+L12 == 0){ARDU12();}


//-----------------------------------
else if (turno+L11 == 0){ARDU11();}   
else if (turno+L12 == 0){ARDU12();}
else if (turno+L13 == 0){ARDU13();}
//-----------------------------------
else if (turno+L21 == 0){ARDU21();}   
else if (turno+L22 == 0){ARDU22();}
else if (turno+L23 == 0){ARDU23();}
//-----------------------------------
else if (turno+L31 == 0){ARDU31();}   
else if (turno+L32 == 0){ARDU32();}
else if (turno+L33 == 0){ARDU33();}
//-----------------------------------
}
  }
//==============================================
//================== SETUP =====================
//==============================================

void setup() 
{ 
  Serial.begin(9600);
  tft.reset();
  tft.initDisplay();
  tft.setRotation(1);
  tft.fillScreen(BLACK);
 tft.drawRoundRect(0,0,320,240,14,VERDE_O);
//--------------------------------------
tft.fillRoundRect(10,162,BOTON,BOTON,12,VERDE_O);
tft.fillRoundRect(10,86,BOTON,BOTON,12,VERDE_O);
tft.fillRoundRect(10,10,BOTON,BOTON,12,VERDE_O);
//--------------------------------------
tft.drawRoundRect(10,162,BOTON,BOTON,13,GRISCLARO );
tft.drawRoundRect(10,86,BOTON,BOTON,13,GRISCLARO);
tft.drawRoundRect(10,10,BOTON,BOTON,13,GRISCLARO);
//--------------------------------------
tft.drawRoundRect(86,10,224,218,14,VERDE_O);
//--------------------------------------
//tft.drawHorizontalLine(98,88,200,GRIS );
//tft.drawHorizontalLine(98,154,200,GRIS_O );
//tft.drawVerticalLine(164,18,200,GRIS );
//tft.drawVerticalLine(230,18,200,GRIS );


  tft.drawString(35,25,"2",TEXTCOLOR,3);
  tft.drawString(25,55,"PLAYER",TEXTCOLOR,1);

  tft.drawString(35,101,"1",TEXTCOLOR,3);
  tft.drawString(25,131,"PLAYER",TEXTCOLOR,1);

  tft.drawString(95,30,"GATO, TIC TAC TOE",VERDE_O,2);
  tft.drawString(95,60,"CODIGO DE MAURICIO BARUCH CHAVEZ",VERDE_O,1);
  tft.drawString(95,80,"PARA ARDUINO UNO",VERDE_O,1);
  tft.drawString(95,100,"TFT DRIVER 7783",VERDE_O,1);
  tft.drawString(95,120," ",VERDE_O,1);
  tft.drawString(95,140," ",VERDE_O,1);
  tft.drawString(95,160,"mbaru2k@hotmail.com",VERDE_O,1);
  tft.drawString(95,180,"MEXICO 19 DE SEPTIEMBRE 2017",VERDE_O,1);
  delay(5000);
  tft.drawString(95,30,"GATO, TIC TAC TOE",BLACK,2);
  tft.drawString(95,60,"CODIGO DE MAURICIO BARUCH CHAVEZ",BLACK,1);
  tft.drawString(95,80,"PARA ARDUINO UNO",BLACK,1);
  tft.drawString(95,100,"TFT DRIVER 7783",BLACK,1);
  tft.drawString(95,120," ",BLACK,1);
  tft.drawString(95,140," ",BLACK,1);
  tft.drawString(95,160,"mbaru2k@hotmail.com",BLACK,1);
  tft.drawString(95,180,"MEXICO 19 DE SEPTIEMBRE 2017",BLACK,1);

  tft.drawString(95,40,"<- 2 PLAYER",WHITE,2);
  tft.drawString(95,110,"<- 1 PLAYER",WHITE,2);
 

  
}
//==============================================
//================== LOOP ======================
//==============================================
void loop() 
{ 
    Point p = ts.getPoint();
    pinMode(XM, OUTPUT);
    pinMode(YP, OUTPUT);
    if (p.z > MINPRESSURE && p.z < MAXPRESSURE) 
    {
    x = map(p.x, TS_MAXX,TS_MINX, 0, 240);
    y = map(p.y, TS_MINY,TS_MAXY, 0, 320);
    }
  if (turno == 0) {currentcolor = RED;}
  if (turno == 1){currentcolor = GREEN;}
  
  if (game==0){selector();}
  if (mensaje ==1){mensajes();}
  if (mensaje ==2){mensajes2();}
  if (tablero ==1){tablero1();}
  if (juego ==1){tft.drawRoundRect(10,10,BOTON,BOTON,13,WHITE);juego1();}
  if (juego ==2){tft.drawRoundRect(10,10,BOTON,BOTON,13,WHITE);juego2();inteligencia();}

  
gana();
}
//==============================================
//================== FIN =======================
//==============================================

Comments

Similar projects you might like

Arduino Bluetooth Basic Tutorial

by Mayoogh Girish

  • 456,048 views
  • 44 comments
  • 242 respects

Home Automation Using Raspberry Pi 2 And Windows 10 IoT

Project tutorial by Anurag S. Vasanwala

  • 285,722 views
  • 95 comments
  • 672 respects

Security Access Using RFID Reader

by Aritro Mukherjee

  • 231,178 views
  • 38 comments
  • 241 respects

OpenCat

Project in progress by Team Petoi

  • 196,974 views
  • 154 comments
  • 1,369 respects
Add projectSign up / Login