Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Algoritmo: Jogo da velha
- //Função: Fazer um jogo da velha
- //Autor: Pedro Pinheiro
- //Data: 29/04/2017
- programa
- {
- inclua biblioteca Matematica --> mat
- inclua biblioteca Tipos --> tps
- inclua biblioteca Graficos --> grf
- inclua biblioteca Mouse
- inclua biblioteca Util
- funcao inicio()
- {
- inteiro matriz[3][3]
- inteiro posx, posy, posi, posj
- inteiro vet[3]={0, 0, 0}
- para(inteiro i=0; i<3; i++){
- para(inteiro j=0; j<3; j++
- ){
- matriz[i][j]=0
- }
- }
- grf.iniciar_modo_grafico(falso)
- grf.definir_dimensoes_janela(500, 650)
- grf.definir_cor(grf.COR_BRANCO)
- grf.desenhar_linha(500/3, 0, 500/3, 600)
- grf.desenhar_linha((500/3)*2, 0, (500/3)*2, 600)
- grf.desenhar_linha(0, 200, 500, 200)
- grf.desenhar_linha(0, 400, 500, 400)
- grf.definir_tamanho_texto(50.0)
- grf.definir_cor(grf.COR_VERMELHO)
- grf.desenhar_texto(0, 600, " ..::Jogo da Velha::..")
- grf.renderizar()
- para(inteiro jogadas=1; jogadas<=9; jogadas++){
- Mouse.ler_botao()
- posx=Mouse.posicao_x()
- posy=Mouse.posicao_y()
- posi=Tipos.real_para_inteiro(posx/(500/3.0))
- posj=Tipos.real_para_inteiro(posy/200.0)
- escreva(posx, " ", posy, " ", posi, " ", posj)
- se(jogadas%2==1)
- matriz[posi][posj]=1
- senao
- matriz[posi][posj]=2
- para(inteiro i=0; i<3; i++){
- para(inteiro j=0;j<3; j++){
- se(jogadas%2==1)
- grf.definir_cor(grf.COR_AZUL)
- senao
- grf.definir_cor(grf.COR_VERDE)
- se(matriz[i][j]==1)
- grf.desenhar_retangulo(posi*(500/3), posj*200, 500/3, 200, falso, verdadeiro)
- grf.definir_cor(grf.COR_BRANCO)
- grf.desenhar_linha(500/3, 0, 500/3, 600)
- grf.desenhar_linha((500/3)*2, 0, (500/3)*2, 600)
- grf.desenhar_linha(0, 200, 500, 200)
- grf.desenhar_linha(0, 400, 500, 400)
- grf.renderizar()
- se(matriz[0][0]==matriz[1][1] e matriz[0][0]==matriz[2][2] e matriz[0][0]!=0){
- grf.encerrar_modo_grafico()
- se(jogadas%2==1){
- escreva("\n\nJogador AZUL VENCE!")
- retorne
- }
- senao
- escreva("\n\nJogador VERDE VENCE!")
- retorne
- }
- se(matriz[0][2]==matriz[1][1] e matriz[0][2]==matriz[2][0] e matriz[0][2]!=0){
- grf.encerrar_modo_grafico()
- se(jogadas%2==1){
- escreva("\n\nJogador AZUL VENCE!")
- retorne
- }
- senao
- escreva("\n\nJogador VERDE VENCE!")
- retorne
- }
- //ate aqui td certo
- para(inteiro lin=0; lin<3; lin++){
- se(matriz[lin][0]==matriz[lin][1] e matriz[lin][0]==matriz[lin][2] e matriz[lin][0]!=0){
- grf.encerrar_modo_grafico()
- se(jogadas%2==1){
- escreva("\n\nJogador AZUL VENCE!")
- retorne
- }
- senao
- escreva("\n\nJogador VERDE VENCE!")
- retorne
- }
- }
- para(inteiro col=0; col<3; col++){
- se(matriz[0][col]==matriz[1][col] e matriz[0][col]==matriz[2][col] e matriz[0][col]!=0){
- grf.encerrar_modo_grafico()
- se(jogadas%2==1){
- escreva("\n\nJogador AZUL VENCE!")
- retorne
- }
- senao
- escreva("\n\nJogador VERDE VENCE!")
- retorne
- }
- }
- }
- }
- }
- grf.renderizar()
- escreva("\n")
- para(inteiro i=0; i<3; i++){
- para(inteiro j=0; j<3; j++){
- escreva(matriz[i][j], "\t")
- }
- escreva("\n")
- }
- Mouse.ler_botao()
- grf.encerrar_modo_grafico()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement