Advertisement
PedroPinheiroUFRN

Jogo da velha - nao comentado

Apr 29th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. //Algoritmo: Jogo da velha
  2. //Função: Fazer um jogo da velha
  3. //Autor: Pedro Pinheiro
  4. //Data: 29/04/2017
  5. programa
  6. {
  7. inclua biblioteca Matematica --> mat
  8. inclua biblioteca Tipos --> tps
  9. inclua biblioteca Graficos --> grf
  10. inclua biblioteca Mouse
  11. inclua biblioteca Util
  12.  
  13. funcao inicio()
  14. {
  15. inteiro matriz[3][3]
  16. inteiro posx, posy, posi, posj
  17. inteiro vet[3]={0, 0, 0}
  18.  
  19.  
  20.  
  21.  
  22. para(inteiro i=0; i<3; i++){
  23. para(inteiro j=0; j<3; j++
  24. ){
  25. matriz[i][j]=0
  26. }
  27. }
  28.  
  29. grf.iniciar_modo_grafico(falso)
  30. grf.definir_dimensoes_janela(500, 650)
  31. grf.definir_cor(grf.COR_BRANCO)
  32.  
  33. grf.desenhar_linha(500/3, 0, 500/3, 600)
  34. grf.desenhar_linha((500/3)*2, 0, (500/3)*2, 600)
  35. grf.desenhar_linha(0, 200, 500, 200)
  36. grf.desenhar_linha(0, 400, 500, 400)
  37. grf.definir_tamanho_texto(50.0)
  38. grf.definir_cor(grf.COR_VERMELHO)
  39. grf.desenhar_texto(0, 600, " ..::Jogo da Velha::..")
  40. grf.renderizar()
  41.  
  42.  
  43. para(inteiro jogadas=1; jogadas<=9; jogadas++){
  44. Mouse.ler_botao()
  45. posx=Mouse.posicao_x()
  46. posy=Mouse.posicao_y()
  47. posi=Tipos.real_para_inteiro(posx/(500/3.0))
  48. posj=Tipos.real_para_inteiro(posy/200.0)
  49. escreva(posx, " ", posy, " ", posi, " ", posj)
  50. se(jogadas%2==1)
  51. matriz[posi][posj]=1
  52. senao
  53. matriz[posi][posj]=2
  54. para(inteiro i=0; i<3; i++){
  55. para(inteiro j=0;j<3; j++){
  56. se(jogadas%2==1)
  57. grf.definir_cor(grf.COR_AZUL)
  58. senao
  59. grf.definir_cor(grf.COR_VERDE)
  60.  
  61. se(matriz[i][j]==1)
  62. grf.desenhar_retangulo(posi*(500/3), posj*200, 500/3, 200, falso, verdadeiro)
  63.  
  64. grf.definir_cor(grf.COR_BRANCO)
  65. grf.desenhar_linha(500/3, 0, 500/3, 600)
  66. grf.desenhar_linha((500/3)*2, 0, (500/3)*2, 600)
  67. grf.desenhar_linha(0, 200, 500, 200)
  68. grf.desenhar_linha(0, 400, 500, 400)
  69. grf.renderizar()
  70.  
  71. se(matriz[0][0]==matriz[1][1] e matriz[0][0]==matriz[2][2] e matriz[0][0]!=0){
  72. grf.encerrar_modo_grafico()
  73. se(jogadas%2==1){
  74. escreva("\n\nJogador AZUL VENCE!")
  75. retorne
  76. }
  77. senao
  78.  
  79. escreva("\n\nJogador VERDE VENCE!")
  80. retorne
  81.  
  82. }
  83. se(matriz[0][2]==matriz[1][1] e matriz[0][2]==matriz[2][0] e matriz[0][2]!=0){
  84. grf.encerrar_modo_grafico()
  85. se(jogadas%2==1){
  86. escreva("\n\nJogador AZUL VENCE!")
  87. retorne
  88. }
  89. senao
  90.  
  91. escreva("\n\nJogador VERDE VENCE!")
  92. retorne
  93. }
  94.  
  95. //ate aqui td certo
  96.  
  97. para(inteiro lin=0; lin<3; lin++){
  98. se(matriz[lin][0]==matriz[lin][1] e matriz[lin][0]==matriz[lin][2] e matriz[lin][0]!=0){
  99. grf.encerrar_modo_grafico()
  100. se(jogadas%2==1){
  101. escreva("\n\nJogador AZUL VENCE!")
  102. retorne
  103. }
  104. senao
  105.  
  106. escreva("\n\nJogador VERDE VENCE!")
  107. retorne
  108. }
  109. }
  110. para(inteiro col=0; col<3; col++){
  111. se(matriz[0][col]==matriz[1][col] e matriz[0][col]==matriz[2][col] e matriz[0][col]!=0){
  112. grf.encerrar_modo_grafico()
  113. se(jogadas%2==1){
  114. escreva("\n\nJogador AZUL VENCE!")
  115. retorne
  116. }
  117. senao
  118.  
  119. escreva("\n\nJogador VERDE VENCE!")
  120. retorne
  121. }
  122. }
  123.  
  124. }
  125. }
  126.  
  127. }
  128. grf.renderizar()
  129. escreva("\n")
  130. para(inteiro i=0; i<3; i++){
  131. para(inteiro j=0; j<3; j++){
  132. escreva(matriz[i][j], "\t")
  133. }
  134. escreva("\n")
  135. }
  136. Mouse.ler_botao()
  137. grf.encerrar_modo_grafico()
  138.  
  139.  
  140. }
  141.  
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement