Advertisement
arakuta

Jogo da Velha em TextDraw - SAMP

Mar 15th, 2015
1,210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 24.94 KB | None | 0 0
  1. #include <a_samp>
  2. #include <zcmd>
  3.  
  4. // Jogo da Velha para dois jogadores, By Arakuta :D
  5.  
  6. // Defines que formatam a "peça" para cada jogador, e a peça para quando não tem nada jogado ainda.
  7.  
  8. #define PIECE_ZERO  "-"
  9. #define PIECE_ONE   "X"
  10. #define PIECE_TWO   "0"
  11.  
  12. // Declarações de variáveis de textdraw.
  13.  
  14. new Text:Textdraw0;
  15. new Text:Textdraw1;
  16. new Text:Textdraw2;
  17. new Text:Textdraw3;
  18. new Text:Textdraw4;
  19. new Text:VsText;
  20. new PlayerText:StatsText[MAX_PLAYERS];
  21. new PlayerText:PosText[MAX_PLAYERS][9];
  22.  
  23. // algumas variaveis de apoio
  24.  
  25. new STR[144]; // para formatar strings
  26. new MAXPLAYERS; // Valor de slots do servidor
  27.  
  28. // Matriz contendo o estado do tabuleiro, onde tem peça, etc.
  29.  
  30. new vPos[MAX_PLAYERS][9 char];
  31.  
  32. // A | B | C      0 | 1 | 2
  33. // D | E | F      3 | 4 | 5
  34. // G | H | I      6 | 7 | 8
  35.  
  36. // Enumeração para matriz que contém valores sobre jogo do player, vitorias derrotas, etc.
  37.  
  38. enum pVelha
  39. {
  40.     playing,
  41.     wins,
  42.     losses,
  43.     draws,
  44.     round,
  45. }
  46.  
  47. new PV[MAX_PLAYERS][pVelha];
  48.  
  49. forward JogadaCPU(playerid);
  50.  
  51. public JogadaCPU(playerid)
  52. {
  53.  
  54.     SetRoundRandomValue(playerid);
  55.  
  56.     return 1;
  57. }
  58.  
  59. public OnFilterScriptExit()
  60. {
  61.  
  62.     // Destroy textos caso o filterscript seja fechado.
  63.  
  64.     TextDrawDestroy(Textdraw0);
  65.     TextDrawDestroy(Textdraw1);
  66.     TextDrawDestroy(Textdraw2);
  67.     TextDrawDestroy(Textdraw3);
  68.     TextDrawDestroy(Textdraw4);
  69.     TextDrawDestroy(VsText);
  70.    
  71.     for(new i; i < MAXPLAYERS; ++i)
  72.     {
  73.         if(IsPlayerConnected(i))
  74.         {
  75.             PlayerTextDrawDestroy(i,StatsText[i]);
  76.             PlayerTextDrawDestroy(i,PosText[i][0]);
  77.             PlayerTextDrawDestroy(i,PosText[i][1]);
  78.             PlayerTextDrawDestroy(i,PosText[i][2]);
  79.             PlayerTextDrawDestroy(i,PosText[i][3]);
  80.             PlayerTextDrawDestroy(i,PosText[i][4]);
  81.             PlayerTextDrawDestroy(i,PosText[i][5]);
  82.             PlayerTextDrawDestroy(i,PosText[i][6]);
  83.             PlayerTextDrawDestroy(i,PosText[i][7]);
  84.             PlayerTextDrawDestroy(i,PosText[i][8]);
  85.         }
  86.     }
  87.    
  88.     return 1;
  89. }
  90.  
  91. public OnFilterScriptInit()
  92. {
  93.    
  94.     // Carrega a quantidade de slots máximos do servidor
  95.    
  96.     MAXPLAYERS = GetMaxPlayers();
  97.    
  98.     // Cria os textos que não são per-player.
  99.    
  100.     Textdraw0 = TextDrawCreate(200.000000, 290.000000, "_");
  101.     TextDrawAlignment(Textdraw0, 2);
  102.     TextDrawBackgroundColor(Textdraw0, 255);
  103.     TextDrawFont(Textdraw0, 2);
  104.     TextDrawLetterSize(Textdraw0, 0.150000, 13.500000);
  105.     TextDrawColor(Textdraw0, -1);
  106.     TextDrawSetOutline(Textdraw0, 0);
  107.     TextDrawSetProportional(Textdraw0, 1);
  108.     TextDrawSetShadow(Textdraw0, 1);
  109.     TextDrawUseBox(Textdraw0, 1);
  110.     TextDrawBoxColor(Textdraw0, 68);
  111.     TextDrawTextSize(Textdraw0, 10.000000, 100.000000);
  112.     TextDrawSetSelectable(Textdraw0, 0);
  113.  
  114.     Textdraw1 = TextDrawCreate(185.000000, 290.000000, "~y~Jogo da Velha");
  115.     TextDrawAlignment(Textdraw1, 2);
  116.     TextDrawBackgroundColor(Textdraw1, 255);
  117.     TextDrawFont(Textdraw1, 2);
  118.     TextDrawLetterSize(Textdraw1, 0.200000, 1.000000);
  119.     TextDrawColor(Textdraw1, -1);
  120.     TextDrawSetOutline(Textdraw1, 0);
  121.     TextDrawSetProportional(Textdraw1, 1);
  122.     TextDrawSetShadow(Textdraw1, 1);
  123.     TextDrawSetSelectable(Textdraw1, 0);
  124.    
  125.     Textdraw2 = TextDrawCreate(199.000000, 338.000000, "-~n~~n~~n~-");
  126.     TextDrawAlignment(Textdraw2, 2);
  127.     TextDrawBackgroundColor(Textdraw2, 255);
  128.     TextDrawFont(Textdraw2, 1);
  129.     TextDrawLetterSize(Textdraw2, 6.699995, 1.000000);
  130.     TextDrawColor(Textdraw2, -1);
  131.     TextDrawSetOutline(Textdraw2, 0);
  132.     TextDrawSetProportional(Textdraw2, 1);
  133.     TextDrawSetShadow(Textdraw2, 1);
  134.     TextDrawSetSelectable(Textdraw2, 0);
  135.  
  136.     Textdraw3 = TextDrawCreate(199.000000, 285.000000,"l      l");
  137.     TextDrawAlignment(Textdraw3,2);
  138.     TextDrawBackgroundColor(Textdraw3,255);
  139.     TextDrawFont(Textdraw3,1);
  140.     TextDrawLetterSize(Textdraw3,0.270000,15.000000);
  141.     TextDrawColor(Textdraw3,-1);
  142.     TextDrawSetOutline(Textdraw3,0);
  143.     TextDrawSetProportional(Textdraw3,1);
  144.     TextDrawSetShadow(Textdraw3,1);
  145.     TextDrawSetSelectable(Textdraw3,0);
  146.    
  147.     Textdraw4 = TextDrawCreate(227.000000,290.000000,"Fechar");
  148.     TextDrawTextSize(Textdraw4,251.000000,10.000000);
  149.     TextDrawBackgroundColor(Textdraw4,255);
  150.     TextDrawFont(Textdraw4,2);
  151.     TextDrawLetterSize(Textdraw4,0.129999,1.000000);
  152.     TextDrawColor(Textdraw4,-1);
  153.     TextDrawSetOutline(Textdraw4,0);
  154.     TextDrawSetProportional(Textdraw4,1);
  155.     TextDrawSetShadow(Textdraw4,1);
  156.     TextDrawSetSelectable(Textdraw4,1);
  157.    
  158.     VsText = TextDrawCreate(201.000000,403.000000, "~b~vs. ~w~CPU");
  159.     TextDrawAlignment(VsText,2);
  160.     TextDrawBackgroundColor(VsText,255);
  161.     TextDrawFont(VsText,2);
  162.     TextDrawLetterSize(VsText,0.200000,1.000000);
  163.     TextDrawColor(VsText,-1);
  164.     TextDrawSetOutline(VsText,0);
  165.     TextDrawSetProportional(VsText,1);
  166.     TextDrawSetShadow(VsText,1);
  167.    
  168.     // Carrega as textdraws para os jogadores que estiverem conectados.
  169.    
  170.     for(new i; i < MAXPLAYERS; ++i)
  171.     {
  172.         if(IsPlayerConnected(i))
  173.             LoadTextDraws(i);
  174.     }
  175.    
  176.     printf("Jogo da Velha by Arakuta Carregado.");
  177.    
  178.     return 1;
  179. }
  180.  
  181. public OnPlayerConnect(playerid)
  182. {
  183.     LoadTextDraws(playerid); // Carrega os textos do jogador
  184.     ClearVariables(playerid); // Limpa as variáveis do jogodavelha
  185. }
  186.  
  187. public OnPlayerClickPlayerTextDraw(playerid,PlayerText:playertextid)
  188. {
  189.     // Verifica se o round é par (pois o player só pode jogar em round par?)
  190.    
  191.     if(!(PV[playerid][round] % 2))
  192.     {
  193.    
  194.         // Round par
  195.         for(new i; i < 9; ++i)
  196.         {
  197.             if(vPos[playerid]{i} && playertextid == PosText[playerid][i])
  198.                 return 1;
  199.            
  200.             if(playertextid == PosText[playerid][i])
  201.             {
  202.                 // Clicou na posição "i"
  203.                
  204.                 SetRoundValue(playerid,i);
  205.                
  206.                 // Coloca a PIECE_ONE
  207.                
  208.                 format(STR,5,"%s",PIECE_ONE);
  209.                 PlayerTextDrawSetString(playerid,PosText[playerid][i],STR);
  210.                
  211.                 // Verifica se venceu
  212.                
  213.                 if(CheckCombination(playerid,1))
  214.                 {
  215.                     EndGame(playerid,1);
  216.                 }
  217.                 else
  218.                 {
  219.                     // Avança o round
  220.                
  221.                     PV[playerid][round] ++;
  222.                    
  223.                     // Faz a jogada do computador
  224.                    
  225.                     SetTimerEx("JogadaCPU",1000,false,"d",playerid);
  226.    
  227.                     format(STR,100,"[ROUND %d] É a vez do computador jogar.",PV[playerid][round]);
  228.                     SendClientMessage(playerid,0x22FF22FF,STR);
  229.                 }
  230.            
  231.                 return 1;
  232.             }
  233.         }
  234.     }
  235.     return 0;
  236. }
  237.  
  238. public OnPlayerClickTextDraw(playerid,Text:clickedid)
  239. {
  240.     if(clickedid == Textdraw4)
  241.     {
  242.         // Texto "Fechar"
  243.         // Fecha o jogo da velha para o jogador;
  244.        
  245.         HidePlayerTicTacToe(playerid); // Fecha.   
  246.        
  247.         PV[playerid][playing] = 0;
  248.    
  249.         CancelSelectTextDraw(playerid);
  250.        
  251.         return 1;
  252.     }
  253.    
  254.     return 0;
  255. }
  256.  
  257. CMD:velha(playerid)
  258. {
  259.     if(PV[playerid][playing] && PV[playerid][round] != 99)
  260.         return SendClientMessage(playerid,0xCCCCCCFF,"Você já está em uma partida.");
  261.        
  262.     PV[playerid][playing] = 1;
  263.    
  264.     ShowPlayerTicTacToe(playerid);
  265.    
  266.     StartGame(playerid);
  267.    
  268.     return 1;
  269. }
  270.  
  271. stock StartGame(playerid)
  272. {
  273.    
  274.     // Limpa o jogo
  275.    
  276.     ZerarJogoDaVelha(playerid);
  277.    
  278.     // Começa no round 1
  279.    
  280.     PV[playerid][round] = 1;
  281.    
  282.     // Faz a jogada do computador
  283.    
  284.     SetTimerEx("JogadaCPU",1000,false,"d",playerid);
  285.    
  286.     format(STR,100,"[ROUND %d] É a vez do computador jogar.",PV[playerid][round]);
  287.     SendClientMessage(playerid,0x22FF22FF,STR);
  288.  
  289. }
  290.  
  291. stock LoadTextDraws(playerid)
  292. {
  293.     StatsText[playerid] = CreatePlayerTextDraw(playerid,199.000000,301.000000,"~g~W: ~w~150 ~r~L: ~w~200 ~b~D: ~w~400");
  294.     PlayerTextDrawAlignment(playerid,StatsText[playerid],2);
  295.     PlayerTextDrawBackgroundColor(playerid,StatsText[playerid],255);
  296.     PlayerTextDrawFont(playerid,StatsText[playerid],2);
  297.     PlayerTextDrawLetterSize(playerid,StatsText[playerid],0.200000,1.000000);
  298.     PlayerTextDrawColor(playerid,StatsText[playerid],-1);
  299.     PlayerTextDrawSetOutline(playerid,StatsText[playerid],0);
  300.     PlayerTextDrawSetProportional(playerid,StatsText[playerid],1);
  301.     PlayerTextDrawSetShadow(playerid,StatsText[playerid],1);
  302.  
  303.     PosText[playerid][0] = CreatePlayerTextDraw(playerid,165.000000,311.000000, PIECE_ZERO);
  304.     PlayerTextDrawTextSize(playerid,PosText[playerid][0],183.000000,22.000000);
  305.     PlayerTextDrawBackgroundColor(playerid,PosText[playerid][0],255);
  306.     PlayerTextDrawFont(playerid,PosText[playerid][0],1);
  307.     PlayerTextDrawLetterSize(playerid,PosText[playerid][0],0.730000,3.500000);
  308.     PlayerTextDrawColor(playerid,PosText[playerid][0],-1);
  309.     PlayerTextDrawSetOutline(playerid,PosText[playerid][0],0);
  310.     PlayerTextDrawSetProportional(playerid,PosText[playerid][0],1);
  311.     PlayerTextDrawSetShadow(playerid,PosText[playerid][0],1);
  312.     PlayerTextDrawSetSelectable(playerid,PosText[playerid][0],1);
  313.  
  314.     PosText[playerid][1] = CreatePlayerTextDraw(playerid,191.000000, 311.000000, PIECE_ZERO);
  315.     PlayerTextDrawTextSize(playerid,PosText[playerid][1],209.000000,22.000000);
  316.     PlayerTextDrawBackgroundColor(playerid,PosText[playerid][1], 255);
  317.     PlayerTextDrawFont(playerid,PosText[playerid][1], 1);
  318.     PlayerTextDrawLetterSize(playerid,PosText[playerid][1], 0.730000, 3.500000);
  319.     PlayerTextDrawColor(playerid,PosText[playerid][1], -1);
  320.     PlayerTextDrawSetOutline(playerid,PosText[playerid][1], 0);
  321.     PlayerTextDrawSetProportional(playerid,PosText[playerid][1], 1);
  322.     PlayerTextDrawSetShadow(playerid,PosText[playerid][1], 1);
  323.     PlayerTextDrawSetSelectable(playerid,PosText[playerid][1], 1);
  324.  
  325.     PosText[playerid][2] = CreatePlayerTextDraw(playerid,218.000000, 311.000000, PIECE_ZERO);
  326.     PlayerTextDrawTextSize(playerid,PosText[playerid][2],236.000000,22.000000);
  327.     PlayerTextDrawBackgroundColor(playerid,PosText[playerid][2], 255);
  328.     PlayerTextDrawFont(playerid,PosText[playerid][2], 1);
  329.     PlayerTextDrawLetterSize(playerid,PosText[playerid][2], 0.730000, 3.500000);
  330.     PlayerTextDrawColor(playerid,PosText[playerid][2], -1);
  331.     PlayerTextDrawSetOutline(playerid,PosText[playerid][2], 0);
  332.     PlayerTextDrawSetProportional(playerid,PosText[playerid][2], 1);
  333.     PlayerTextDrawSetShadow(playerid,PosText[playerid][2], 1);
  334.     PlayerTextDrawSetSelectable(playerid,PosText[playerid][2], 1);
  335.  
  336.     PosText[playerid][3] = CreatePlayerTextDraw(playerid,165.000000, 340.000000, PIECE_ZERO);
  337.     PlayerTextDrawTextSize(playerid,PosText[playerid][3],183.000000,22.000000);
  338.     PlayerTextDrawBackgroundColor(playerid,PosText[playerid][3], 255);
  339.     PlayerTextDrawFont(playerid,PosText[playerid][3], 1);
  340.     PlayerTextDrawLetterSize(playerid,PosText[playerid][3], 0.730000, 3.500000);
  341.     PlayerTextDrawColor(playerid,PosText[playerid][3], -1);
  342.     PlayerTextDrawSetOutline(playerid,PosText[playerid][3], 0);
  343.     PlayerTextDrawSetProportional(playerid,PosText[playerid][3], 1);
  344.     PlayerTextDrawSetShadow(playerid,PosText[playerid][3], 1);
  345.     PlayerTextDrawSetSelectable(playerid,PosText[playerid][3], 1);
  346.  
  347.     PosText[playerid][4] = CreatePlayerTextDraw(playerid,191.000000, 340.000000, PIECE_ZERO);
  348.     PlayerTextDrawTextSize(playerid,PosText[playerid][4],209.000000,22.000000);
  349.     PlayerTextDrawBackgroundColor(playerid,PosText[playerid][4], 255);
  350.     PlayerTextDrawFont(playerid,PosText[playerid][4], 1);
  351.     PlayerTextDrawLetterSize(playerid,PosText[playerid][4], 0.730000, 3.500000);
  352.     PlayerTextDrawColor(playerid,PosText[playerid][4], -1);
  353.     PlayerTextDrawSetOutline(playerid,PosText[playerid][4], 0);
  354.     PlayerTextDrawSetProportional(playerid,PosText[playerid][4], 1);
  355.     PlayerTextDrawSetShadow(playerid,PosText[playerid][4], 1);
  356.     PlayerTextDrawSetSelectable(playerid,PosText[playerid][4], 1);
  357.  
  358.     PosText[playerid][5] = CreatePlayerTextDraw(playerid,218.000000, 340.000000, PIECE_ZERO);
  359.     PlayerTextDrawTextSize(playerid,PosText[playerid][5],236.000000,22.000000);
  360.     PlayerTextDrawBackgroundColor(playerid,PosText[playerid][5], 255);
  361.     PlayerTextDrawFont(playerid,PosText[playerid][5], 1);
  362.     PlayerTextDrawLetterSize(playerid,PosText[playerid][5], 0.730000, 3.500000);
  363.     PlayerTextDrawColor(playerid,PosText[playerid][5], -1);
  364.     PlayerTextDrawSetOutline(playerid,PosText[playerid][5], 0);
  365.     PlayerTextDrawSetProportional(playerid,PosText[playerid][5], 1);
  366.     PlayerTextDrawSetShadow(playerid,PosText[playerid][5], 1);
  367.     PlayerTextDrawSetSelectable(playerid,PosText[playerid][5], 1);
  368.  
  369.     PosText[playerid][6] = CreatePlayerTextDraw(playerid,165.000000, 369.000000, PIECE_ZERO);
  370.     PlayerTextDrawTextSize(playerid,PosText[playerid][6],183.000000,22.000000);
  371.     PlayerTextDrawBackgroundColor(playerid,PosText[playerid][6], 255);
  372.     PlayerTextDrawFont(playerid,PosText[playerid][6], 1);
  373.     PlayerTextDrawLetterSize(playerid,PosText[playerid][6], 0.730000, 3.500000);
  374.     PlayerTextDrawColor(playerid,PosText[playerid][6], -1);
  375.     PlayerTextDrawSetOutline(playerid,PosText[playerid][6], 0);
  376.     PlayerTextDrawSetProportional(playerid,PosText[playerid][6], 1);
  377.     PlayerTextDrawSetShadow(playerid,PosText[playerid][6], 1);
  378.     PlayerTextDrawSetSelectable(playerid,PosText[playerid][6], 1);
  379.  
  380.     PosText[playerid][7] = CreatePlayerTextDraw(playerid,191.000000,369.000000, PIECE_ZERO);
  381.     PlayerTextDrawTextSize(playerid,PosText[playerid][7],209.000000,22.000000);
  382.     PlayerTextDrawBackgroundColor(playerid,PosText[playerid][7], 255);
  383.     PlayerTextDrawFont(playerid,PosText[playerid][7], 1);
  384.     PlayerTextDrawLetterSize(playerid,PosText[playerid][7], 0.730000, 3.500000);
  385.     PlayerTextDrawColor(playerid,PosText[playerid][7], -1);
  386.     PlayerTextDrawSetOutline(playerid,PosText[playerid][7], 0);
  387.     PlayerTextDrawSetProportional(playerid,PosText[playerid][7], 1);
  388.     PlayerTextDrawSetShadow(playerid,PosText[playerid][7], 1);
  389.     PlayerTextDrawSetSelectable(playerid,PosText[playerid][7], 1);
  390.  
  391.     PosText[playerid][8] = CreatePlayerTextDraw(playerid,218.000000, 369.000000, PIECE_ZERO);
  392.     PlayerTextDrawTextSize(playerid,PosText[playerid][8],236.000000,22.000000);
  393.     PlayerTextDrawBackgroundColor(playerid,PosText[playerid][8], 255);
  394.     PlayerTextDrawFont(playerid,PosText[playerid][8], 1);
  395.     PlayerTextDrawLetterSize(playerid,PosText[playerid][8], 0.730000, 3.500000);
  396.     PlayerTextDrawColor(playerid,PosText[playerid][8], -1);
  397.     PlayerTextDrawSetOutline(playerid,PosText[playerid][8], 0);
  398.     PlayerTextDrawSetProportional(playerid,PosText[playerid][8], 1);
  399.     PlayerTextDrawSetShadow(playerid,PosText[playerid][8], 1);
  400.     PlayerTextDrawSetSelectable(playerid,PosText[playerid][8], 1);
  401. }
  402.  
  403. stock ClearVariables(playerid)
  404. {
  405.     PV[playerid][losses] = 0;
  406.     PV[playerid][wins] = 0;
  407.     PV[playerid][draws] = 0;
  408.     PV[playerid][playing] = 0;
  409. }
  410.  
  411. stock CheckCombination(x,y)
  412. {
  413.     // Aqui é feita a verificação das combinações. Determina quem e como venceu.
  414.  
  415.     if(vPos[x]{0} == y && vPos[x]{3} == y && vPos[x]{6} == y)
  416.     {
  417.         // Primeira coluna é toda 1 ou 2
  418.         PlayerTextDrawColor(x,PosText[x][0],0xFF5555FF);
  419.         PlayerTextDrawColor(x,PosText[x][3],0xFF5555FF);
  420.         PlayerTextDrawColor(x,PosText[x][6],0xFF5555FF);
  421.     }
  422.     else if(vPos[x]{1} == y && vPos[x]{4} == y && vPos[x]{7} == y)
  423.     {
  424.         // Segunda coluna é toda 1 ou 2
  425.         PlayerTextDrawColor(x,PosText[x][1],0xFF5555FF);
  426.         PlayerTextDrawColor(x,PosText[x][4],0xFF5555FF);
  427.         PlayerTextDrawColor(x,PosText[x][7],0xFF5555FF);
  428.     }
  429.     else if(vPos[x]{2} == y && vPos[x]{5} == y && vPos[x]{8} == y)
  430.     {
  431.         // Terceira coluna é toda 1 ou 2
  432.         PlayerTextDrawColor(x,PosText[x][2],0xFF5555FF);
  433.         PlayerTextDrawColor(x,PosText[x][5],0xFF5555FF);
  434.         PlayerTextDrawColor(x,PosText[x][8],0xFF5555FF);
  435.     }
  436.     else if(vPos[x]{0} == y && vPos[x]{1} == y && vPos[x]{2} == y)
  437.     {
  438.         // Primeira linha é toda 1 ou 2
  439.         PlayerTextDrawColor(x,PosText[x][0],0xFF5555FF);
  440.         PlayerTextDrawColor(x,PosText[x][1],0xFF5555FF);
  441.         PlayerTextDrawColor(x,PosText[x][2],0xFF5555FF);
  442.     }
  443.     else if(vPos[x]{3} == y && vPos[x]{4} == y && vPos[x]{5} == y)
  444.     {
  445.         PlayerTextDrawColor(x,PosText[x][3],0xFF5555FF);
  446.         PlayerTextDrawColor(x,PosText[x][4],0xFF5555FF);
  447.         PlayerTextDrawColor(x,PosText[x][5],0xFF5555FF);
  448.         // Segunda linha é toda 1 ou 2
  449.     }
  450.     else if(vPos[x]{6} == y && vPos[x]{7} == y && vPos[x]{8} == y)
  451.     {
  452.         PlayerTextDrawColor(x,PosText[x][6],0xFF5555FF);
  453.         PlayerTextDrawColor(x,PosText[x][7],0xFF5555FF);
  454.         PlayerTextDrawColor(x,PosText[x][8],0xFF5555FF);
  455.         // Terceira linha é toda 1 ou 2
  456.     }
  457.     else if(vPos[x]{0} == y && vPos[x]{4} == y && vPos[x]{8} == y)
  458.     {
  459.         // Primeira Diagonal é toda 1 ou 2
  460.         PlayerTextDrawColor(x,PosText[x][0],0xFF5555FF);
  461.         PlayerTextDrawColor(x,PosText[x][4],0xFF5555FF);
  462.         PlayerTextDrawColor(x,PosText[x][8],0xFF5555FF);
  463.     }
  464.     else if(vPos[x]{2} == y && vPos[x]{4} == y && vPos[x]{6} == y)
  465.     {
  466.         // Segunda Diagonal é toda 1 ou 2
  467.         PlayerTextDrawColor(x,PosText[x][2],0xFF5555FF);
  468.         PlayerTextDrawColor(x,PosText[x][4],0xFF5555FF);
  469.         PlayerTextDrawColor(x,PosText[x][6],0xFF5555FF);
  470.     }
  471.     else
  472.         // Ainda sem vencedor
  473.         return 0;
  474.    
  475.     PlayerTextDrawShow(x,PosText[x][0]);
  476.     PlayerTextDrawShow(x,PosText[x][1]);
  477.     PlayerTextDrawShow(x,PosText[x][2]);
  478.     PlayerTextDrawShow(x,PosText[x][3]);
  479.     PlayerTextDrawShow(x,PosText[x][4]);
  480.     PlayerTextDrawShow(x,PosText[x][5]);
  481.     PlayerTextDrawShow(x,PosText[x][6]);
  482.     PlayerTextDrawShow(x,PosText[x][7]);
  483.     PlayerTextDrawShow(x,PosText[x][8]);
  484.    
  485.     return 1;
  486. }
  487.  
  488. stock ShowPlayerTicTacToe(playerid)
  489. {
  490.     TextDrawShowForPlayer(playerid,Textdraw0);
  491.     TextDrawShowForPlayer(playerid,Textdraw1);
  492.     TextDrawShowForPlayer(playerid,Textdraw2);
  493.     TextDrawShowForPlayer(playerid,Textdraw3);
  494.     TextDrawShowForPlayer(playerid,Textdraw4)
  495.     TextDrawShowForPlayer(playerid,VsText);
  496.    
  497.     UpdateStatsText(playerid);
  498.    
  499.     for(new i; i < 9; ++i)
  500.         PlayerTextDrawShow(playerid,PosText[playerid][i]);
  501.    
  502.     PlayerTextDrawShow(playerid,StatsText[playerid]);
  503.    
  504.     SelectTextDraw(playerid,0x22FF22FF);
  505. }
  506.  
  507. stock HidePlayerTicTacToe(playerid)
  508. {
  509.     TextDrawHideForPlayer(playerid,Textdraw0);
  510.     TextDrawHideForPlayer(playerid,Textdraw1);
  511.     TextDrawHideForPlayer(playerid,Textdraw2);
  512.     TextDrawHideForPlayer(playerid,Textdraw3);
  513.     TextDrawHideForPlayer(playerid,Textdraw4);
  514.     TextDrawHideForPlayer(playerid,VsText);
  515.    
  516.     PlayerTextDrawHide(playerid,PosText[playerid][0]);
  517.     PlayerTextDrawHide(playerid,PosText[playerid][1]);
  518.     PlayerTextDrawHide(playerid,PosText[playerid][2]);
  519.     PlayerTextDrawHide(playerid,PosText[playerid][3]);
  520.     PlayerTextDrawHide(playerid,PosText[playerid][4]);
  521.     PlayerTextDrawHide(playerid,PosText[playerid][5]);
  522.     PlayerTextDrawHide(playerid,PosText[playerid][6]);
  523.     PlayerTextDrawHide(playerid,PosText[playerid][7]);
  524.     PlayerTextDrawHide(playerid,PosText[playerid][8]);
  525.    
  526.     PlayerTextDrawHide(playerid,StatsText[playerid]);
  527. }
  528.  
  529. stock SetRoundValue(playerid,pos)
  530. {
  531.     vPos[playerid]{pos} = 1;
  532. }
  533.  
  534. stock ZerarJogoDaVelha(playerid)
  535. {
  536.     for(new i; i < 9; ++i)
  537.     {
  538.         PlayerTextDrawColor(playerid,PosText[playerid][i],0xFFFFFFFF);
  539.         PlayerTextDrawSetString(playerid,PosText[playerid][i],PIECE_ZERO);
  540.         PlayerTextDrawShow(playerid,PosText[playerid][i]);
  541.         vPos[playerid]{i} = 0;
  542.     }
  543. }
  544.  
  545. stock SetRoundRandomValue(playerid)
  546. {  
  547.     new pos;
  548.    
  549.     // PC Joga aleatorio no inicio
  550.    
  551.     if(PV[playerid][round] == 1)
  552.         pos = random(9);
  553.    
  554.     new x = playerid;
  555.    
  556.     // E nas outras rodadas, inteligencia artificial :D
  557.    
  558.     // A CPU primeiro tenta vencer
  559.    
  560.     if(vPos[x]{0} == 2 && !vPos[x]{1} && vPos[x]{2} == 2)
  561.         pos = 1;
  562.    
  563.     // X X -
  564.     else if(vPos[x]{0} == 2 && vPos[x]{1} == 2 && !vPos[x]{2})
  565.         pos = 2;
  566.    
  567.     // - X X
  568.     else if(vPos[x]{1} == 2 && vPos[x]{2} == 2 && !vPos[x]{0})
  569.         pos = 0;
  570.    
  571.     // 0 1 2
  572.     // X - X
  573.     else if(vPos[x]{3} == 2 && !vPos[x]{4} && vPos[x]{5} == 2)
  574.         pos = 4;
  575.    
  576.     // 0 1 2
  577.     // X X -
  578.     else if(vPos[x]{3} == 2 && vPos[x]{4} == 2 && !vPos[x]{5})
  579.         pos = 5;
  580.        
  581.     // 0 1 2
  582.     // - X X
  583.     else if(vPos[x]{4} == 2 && !vPos[x]{3} && vPos[x]{5} == 2)
  584.         pos = 3;
  585.    
  586.     // 0 1 2
  587.     // 3 4 5
  588.     // X - X
  589.     else if(vPos[x]{6} == 2 && !vPos[x]{7} && vPos[x]{8} == 2)
  590.         pos = 7;
  591.    
  592.     // 0 1 2
  593.     // 3 4 5
  594.     // X X -
  595.     else if(vPos[x]{6} == 2 && vPos[x]{7} == 2 && !vPos[x]{8})
  596.         pos = 8;
  597.        
  598.     // 0 1 2
  599.     // 3 4 5
  600.     // - X X
  601.     else if(vPos[x]{7} == 2 && vPos[x]{8} == 2 && !vPos[x]{6})
  602.         pos = 6;
  603.    
  604.     // X 1 2
  605.     // - 4 5
  606.     // X 7 8
  607.     else if(vPos[x]{0} == 2 && !vPos[x]{3} && vPos[x]{6} == 2)
  608.         pos = 3;
  609.    
  610.     // X 1 2
  611.     // X 4 5
  612.     // - 7 8
  613.     else if(vPos[x]{0} == 2 && vPos[x]{3} == 2 && !vPos[x]{6})
  614.         pos = 6;
  615.    
  616.     // - 1 2
  617.     // X 4 5
  618.     // X 7 8
  619.     else if(vPos[x]{3} == 2 && vPos[x]{6} == 2 && !vPos[x]{0})
  620.         pos = 0;
  621.    
  622.     // 0 X 2
  623.     // 3 - 5
  624.     // 6 X 8
  625.     else if(vPos[x]{1} == 2 && !vPos[x]{4} && vPos[x]{7} == 2)
  626.         pos = 4;
  627.    
  628.     // 0 - 2
  629.     // 3 X 5
  630.     // 6 X 8
  631.     else if(vPos[x]{4} == 2 && !vPos[x]{7} && vPos[x]{7} == 2)
  632.         pos = 1;
  633.    
  634.     // 0 X 2
  635.     // 3 X 5
  636.     // 6 - 8
  637.     else if(vPos[x]{1} == 2 && vPos[x]{7} == 2 && !vPos[x]{7})
  638.         pos = 7;
  639.        
  640.     // 0 1 X
  641.     // 3 4 -
  642.     // 6 7 X
  643.     else if(vPos[x]{2} == 2 && !vPos[x]{5} && vPos[x]{8} == 2)
  644.         pos = 5;
  645.    
  646.     // 0 1 -
  647.     // 3 4 X
  648.     // 6 7 X
  649.     else if(vPos[x]{5} == 2 && !vPos[x]{2} && vPos[x]{8} == 2)
  650.         pos = 2;
  651.    
  652.     // 0 1 X
  653.     // 3 4 X
  654.     // 6 7 -
  655.     else if(vPos[x]{2} == 2 && vPos[x]{5} == 2 && !vPos[x]{8})
  656.         pos = 8;
  657.        
  658.     // X 1 2
  659.     // 3 - 5
  660.     // 6 7 X
  661.     else if(vPos[x]{0} ==2  && vPos[x]{8} == 2 && !vPos[x]{4})
  662.         pos = 4;
  663.    
  664.     // X 1 2
  665.     // 3 X 5
  666.     // 6 7 -
  667.     else if(vPos[x]{0} == 2 && vPos[x]{4} == 2 && !vPos[x]{8})
  668.         pos = 8;
  669.    
  670.     // - 1 2
  671.     // 3 X 5
  672.     // 6 7 X
  673.     else if(vPos[x]{4} == 2 && vPos[x]{8} == 2 && !vPos[x]{0})
  674.         pos = 0;
  675.    
  676.     // 0 1 X
  677.     // 3 - 5
  678.     // X 7 8
  679.     else if(vPos[x]{2} == 2 && vPos[x]{6} == 2 && !vPos[x]{4})
  680.         pos = 4;
  681.    
  682.     // 0 1 X
  683.     // 3 X 5
  684.     // - 7 8
  685.     else if(vPos[x]{2} == 2 && vPos[x]{4} == 2 && !vPos[x]{6})
  686.         pos = 6;
  687.    
  688.     // 0 1 -
  689.     // 3 X 5
  690.     // X 7 8
  691.     else if(vPos[x]{4} == 2 && vPos[x]{6} == 2 && !vPos[x]{2})
  692.         pos = 2;
  693.    
  694.     // Senão vai sempre tentar te impedir de fechar a sequencia...
  695.     // X - X
  696.     else if(vPos[x]{0} == 1 && !vPos[x]{1} && vPos[x]{2} == 1)
  697.         pos = 1;
  698.    
  699.     // X X -
  700.     else if(vPos[x]{0} == 1 && vPos[x]{1} == 1 && !vPos[x]{2})
  701.         pos = 2;
  702.    
  703.     // - X X
  704.     else if(vPos[x]{1} == 1 && vPos[x]{2} == 1 && !vPos[x]{0})
  705.         pos = 0;
  706.    
  707.     // 0 1 2
  708.     // X - X
  709.     else if(vPos[x]{3} == 1 && !vPos[x]{4} && vPos[x]{5} == 1)
  710.         pos = 4;
  711.    
  712.     // 0 1 2
  713.     // X X -
  714.     else if(vPos[x]{3} == 1 && vPos[x]{4} == 1 && !vPos[x]{5})
  715.         pos = 5;
  716.        
  717.     // 0 1 2
  718.     // - X X
  719.     else if(vPos[x]{4} == 1 && !vPos[x]{3} && vPos[x]{5} == 1)
  720.         pos = 3;
  721.    
  722.     // 0 1 2
  723.     // 3 4 5
  724.     // X - X
  725.     else if(vPos[x]{6} == 1 && !vPos[x]{7} && vPos[x]{8} == 1)
  726.         pos = 7;
  727.    
  728.     // 0 1 2
  729.     // 3 4 5
  730.     // X X -
  731.     else if(vPos[x]{6} == 1 && vPos[x]{7} == 1 && !vPos[x]{8})
  732.         pos = 8;
  733.        
  734.     // 0 1 2
  735.     // 3 4 5
  736.     // - X X
  737.     else if(vPos[x]{7} == 1 && vPos[x]{8} == 1 && !vPos[x]{6})
  738.         pos = 6;
  739.    
  740.     // X 1 2
  741.     // - 4 5
  742.     // X 7 8
  743.     else if(vPos[x]{0} == 1 && !vPos[x]{3} && vPos[x]{6} == 1)
  744.         pos = 3;
  745.    
  746.     // X 1 2
  747.     // X 4 5
  748.     // - 7 8
  749.     else if(vPos[x]{0} == 1 && vPos[x]{3} == 1 && !vPos[x]{6})
  750.         pos = 6;
  751.    
  752.     // - 1 2
  753.     // X 4 5
  754.     // X 7 8
  755.     else if(vPos[x]{3} == 1 && vPos[x]{6} == 1 && !vPos[x]{0})
  756.         pos = 0;
  757.    
  758.     // 0 X 2
  759.     // 3 - 5
  760.     // 6 X 8
  761.     else if(vPos[x]{1} == 1 && !vPos[x]{4} && vPos[x]{7} == 1)
  762.         pos = 4;
  763.    
  764.     // 0 - 2
  765.     // 3 X 5
  766.     // 6 X 8
  767.     else if(vPos[x]{4} == 1 && !vPos[x]{7} && vPos[x]{7} == 1)
  768.         pos = 1;
  769.    
  770.     // 0 X 2
  771.     // 3 X 5
  772.     // 6 - 8
  773.     else if(vPos[x]{1} == 1 && vPos[x]{7} == 1 && !vPos[x]{7})
  774.         pos = 7;
  775.        
  776.     // 0 1 X
  777.     // 3 4 -
  778.     // 6 7 X
  779.     else if(vPos[x]{2} == 1 && !vPos[x]{5} && vPos[x]{8} == 1)
  780.         pos = 5;
  781.    
  782.     // 0 1 -
  783.     // 3 4 X
  784.     // 6 7 X
  785.     else if(vPos[x]{5} == 1 && !vPos[x]{2} && vPos[x]{8} == 1)
  786.         pos = 2;
  787.    
  788.     // 0 1 X
  789.     // 3 4 X
  790.     // 6 7 -
  791.     else if(vPos[x]{2} == 1 && vPos[x]{5} == 1 && !vPos[x]{8})
  792.         pos = 8;
  793.        
  794.     // X 1 2
  795.     // 3 - 5
  796.     // 6 7 X
  797.     else if(vPos[x]{0} == 1 && vPos[x]{8} == 1 && !vPos[x]{4})
  798.         pos = 4;
  799.    
  800.     // X 1 2
  801.     // 3 X 5
  802.     // 6 7 -
  803.     else if(vPos[x]{0} == 1 && vPos[x]{4} == 1 && !vPos[x]{8})
  804.         pos = 8;
  805.    
  806.     // - 1 2
  807.     // 3 X 5
  808.     // 6 7 X
  809.     else if(vPos[x]{4} == 1 && vPos[x]{8} == 1 && !vPos[x]{0})
  810.         pos = 0;
  811.    
  812.     // 0 1 X
  813.     // 3 - 5
  814.     // X 7 8
  815.     else if(vPos[x]{2} == 1 && vPos[x]{6} == 1 && !vPos[x]{4})
  816.         pos = 4;
  817.    
  818.     // 0 1 X
  819.     // 3 X 5
  820.     // - 7 8
  821.     else if(vPos[x]{2} == 1 && vPos[x]{4} == 1 && !vPos[x]{6})
  822.         pos = 6;
  823.    
  824.     // 0 1 -
  825.     // 3 X 5
  826.     // X 7 8
  827.     else if(vPos[x]{4} == 1 && vPos[x]{6} == 1 && !vPos[x]{2})
  828.         pos = 2;
  829.        
  830.     else
  831.         pos = RandomPos(playerid);
  832.    
  833.    
  834.     // Coloca a PIECE_TWO
  835.                
  836.     format(STR,5,"%s",PIECE_TWO);
  837.     PlayerTextDrawSetString(playerid,PosText[playerid][pos],STR);
  838.    
  839.     vPos[playerid]{pos} = 2;
  840.    
  841.     // Verifica se o computador venceu
  842.            
  843.     if(CheckCombination(playerid,2))
  844.     {
  845.         EndGame(playerid,2);
  846.     }
  847.     else
  848.     {
  849.         // Avança o round
  850.    
  851.         PV[playerid][round] ++;
  852.        
  853.         if(PV[playerid][round] == 10)
  854.         {
  855.             EndGame(playerid,0);
  856.             return;
  857.         }
  858.        
  859.         format(STR,100,"[ROUND %d] É a sua vez de jogar.",PV[playerid][round]);
  860.         SendClientMessage(playerid,0x22FF22FF,STR);
  861.     }
  862. }
  863.  
  864. stock CasaVazia(playerid)
  865. {
  866.     for(new i; i < 9; ++i)
  867.     {
  868.         if(!vPos[playerid]{i})
  869.             return 1;
  870.     }
  871.    
  872.     return 0;
  873. }
  874.  
  875. stock RandomPos(playerid)
  876. {
  877.     new pos;
  878.     while(!pos)
  879.     {
  880.         pos = random(9);
  881.         if(!vPos[playerid]{pos})
  882.             break;
  883.         pos = 0;
  884.     }
  885.    
  886.     return pos;
  887. }
  888.  
  889. stock EndGame(playerid,winner)
  890. {
  891.     if(winner == 2)
  892.     {
  893.         SendClientMessage(playerid,0xFF2222FF,"Poxa, você perdeu pro computador :/");
  894.         PV[playerid][losses] ++;
  895.     }
  896.     else if(winner == 1)
  897.     {
  898.         SendClientMessage(playerid,0xFF2222FF,"Boa! Você venceu o jogo da velha!");
  899.         PV[playerid][wins] ++;
  900.     }
  901.     else
  902.     {
  903.         SendClientMessage(playerid,0xFF2222FF,"Eita porra deu velha x.x");
  904.         PV[playerid][draws] ++;
  905.     }
  906.    
  907.     PV[playerid][round] = 99;
  908.    
  909.     UpdateStatsText(playerid);
  910. }
  911.  
  912. stock UpdateStatsText(playerid)
  913. {
  914.     format(STR,100,"~g~W: ~w~%d ~r~L: ~w~%d ~b~D: ~w~%d",PV[playerid][wins],PV[playerid][losses],PV[playerid][draws]);
  915.     PlayerTextDrawSetString(playerid,StatsText[playerid],STR);
  916. }
  917.  
  918.  
  919. stock pName(playerid)
  920. {
  921.     new name[24];
  922.     GetPlayerName(playerid,name,24);
  923.     return name;
  924. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement