tutostudio1

MODELO - JOGO DA FORCA

Apr 12th, 2015
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.08 KB | None | 0 0
  1. package jogo_forca;
  2.  
  3. import java.util.Random;
  4.  
  5. public class Modelo {
  6.  
  7.     private int tamanhof;
  8.     private int tamanhor;
  9.     private int sort;
  10.     private int tipo;
  11.     private boolean vel = false;
  12.     private boolean pla = false;
  13.     private boolean rep = false;
  14.     private int falta = 0;
  15.     private int erros = 0;
  16.     private char[] palavra;
  17.     private String res;
  18.     private String dica;
  19.     private String[][] palavras = {
  20.         {"HAMBURGUER", "PIZZA", "BATATA FRITA", "CACHORRO QUENTE", "LASANHA", "MACARRONADA", "ESCONDIDINHO", "STROGONOFF", "REFRIGERANTE", "SUCO DE LARANJA", "SUCO DE GOIABA", "SUCO DE MARACUJA"},
  21.         {"BOLA", "LÁPIS", "CANETA", "BORRACHA", "PANELA", "FOGAO", "GELADEIRA", "PRATO", "PLACA DE REDE", "HARD DISK", "MONITOR", "FONTE DE ALIMENTACAO"}
  22.     };
  23.     private String[] dicas = {"LANCHES", "COMIDAS", "BEBIDAS", "ESCOLAR", "COZINHA", "COMPUTADOR"};
  24.     private char[] let_errada;
  25.  
  26.     public Modelo() {
  27.         this.let_errada = new char[6];
  28.     }
  29.  
  30.     public void gerar(int tipo) {
  31.         this.tipo = tipo;
  32.         Random gerador = new Random();
  33.         sort = gerador.nextInt(12);
  34.         tamanhor = palavras[tipo][sort].length();
  35.         res = palavras[tipo][sort];
  36.         let_errada[0] = '\0';
  37.     }
  38.  
  39.     public void geraTraco() {
  40.         palavra = new char[tamanhor];
  41.         for (int i = 0; i < tamanhor; i++) {
  42.             if (palavras[tipo][sort].charAt(i) != ' ') {
  43.                 palavra[i] = '_';
  44.             }
  45.         }
  46.     }
  47.  
  48.     public void verifica() {
  49.         if (erros == 6) {
  50.             erros = 0;
  51.             falta = 0;
  52.             pla = false;
  53.         } else if (falta == 0) {
  54.             erros = 0;
  55.             pla = true;
  56.         }
  57.     }
  58.  
  59.     public void procLetra(String letra) {
  60.         rep = false;
  61.         for(int i = 0; i < 6; i++){
  62.             if(let_errada[i]==letra.charAt(0)){
  63.                 rep=true;
  64.             }
  65.         }
  66.         for (int i = 0; i < tamanhor; i++) {
  67.             if (palavras[tipo][sort].charAt(i) == letra.charAt(0)) {
  68.                 if (palavra[i] == '_') {
  69.                     palavra[i] = letra.charAt(0);
  70.                     vel = true;
  71.                     falta--;
  72.                 } else {
  73.                     rep = true;
  74.                 }
  75.             }
  76.         }
  77.         if (vel == false && rep == false) {
  78.             let_errada[erros] = letra.charAt(0);
  79.             erros++;
  80.         }
  81.         vel = false;
  82.     }
  83.  
  84.     public void geraDica() {
  85.         if (tipo == 0) {
  86.             if (sort < 4) {
  87.                 dica = dicas[0];
  88.             } else if (sort < 8) {
  89.                 dica = dicas[1];
  90.             } else if (sort < 12) {
  91.                 dica = dicas[2];
  92.             }
  93.         } else if (tipo == 1) {
  94.             if (sort < 4) {
  95.                 dica = dicas[3];
  96.             } else if (sort < 8) {
  97.                 dica = dicas[4];
  98.             } else if (sort < 12) {
  99.                 dica = dicas[5];
  100.             }
  101.         }
  102.     }
  103.  
  104.     public void calcTamanho() {
  105.         tamanhof = palavras[tipo][sort].length();
  106.         for (int i = 0; i < palavras[tipo][sort].length(); i++) {
  107.             if (palavras[tipo][sort].charAt(i) == ' ') {
  108.                 tamanhof--;
  109.             }
  110.         }
  111.         falta = tamanhof;
  112.     }
  113.  
  114.     public int getTamanhor() {
  115.         return tamanhor;
  116.     }
  117.  
  118.     public void setTamanhor(int tamanho) {
  119.         this.tamanhor = tamanho;
  120.     }
  121.  
  122.     public int getTamanhof() {
  123.         return tamanhof;
  124.     }
  125.  
  126.     public void setTamanhof(int tamanhof) {
  127.         this.tamanhof = tamanhof;
  128.     }
  129.  
  130.     public int getSort() {
  131.         return sort;
  132.     }
  133.  
  134.     public void setSort(int sort) {
  135.         this.sort = sort;
  136.     }
  137.  
  138.     public int getTipo() {
  139.         return tipo;
  140.     }
  141.  
  142.     public void setTipo(int tipo) {
  143.         this.tipo = tipo;
  144.     }
  145.  
  146.     public char[] getPalavra() {
  147.         return palavra;
  148.     }
  149.  
  150.     public void setPalavra(char[] palavra) {
  151.         this.palavra = palavra;
  152.     }
  153.  
  154.     public String getDica() {
  155.         return dica;
  156.     }
  157.  
  158.     public void setDica(String dica) {
  159.         this.dica = dica;
  160.     }
  161.  
  162.     public String getRes() {
  163.         return res;
  164.     }
  165.  
  166.     public void setRes(String res) {
  167.         this.res = res;
  168.     }
  169.  
  170.     public boolean isVel() {
  171.         return vel;
  172.     }
  173.  
  174.     public void setVel(boolean vel) {
  175.         this.vel = vel;
  176.     }
  177.  
  178.     public boolean isPla() {
  179.         return pla;
  180.     }
  181.  
  182.     public void setPla(boolean pla) {
  183.         this.pla = pla;
  184.     }
  185.  
  186.     public int getFalta() {
  187.         return falta;
  188.     }
  189.  
  190.     public void setFalta(int falta) {
  191.         this.falta = falta;
  192.     }
  193.  
  194.     public int getErros() {
  195.         return erros;
  196.     }
  197.  
  198.     public void setErros(int erros) {
  199.         this.erros = erros;
  200.     }
  201.  
  202.     public char[] getLet_errada() {
  203.         return let_errada;
  204.     }
  205.  
  206.     public void setLet_errada(char[] let_errada) {
  207.         this.let_errada = let_errada;
  208.     }
  209.  
  210.     public boolean isRep() {
  211.         return rep;
  212.     }
  213.  
  214.     public void setRep(boolean rep) {
  215.         this.rep = rep;
  216.     }
  217.  
  218. }
Advertisement
Add Comment
Please, Sign In to add comment