Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <zcmd>
- // Jogo da Velha para dois jogadores, By Arakuta :D
- // Defines que formatam a "peça" para cada jogador, e a peça para quando não tem nada jogado ainda.
- #define PIECE_ZERO "-"
- #define PIECE_ONE "X"
- #define PIECE_TWO "0"
- // Declarações de variáveis de textdraw.
- new Text:Textdraw0;
- new Text:Textdraw1;
- new Text:Textdraw2;
- new Text:Textdraw3;
- new Text:Textdraw4;
- new Text:VsText;
- new PlayerText:StatsText[MAX_PLAYERS];
- new PlayerText:PosText[MAX_PLAYERS][9];
- // algumas variaveis de apoio
- new STR[144]; // para formatar strings
- new MAXPLAYERS; // Valor de slots do servidor
- // Matriz contendo o estado do tabuleiro, onde tem peça, etc.
- new vPos[MAX_PLAYERS][9 char];
- // A | B | C 0 | 1 | 2
- // D | E | F 3 | 4 | 5
- // G | H | I 6 | 7 | 8
- // Enumeração para matriz que contém valores sobre jogo do player, vitorias derrotas, etc.
- enum pVelha
- {
- playing,
- wins,
- losses,
- draws,
- round,
- }
- new PV[MAX_PLAYERS][pVelha];
- forward JogadaCPU(playerid);
- public JogadaCPU(playerid)
- {
- SetRoundRandomValue(playerid);
- return 1;
- }
- public OnFilterScriptExit()
- {
- // Destroy textos caso o filterscript seja fechado.
- TextDrawDestroy(Textdraw0);
- TextDrawDestroy(Textdraw1);
- TextDrawDestroy(Textdraw2);
- TextDrawDestroy(Textdraw3);
- TextDrawDestroy(Textdraw4);
- TextDrawDestroy(VsText);
- for(new i; i < MAXPLAYERS; ++i)
- {
- if(IsPlayerConnected(i))
- {
- PlayerTextDrawDestroy(i,StatsText[i]);
- PlayerTextDrawDestroy(i,PosText[i][0]);
- PlayerTextDrawDestroy(i,PosText[i][1]);
- PlayerTextDrawDestroy(i,PosText[i][2]);
- PlayerTextDrawDestroy(i,PosText[i][3]);
- PlayerTextDrawDestroy(i,PosText[i][4]);
- PlayerTextDrawDestroy(i,PosText[i][5]);
- PlayerTextDrawDestroy(i,PosText[i][6]);
- PlayerTextDrawDestroy(i,PosText[i][7]);
- PlayerTextDrawDestroy(i,PosText[i][8]);
- }
- }
- return 1;
- }
- public OnFilterScriptInit()
- {
- // Carrega a quantidade de slots máximos do servidor
- MAXPLAYERS = GetMaxPlayers();
- // Cria os textos que não são per-player.
- Textdraw0 = TextDrawCreate(200.000000, 290.000000, "_");
- TextDrawAlignment(Textdraw0, 2);
- TextDrawBackgroundColor(Textdraw0, 255);
- TextDrawFont(Textdraw0, 2);
- TextDrawLetterSize(Textdraw0, 0.150000, 13.500000);
- TextDrawColor(Textdraw0, -1);
- TextDrawSetOutline(Textdraw0, 0);
- TextDrawSetProportional(Textdraw0, 1);
- TextDrawSetShadow(Textdraw0, 1);
- TextDrawUseBox(Textdraw0, 1);
- TextDrawBoxColor(Textdraw0, 68);
- TextDrawTextSize(Textdraw0, 10.000000, 100.000000);
- TextDrawSetSelectable(Textdraw0, 0);
- Textdraw1 = TextDrawCreate(185.000000, 290.000000, "~y~Jogo da Velha");
- TextDrawAlignment(Textdraw1, 2);
- TextDrawBackgroundColor(Textdraw1, 255);
- TextDrawFont(Textdraw1, 2);
- TextDrawLetterSize(Textdraw1, 0.200000, 1.000000);
- TextDrawColor(Textdraw1, -1);
- TextDrawSetOutline(Textdraw1, 0);
- TextDrawSetProportional(Textdraw1, 1);
- TextDrawSetShadow(Textdraw1, 1);
- TextDrawSetSelectable(Textdraw1, 0);
- Textdraw2 = TextDrawCreate(199.000000, 338.000000, "-~n~~n~~n~-");
- TextDrawAlignment(Textdraw2, 2);
- TextDrawBackgroundColor(Textdraw2, 255);
- TextDrawFont(Textdraw2, 1);
- TextDrawLetterSize(Textdraw2, 6.699995, 1.000000);
- TextDrawColor(Textdraw2, -1);
- TextDrawSetOutline(Textdraw2, 0);
- TextDrawSetProportional(Textdraw2, 1);
- TextDrawSetShadow(Textdraw2, 1);
- TextDrawSetSelectable(Textdraw2, 0);
- Textdraw3 = TextDrawCreate(199.000000, 285.000000,"l l");
- TextDrawAlignment(Textdraw3,2);
- TextDrawBackgroundColor(Textdraw3,255);
- TextDrawFont(Textdraw3,1);
- TextDrawLetterSize(Textdraw3,0.270000,15.000000);
- TextDrawColor(Textdraw3,-1);
- TextDrawSetOutline(Textdraw3,0);
- TextDrawSetProportional(Textdraw3,1);
- TextDrawSetShadow(Textdraw3,1);
- TextDrawSetSelectable(Textdraw3,0);
- Textdraw4 = TextDrawCreate(227.000000,290.000000,"Fechar");
- TextDrawTextSize(Textdraw4,251.000000,10.000000);
- TextDrawBackgroundColor(Textdraw4,255);
- TextDrawFont(Textdraw4,2);
- TextDrawLetterSize(Textdraw4,0.129999,1.000000);
- TextDrawColor(Textdraw4,-1);
- TextDrawSetOutline(Textdraw4,0);
- TextDrawSetProportional(Textdraw4,1);
- TextDrawSetShadow(Textdraw4,1);
- TextDrawSetSelectable(Textdraw4,1);
- VsText = TextDrawCreate(201.000000,403.000000, "~b~vs. ~w~CPU");
- TextDrawAlignment(VsText,2);
- TextDrawBackgroundColor(VsText,255);
- TextDrawFont(VsText,2);
- TextDrawLetterSize(VsText,0.200000,1.000000);
- TextDrawColor(VsText,-1);
- TextDrawSetOutline(VsText,0);
- TextDrawSetProportional(VsText,1);
- TextDrawSetShadow(VsText,1);
- // Carrega as textdraws para os jogadores que estiverem conectados.
- for(new i; i < MAXPLAYERS; ++i)
- {
- if(IsPlayerConnected(i))
- LoadTextDraws(i);
- }
- printf("Jogo da Velha by Arakuta Carregado.");
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- LoadTextDraws(playerid); // Carrega os textos do jogador
- ClearVariables(playerid); // Limpa as variáveis do jogodavelha
- }
- public OnPlayerClickPlayerTextDraw(playerid,PlayerText:playertextid)
- {
- // Verifica se o round é par (pois o player só pode jogar em round par?)
- if(!(PV[playerid][round] % 2))
- {
- // Round par
- for(new i; i < 9; ++i)
- {
- if(vPos[playerid]{i} && playertextid == PosText[playerid][i])
- return 1;
- if(playertextid == PosText[playerid][i])
- {
- // Clicou na posição "i"
- SetRoundValue(playerid,i);
- // Coloca a PIECE_ONE
- format(STR,5,"%s",PIECE_ONE);
- PlayerTextDrawSetString(playerid,PosText[playerid][i],STR);
- // Verifica se venceu
- if(CheckCombination(playerid,1))
- {
- EndGame(playerid,1);
- }
- else
- {
- // Avança o round
- PV[playerid][round] ++;
- // Faz a jogada do computador
- SetTimerEx("JogadaCPU",1000,false,"d",playerid);
- format(STR,100,"[ROUND %d] É a vez do computador jogar.",PV[playerid][round]);
- SendClientMessage(playerid,0x22FF22FF,STR);
- }
- return 1;
- }
- }
- }
- return 0;
- }
- public OnPlayerClickTextDraw(playerid,Text:clickedid)
- {
- if(clickedid == Textdraw4)
- {
- // Texto "Fechar"
- // Fecha o jogo da velha para o jogador;
- HidePlayerTicTacToe(playerid); // Fecha.
- PV[playerid][playing] = 0;
- CancelSelectTextDraw(playerid);
- return 1;
- }
- return 0;
- }
- CMD:velha(playerid)
- {
- if(PV[playerid][playing] && PV[playerid][round] != 99)
- return SendClientMessage(playerid,0xCCCCCCFF,"Você já está em uma partida.");
- PV[playerid][playing] = 1;
- ShowPlayerTicTacToe(playerid);
- StartGame(playerid);
- return 1;
- }
- stock StartGame(playerid)
- {
- // Limpa o jogo
- ZerarJogoDaVelha(playerid);
- // Começa no round 1
- PV[playerid][round] = 1;
- // Faz a jogada do computador
- SetTimerEx("JogadaCPU",1000,false,"d",playerid);
- format(STR,100,"[ROUND %d] É a vez do computador jogar.",PV[playerid][round]);
- SendClientMessage(playerid,0x22FF22FF,STR);
- }
- stock LoadTextDraws(playerid)
- {
- StatsText[playerid] = CreatePlayerTextDraw(playerid,199.000000,301.000000,"~g~W: ~w~150 ~r~L: ~w~200 ~b~D: ~w~400");
- PlayerTextDrawAlignment(playerid,StatsText[playerid],2);
- PlayerTextDrawBackgroundColor(playerid,StatsText[playerid],255);
- PlayerTextDrawFont(playerid,StatsText[playerid],2);
- PlayerTextDrawLetterSize(playerid,StatsText[playerid],0.200000,1.000000);
- PlayerTextDrawColor(playerid,StatsText[playerid],-1);
- PlayerTextDrawSetOutline(playerid,StatsText[playerid],0);
- PlayerTextDrawSetProportional(playerid,StatsText[playerid],1);
- PlayerTextDrawSetShadow(playerid,StatsText[playerid],1);
- PosText[playerid][0] = CreatePlayerTextDraw(playerid,165.000000,311.000000, PIECE_ZERO);
- PlayerTextDrawTextSize(playerid,PosText[playerid][0],183.000000,22.000000);
- PlayerTextDrawBackgroundColor(playerid,PosText[playerid][0],255);
- PlayerTextDrawFont(playerid,PosText[playerid][0],1);
- PlayerTextDrawLetterSize(playerid,PosText[playerid][0],0.730000,3.500000);
- PlayerTextDrawColor(playerid,PosText[playerid][0],-1);
- PlayerTextDrawSetOutline(playerid,PosText[playerid][0],0);
- PlayerTextDrawSetProportional(playerid,PosText[playerid][0],1);
- PlayerTextDrawSetShadow(playerid,PosText[playerid][0],1);
- PlayerTextDrawSetSelectable(playerid,PosText[playerid][0],1);
- PosText[playerid][1] = CreatePlayerTextDraw(playerid,191.000000, 311.000000, PIECE_ZERO);
- PlayerTextDrawTextSize(playerid,PosText[playerid][1],209.000000,22.000000);
- PlayerTextDrawBackgroundColor(playerid,PosText[playerid][1], 255);
- PlayerTextDrawFont(playerid,PosText[playerid][1], 1);
- PlayerTextDrawLetterSize(playerid,PosText[playerid][1], 0.730000, 3.500000);
- PlayerTextDrawColor(playerid,PosText[playerid][1], -1);
- PlayerTextDrawSetOutline(playerid,PosText[playerid][1], 0);
- PlayerTextDrawSetProportional(playerid,PosText[playerid][1], 1);
- PlayerTextDrawSetShadow(playerid,PosText[playerid][1], 1);
- PlayerTextDrawSetSelectable(playerid,PosText[playerid][1], 1);
- PosText[playerid][2] = CreatePlayerTextDraw(playerid,218.000000, 311.000000, PIECE_ZERO);
- PlayerTextDrawTextSize(playerid,PosText[playerid][2],236.000000,22.000000);
- PlayerTextDrawBackgroundColor(playerid,PosText[playerid][2], 255);
- PlayerTextDrawFont(playerid,PosText[playerid][2], 1);
- PlayerTextDrawLetterSize(playerid,PosText[playerid][2], 0.730000, 3.500000);
- PlayerTextDrawColor(playerid,PosText[playerid][2], -1);
- PlayerTextDrawSetOutline(playerid,PosText[playerid][2], 0);
- PlayerTextDrawSetProportional(playerid,PosText[playerid][2], 1);
- PlayerTextDrawSetShadow(playerid,PosText[playerid][2], 1);
- PlayerTextDrawSetSelectable(playerid,PosText[playerid][2], 1);
- PosText[playerid][3] = CreatePlayerTextDraw(playerid,165.000000, 340.000000, PIECE_ZERO);
- PlayerTextDrawTextSize(playerid,PosText[playerid][3],183.000000,22.000000);
- PlayerTextDrawBackgroundColor(playerid,PosText[playerid][3], 255);
- PlayerTextDrawFont(playerid,PosText[playerid][3], 1);
- PlayerTextDrawLetterSize(playerid,PosText[playerid][3], 0.730000, 3.500000);
- PlayerTextDrawColor(playerid,PosText[playerid][3], -1);
- PlayerTextDrawSetOutline(playerid,PosText[playerid][3], 0);
- PlayerTextDrawSetProportional(playerid,PosText[playerid][3], 1);
- PlayerTextDrawSetShadow(playerid,PosText[playerid][3], 1);
- PlayerTextDrawSetSelectable(playerid,PosText[playerid][3], 1);
- PosText[playerid][4] = CreatePlayerTextDraw(playerid,191.000000, 340.000000, PIECE_ZERO);
- PlayerTextDrawTextSize(playerid,PosText[playerid][4],209.000000,22.000000);
- PlayerTextDrawBackgroundColor(playerid,PosText[playerid][4], 255);
- PlayerTextDrawFont(playerid,PosText[playerid][4], 1);
- PlayerTextDrawLetterSize(playerid,PosText[playerid][4], 0.730000, 3.500000);
- PlayerTextDrawColor(playerid,PosText[playerid][4], -1);
- PlayerTextDrawSetOutline(playerid,PosText[playerid][4], 0);
- PlayerTextDrawSetProportional(playerid,PosText[playerid][4], 1);
- PlayerTextDrawSetShadow(playerid,PosText[playerid][4], 1);
- PlayerTextDrawSetSelectable(playerid,PosText[playerid][4], 1);
- PosText[playerid][5] = CreatePlayerTextDraw(playerid,218.000000, 340.000000, PIECE_ZERO);
- PlayerTextDrawTextSize(playerid,PosText[playerid][5],236.000000,22.000000);
- PlayerTextDrawBackgroundColor(playerid,PosText[playerid][5], 255);
- PlayerTextDrawFont(playerid,PosText[playerid][5], 1);
- PlayerTextDrawLetterSize(playerid,PosText[playerid][5], 0.730000, 3.500000);
- PlayerTextDrawColor(playerid,PosText[playerid][5], -1);
- PlayerTextDrawSetOutline(playerid,PosText[playerid][5], 0);
- PlayerTextDrawSetProportional(playerid,PosText[playerid][5], 1);
- PlayerTextDrawSetShadow(playerid,PosText[playerid][5], 1);
- PlayerTextDrawSetSelectable(playerid,PosText[playerid][5], 1);
- PosText[playerid][6] = CreatePlayerTextDraw(playerid,165.000000, 369.000000, PIECE_ZERO);
- PlayerTextDrawTextSize(playerid,PosText[playerid][6],183.000000,22.000000);
- PlayerTextDrawBackgroundColor(playerid,PosText[playerid][6], 255);
- PlayerTextDrawFont(playerid,PosText[playerid][6], 1);
- PlayerTextDrawLetterSize(playerid,PosText[playerid][6], 0.730000, 3.500000);
- PlayerTextDrawColor(playerid,PosText[playerid][6], -1);
- PlayerTextDrawSetOutline(playerid,PosText[playerid][6], 0);
- PlayerTextDrawSetProportional(playerid,PosText[playerid][6], 1);
- PlayerTextDrawSetShadow(playerid,PosText[playerid][6], 1);
- PlayerTextDrawSetSelectable(playerid,PosText[playerid][6], 1);
- PosText[playerid][7] = CreatePlayerTextDraw(playerid,191.000000,369.000000, PIECE_ZERO);
- PlayerTextDrawTextSize(playerid,PosText[playerid][7],209.000000,22.000000);
- PlayerTextDrawBackgroundColor(playerid,PosText[playerid][7], 255);
- PlayerTextDrawFont(playerid,PosText[playerid][7], 1);
- PlayerTextDrawLetterSize(playerid,PosText[playerid][7], 0.730000, 3.500000);
- PlayerTextDrawColor(playerid,PosText[playerid][7], -1);
- PlayerTextDrawSetOutline(playerid,PosText[playerid][7], 0);
- PlayerTextDrawSetProportional(playerid,PosText[playerid][7], 1);
- PlayerTextDrawSetShadow(playerid,PosText[playerid][7], 1);
- PlayerTextDrawSetSelectable(playerid,PosText[playerid][7], 1);
- PosText[playerid][8] = CreatePlayerTextDraw(playerid,218.000000, 369.000000, PIECE_ZERO);
- PlayerTextDrawTextSize(playerid,PosText[playerid][8],236.000000,22.000000);
- PlayerTextDrawBackgroundColor(playerid,PosText[playerid][8], 255);
- PlayerTextDrawFont(playerid,PosText[playerid][8], 1);
- PlayerTextDrawLetterSize(playerid,PosText[playerid][8], 0.730000, 3.500000);
- PlayerTextDrawColor(playerid,PosText[playerid][8], -1);
- PlayerTextDrawSetOutline(playerid,PosText[playerid][8], 0);
- PlayerTextDrawSetProportional(playerid,PosText[playerid][8], 1);
- PlayerTextDrawSetShadow(playerid,PosText[playerid][8], 1);
- PlayerTextDrawSetSelectable(playerid,PosText[playerid][8], 1);
- }
- stock ClearVariables(playerid)
- {
- PV[playerid][losses] = 0;
- PV[playerid][wins] = 0;
- PV[playerid][draws] = 0;
- PV[playerid][playing] = 0;
- }
- stock CheckCombination(x,y)
- {
- // Aqui é feita a verificação das combinações. Determina quem e como venceu.
- if(vPos[x]{0} == y && vPos[x]{3} == y && vPos[x]{6} == y)
- {
- // Primeira coluna é toda 1 ou 2
- PlayerTextDrawColor(x,PosText[x][0],0xFF5555FF);
- PlayerTextDrawColor(x,PosText[x][3],0xFF5555FF);
- PlayerTextDrawColor(x,PosText[x][6],0xFF5555FF);
- }
- else if(vPos[x]{1} == y && vPos[x]{4} == y && vPos[x]{7} == y)
- {
- // Segunda coluna é toda 1 ou 2
- PlayerTextDrawColor(x,PosText[x][1],0xFF5555FF);
- PlayerTextDrawColor(x,PosText[x][4],0xFF5555FF);
- PlayerTextDrawColor(x,PosText[x][7],0xFF5555FF);
- }
- else if(vPos[x]{2} == y && vPos[x]{5} == y && vPos[x]{8} == y)
- {
- // Terceira coluna é toda 1 ou 2
- PlayerTextDrawColor(x,PosText[x][2],0xFF5555FF);
- PlayerTextDrawColor(x,PosText[x][5],0xFF5555FF);
- PlayerTextDrawColor(x,PosText[x][8],0xFF5555FF);
- }
- else if(vPos[x]{0} == y && vPos[x]{1} == y && vPos[x]{2} == y)
- {
- // Primeira linha é toda 1 ou 2
- PlayerTextDrawColor(x,PosText[x][0],0xFF5555FF);
- PlayerTextDrawColor(x,PosText[x][1],0xFF5555FF);
- PlayerTextDrawColor(x,PosText[x][2],0xFF5555FF);
- }
- else if(vPos[x]{3} == y && vPos[x]{4} == y && vPos[x]{5} == y)
- {
- PlayerTextDrawColor(x,PosText[x][3],0xFF5555FF);
- PlayerTextDrawColor(x,PosText[x][4],0xFF5555FF);
- PlayerTextDrawColor(x,PosText[x][5],0xFF5555FF);
- // Segunda linha é toda 1 ou 2
- }
- else if(vPos[x]{6} == y && vPos[x]{7} == y && vPos[x]{8} == y)
- {
- PlayerTextDrawColor(x,PosText[x][6],0xFF5555FF);
- PlayerTextDrawColor(x,PosText[x][7],0xFF5555FF);
- PlayerTextDrawColor(x,PosText[x][8],0xFF5555FF);
- // Terceira linha é toda 1 ou 2
- }
- else if(vPos[x]{0} == y && vPos[x]{4} == y && vPos[x]{8} == y)
- {
- // Primeira Diagonal é toda 1 ou 2
- PlayerTextDrawColor(x,PosText[x][0],0xFF5555FF);
- PlayerTextDrawColor(x,PosText[x][4],0xFF5555FF);
- PlayerTextDrawColor(x,PosText[x][8],0xFF5555FF);
- }
- else if(vPos[x]{2} == y && vPos[x]{4} == y && vPos[x]{6} == y)
- {
- // Segunda Diagonal é toda 1 ou 2
- PlayerTextDrawColor(x,PosText[x][2],0xFF5555FF);
- PlayerTextDrawColor(x,PosText[x][4],0xFF5555FF);
- PlayerTextDrawColor(x,PosText[x][6],0xFF5555FF);
- }
- else
- // Ainda sem vencedor
- return 0;
- PlayerTextDrawShow(x,PosText[x][0]);
- PlayerTextDrawShow(x,PosText[x][1]);
- PlayerTextDrawShow(x,PosText[x][2]);
- PlayerTextDrawShow(x,PosText[x][3]);
- PlayerTextDrawShow(x,PosText[x][4]);
- PlayerTextDrawShow(x,PosText[x][5]);
- PlayerTextDrawShow(x,PosText[x][6]);
- PlayerTextDrawShow(x,PosText[x][7]);
- PlayerTextDrawShow(x,PosText[x][8]);
- return 1;
- }
- stock ShowPlayerTicTacToe(playerid)
- {
- TextDrawShowForPlayer(playerid,Textdraw0);
- TextDrawShowForPlayer(playerid,Textdraw1);
- TextDrawShowForPlayer(playerid,Textdraw2);
- TextDrawShowForPlayer(playerid,Textdraw3);
- TextDrawShowForPlayer(playerid,Textdraw4);
- TextDrawShowForPlayer(playerid,VsText);
- UpdateStatsText(playerid);
- for(new i; i < 9; ++i)
- PlayerTextDrawShow(playerid,PosText[playerid][i]);
- PlayerTextDrawShow(playerid,StatsText[playerid]);
- SelectTextDraw(playerid,0x22FF22FF);
- }
- stock HidePlayerTicTacToe(playerid)
- {
- TextDrawHideForPlayer(playerid,Textdraw0);
- TextDrawHideForPlayer(playerid,Textdraw1);
- TextDrawHideForPlayer(playerid,Textdraw2);
- TextDrawHideForPlayer(playerid,Textdraw3);
- TextDrawHideForPlayer(playerid,Textdraw4);
- TextDrawHideForPlayer(playerid,VsText);
- PlayerTextDrawHide(playerid,PosText[playerid][0]);
- PlayerTextDrawHide(playerid,PosText[playerid][1]);
- PlayerTextDrawHide(playerid,PosText[playerid][2]);
- PlayerTextDrawHide(playerid,PosText[playerid][3]);
- PlayerTextDrawHide(playerid,PosText[playerid][4]);
- PlayerTextDrawHide(playerid,PosText[playerid][5]);
- PlayerTextDrawHide(playerid,PosText[playerid][6]);
- PlayerTextDrawHide(playerid,PosText[playerid][7]);
- PlayerTextDrawHide(playerid,PosText[playerid][8]);
- PlayerTextDrawHide(playerid,StatsText[playerid]);
- }
- stock SetRoundValue(playerid,pos)
- {
- vPos[playerid]{pos} = 1;
- }
- stock ZerarJogoDaVelha(playerid)
- {
- for(new i; i < 9; ++i)
- {
- PlayerTextDrawColor(playerid,PosText[playerid][i],0xFFFFFFFF);
- PlayerTextDrawSetString(playerid,PosText[playerid][i],PIECE_ZERO);
- PlayerTextDrawShow(playerid,PosText[playerid][i]);
- vPos[playerid]{i} = 0;
- }
- }
- stock SetRoundRandomValue(playerid)
- {
- new pos;
- // PC Joga aleatorio no inicio
- if(PV[playerid][round] == 1)
- pos = random(9);
- new x = playerid;
- // E nas outras rodadas, inteligencia artificial :D
- // A CPU primeiro tenta vencer
- if(vPos[x]{0} == 2 && !vPos[x]{1} && vPos[x]{2} == 2)
- pos = 1;
- // X X -
- else if(vPos[x]{0} == 2 && vPos[x]{1} == 2 && !vPos[x]{2})
- pos = 2;
- // - X X
- else if(vPos[x]{1} == 2 && vPos[x]{2} == 2 && !vPos[x]{0})
- pos = 0;
- // 0 1 2
- // X - X
- else if(vPos[x]{3} == 2 && !vPos[x]{4} && vPos[x]{5} == 2)
- pos = 4;
- // 0 1 2
- // X X -
- else if(vPos[x]{3} == 2 && vPos[x]{4} == 2 && !vPos[x]{5})
- pos = 5;
- // 0 1 2
- // - X X
- else if(vPos[x]{4} == 2 && !vPos[x]{3} && vPos[x]{5} == 2)
- pos = 3;
- // 0 1 2
- // 3 4 5
- // X - X
- else if(vPos[x]{6} == 2 && !vPos[x]{7} && vPos[x]{8} == 2)
- pos = 7;
- // 0 1 2
- // 3 4 5
- // X X -
- else if(vPos[x]{6} == 2 && vPos[x]{7} == 2 && !vPos[x]{8})
- pos = 8;
- // 0 1 2
- // 3 4 5
- // - X X
- else if(vPos[x]{7} == 2 && vPos[x]{8} == 2 && !vPos[x]{6})
- pos = 6;
- // X 1 2
- // - 4 5
- // X 7 8
- else if(vPos[x]{0} == 2 && !vPos[x]{3} && vPos[x]{6} == 2)
- pos = 3;
- // X 1 2
- // X 4 5
- // - 7 8
- else if(vPos[x]{0} == 2 && vPos[x]{3} == 2 && !vPos[x]{6})
- pos = 6;
- // - 1 2
- // X 4 5
- // X 7 8
- else if(vPos[x]{3} == 2 && vPos[x]{6} == 2 && !vPos[x]{0})
- pos = 0;
- // 0 X 2
- // 3 - 5
- // 6 X 8
- else if(vPos[x]{1} == 2 && !vPos[x]{4} && vPos[x]{7} == 2)
- pos = 4;
- // 0 - 2
- // 3 X 5
- // 6 X 8
- else if(vPos[x]{4} == 2 && !vPos[x]{7} && vPos[x]{7} == 2)
- pos = 1;
- // 0 X 2
- // 3 X 5
- // 6 - 8
- else if(vPos[x]{1} == 2 && vPos[x]{7} == 2 && !vPos[x]{7})
- pos = 7;
- // 0 1 X
- // 3 4 -
- // 6 7 X
- else if(vPos[x]{2} == 2 && !vPos[x]{5} && vPos[x]{8} == 2)
- pos = 5;
- // 0 1 -
- // 3 4 X
- // 6 7 X
- else if(vPos[x]{5} == 2 && !vPos[x]{2} && vPos[x]{8} == 2)
- pos = 2;
- // 0 1 X
- // 3 4 X
- // 6 7 -
- else if(vPos[x]{2} == 2 && vPos[x]{5} == 2 && !vPos[x]{8})
- pos = 8;
- // X 1 2
- // 3 - 5
- // 6 7 X
- else if(vPos[x]{0} ==2 && vPos[x]{8} == 2 && !vPos[x]{4})
- pos = 4;
- // X 1 2
- // 3 X 5
- // 6 7 -
- else if(vPos[x]{0} == 2 && vPos[x]{4} == 2 && !vPos[x]{8})
- pos = 8;
- // - 1 2
- // 3 X 5
- // 6 7 X
- else if(vPos[x]{4} == 2 && vPos[x]{8} == 2 && !vPos[x]{0})
- pos = 0;
- // 0 1 X
- // 3 - 5
- // X 7 8
- else if(vPos[x]{2} == 2 && vPos[x]{6} == 2 && !vPos[x]{4})
- pos = 4;
- // 0 1 X
- // 3 X 5
- // - 7 8
- else if(vPos[x]{2} == 2 && vPos[x]{4} == 2 && !vPos[x]{6})
- pos = 6;
- // 0 1 -
- // 3 X 5
- // X 7 8
- else if(vPos[x]{4} == 2 && vPos[x]{6} == 2 && !vPos[x]{2})
- pos = 2;
- // Senão vai sempre tentar te impedir de fechar a sequencia...
- // X - X
- else if(vPos[x]{0} == 1 && !vPos[x]{1} && vPos[x]{2} == 1)
- pos = 1;
- // X X -
- else if(vPos[x]{0} == 1 && vPos[x]{1} == 1 && !vPos[x]{2})
- pos = 2;
- // - X X
- else if(vPos[x]{1} == 1 && vPos[x]{2} == 1 && !vPos[x]{0})
- pos = 0;
- // 0 1 2
- // X - X
- else if(vPos[x]{3} == 1 && !vPos[x]{4} && vPos[x]{5} == 1)
- pos = 4;
- // 0 1 2
- // X X -
- else if(vPos[x]{3} == 1 && vPos[x]{4} == 1 && !vPos[x]{5})
- pos = 5;
- // 0 1 2
- // - X X
- else if(vPos[x]{4} == 1 && !vPos[x]{3} && vPos[x]{5} == 1)
- pos = 3;
- // 0 1 2
- // 3 4 5
- // X - X
- else if(vPos[x]{6} == 1 && !vPos[x]{7} && vPos[x]{8} == 1)
- pos = 7;
- // 0 1 2
- // 3 4 5
- // X X -
- else if(vPos[x]{6} == 1 && vPos[x]{7} == 1 && !vPos[x]{8})
- pos = 8;
- // 0 1 2
- // 3 4 5
- // - X X
- else if(vPos[x]{7} == 1 && vPos[x]{8} == 1 && !vPos[x]{6})
- pos = 6;
- // X 1 2
- // - 4 5
- // X 7 8
- else if(vPos[x]{0} == 1 && !vPos[x]{3} && vPos[x]{6} == 1)
- pos = 3;
- // X 1 2
- // X 4 5
- // - 7 8
- else if(vPos[x]{0} == 1 && vPos[x]{3} == 1 && !vPos[x]{6})
- pos = 6;
- // - 1 2
- // X 4 5
- // X 7 8
- else if(vPos[x]{3} == 1 && vPos[x]{6} == 1 && !vPos[x]{0})
- pos = 0;
- // 0 X 2
- // 3 - 5
- // 6 X 8
- else if(vPos[x]{1} == 1 && !vPos[x]{4} && vPos[x]{7} == 1)
- pos = 4;
- // 0 - 2
- // 3 X 5
- // 6 X 8
- else if(vPos[x]{4} == 1 && !vPos[x]{7} && vPos[x]{7} == 1)
- pos = 1;
- // 0 X 2
- // 3 X 5
- // 6 - 8
- else if(vPos[x]{1} == 1 && vPos[x]{7} == 1 && !vPos[x]{7})
- pos = 7;
- // 0 1 X
- // 3 4 -
- // 6 7 X
- else if(vPos[x]{2} == 1 && !vPos[x]{5} && vPos[x]{8} == 1)
- pos = 5;
- // 0 1 -
- // 3 4 X
- // 6 7 X
- else if(vPos[x]{5} == 1 && !vPos[x]{2} && vPos[x]{8} == 1)
- pos = 2;
- // 0 1 X
- // 3 4 X
- // 6 7 -
- else if(vPos[x]{2} == 1 && vPos[x]{5} == 1 && !vPos[x]{8})
- pos = 8;
- // X 1 2
- // 3 - 5
- // 6 7 X
- else if(vPos[x]{0} == 1 && vPos[x]{8} == 1 && !vPos[x]{4})
- pos = 4;
- // X 1 2
- // 3 X 5
- // 6 7 -
- else if(vPos[x]{0} == 1 && vPos[x]{4} == 1 && !vPos[x]{8})
- pos = 8;
- // - 1 2
- // 3 X 5
- // 6 7 X
- else if(vPos[x]{4} == 1 && vPos[x]{8} == 1 && !vPos[x]{0})
- pos = 0;
- // 0 1 X
- // 3 - 5
- // X 7 8
- else if(vPos[x]{2} == 1 && vPos[x]{6} == 1 && !vPos[x]{4})
- pos = 4;
- // 0 1 X
- // 3 X 5
- // - 7 8
- else if(vPos[x]{2} == 1 && vPos[x]{4} == 1 && !vPos[x]{6})
- pos = 6;
- // 0 1 -
- // 3 X 5
- // X 7 8
- else if(vPos[x]{4} == 1 && vPos[x]{6} == 1 && !vPos[x]{2})
- pos = 2;
- else
- pos = RandomPos(playerid);
- // Coloca a PIECE_TWO
- format(STR,5,"%s",PIECE_TWO);
- PlayerTextDrawSetString(playerid,PosText[playerid][pos],STR);
- vPos[playerid]{pos} = 2;
- // Verifica se o computador venceu
- if(CheckCombination(playerid,2))
- {
- EndGame(playerid,2);
- }
- else
- {
- // Avança o round
- PV[playerid][round] ++;
- if(PV[playerid][round] == 10)
- {
- EndGame(playerid,0);
- return;
- }
- format(STR,100,"[ROUND %d] É a sua vez de jogar.",PV[playerid][round]);
- SendClientMessage(playerid,0x22FF22FF,STR);
- }
- }
- stock CasaVazia(playerid)
- {
- for(new i; i < 9; ++i)
- {
- if(!vPos[playerid]{i})
- return 1;
- }
- return 0;
- }
- stock RandomPos(playerid)
- {
- new pos;
- while(!pos)
- {
- pos = random(9);
- if(!vPos[playerid]{pos})
- break;
- pos = 0;
- }
- return pos;
- }
- stock EndGame(playerid,winner)
- {
- if(winner == 2)
- {
- SendClientMessage(playerid,0xFF2222FF,"Poxa, você perdeu pro computador :/");
- PV[playerid][losses] ++;
- }
- else if(winner == 1)
- {
- SendClientMessage(playerid,0xFF2222FF,"Boa! Você venceu o jogo da velha!");
- PV[playerid][wins] ++;
- }
- else
- {
- SendClientMessage(playerid,0xFF2222FF,"Eita porra deu velha x.x");
- PV[playerid][draws] ++;
- }
- PV[playerid][round] = 99;
- UpdateStatsText(playerid);
- }
- stock UpdateStatsText(playerid)
- {
- format(STR,100,"~g~W: ~w~%d ~r~L: ~w~%d ~b~D: ~w~%d",PV[playerid][wins],PV[playerid][losses],PV[playerid][draws]);
- PlayerTextDrawSetString(playerid,StatsText[playerid],STR);
- }
- stock pName(playerid)
- {
- new name[24];
- GetPlayerName(playerid,name,24);
- return name;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement