Guest User

Untitled

a guest
Jul 30th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.48 KB | None | 0 0
  1. package models;
  2. import java.util.Random;
  3. import models.EnumWords;
  4.  
  5. public class Hangman {
  6. //CONSTANTS
  7. public static EnumWords word;
  8. //Attributes
  9. //1st Constructor
  10. public Hangman() {
  11. setWord(EnumWords.NOTEXT);
  12. }
  13. //2nd Constructor
  14. public Hangman(EnumWords word) {
  15. setWord(word);
  16. }
  17. public EnumWords wordsSelect() {
  18. Random wordRandom = new Random();
  19. int wordOfGame = 1 + wordRandom.nextInt(16);
  20. switch(wordOfGame){
  21. case 1 : word = EnumWords.ALGORITMO; break;
  22. case 2 : word = EnumWords.BOYACÁ; break;
  23. case 3 : word = EnumWords.CLASE; break;
  24. case 4 : word = EnumWords.COMPUTADOR; break;
  25. case 5 : word = EnumWords.DIFÍCIL; break;
  26. case 6 : word = EnumWords.GUERRA; break;
  27. case 7 : word = EnumWords.INTERNET; break;
  28. case 8 : word = EnumWords.JAVA; break;
  29. case 9 : word = EnumWords.LEER; break;
  30. case 10 : word = EnumWords.NADA; break;
  31. case 11 : word = EnumWords.PROGRAMACIÓN; break;
  32. case 12 : word = EnumWords.SANGRE; break;
  33. case 13 : word = EnumWords.TUNJA; break;
  34. case 14 : word = EnumWords.INGENIERIA; break;
  35. case 15 : word = EnumWords.UPTC; break;
  36. case 16 : word = EnumWords.SISTEMAS; break;
  37. }
  38. return word;
  39. }
  40. public String WordLine(String word){
  41. EnumWords text = wordsSelect();
  42. word = text.toString();
  43. String auxWord = word;
  44. int large = word.length()*2;
  45. String change = "_ ";
  46. while(change.length()< large){
  47. change += "_ ";
  48. }
  49. auxWord = change;
  50. return auxWord;
  51.  
  52. }
  53. //Setter
  54.  
  55. public void setWord(EnumWords word) {
  56. this.word = word;
  57. }
  58. //Getter
  59. public EnumWords getWord() {
  60. return word;
  61. }
  62. }
  63.  
  64. package views;
  65. import models.Hangman;
  66. import models.EnumWords;
  67.  
  68. import java.util.Scanner;
  69.  
  70. public class HangmanForm{
  71. private static Scanner readerString = new Scanner (System.in);
  72.  
  73. public static Hangman build(){
  74. System.out.println("+------------------------------------------+");
  75. System.out.println("| EL AHORCADO |");
  76. System.out.println("+------------------------------------------+");
  77. System.out.println("+------------------------------------------+");
  78. Hangman object1 = new Hangman();
  79. EnumWords text = object1.wordsSelect();
  80. String sentence = text.toString();
  81. String auxWord = object1.WordLine(sentence);
  82. System.out.println(sentence);
  83. System.out.println(auxWord);
  84. int lives = 7;
  85. int countWin = 0;
  86. while (lives != 0) {
  87. System.out.print("Ingrese una letra:");
  88. String letter = readerString.nextLine().toUpperCase();
  89. char charLetter = letter.charAt(0);
  90. for (int x = 0; x < sentence.length(); x++) {
  91. if (sentence.toUpperCase().charAt(x) == charLetter) {
  92. countWin++;
  93. auxWord = cambiarString(auxWord,charLetter,x*2);
  94. System.out.println("Puntos Buenos :" + countWin);
  95. System.out.println(auxWord);
  96. }
  97. if (sentence.toUpperCase().charAt(x) != charLetter) {
  98. lives--;
  99. break;
  100. }
  101. }
  102. print(lives);
  103. }
  104. if(lives == 0)
  105. System.out.println("La palabra era: " + sentence);
  106. Hangman hang = new Hangman();
  107. System.out.println("___________________________________________");
  108. System.out.println(" Realizado por YG");
  109. return hang;
  110. }
  111.  
  112.  
  113. public static void print(int lives){
  114. if(lives == 6){
  115. System.out.println(" ---------------------¬");
  116. System.out.println(" | |");
  117. System.out.println(" | |");
  118. System.out.println(" | ");
  119. System.out.println(" | ");
  120. System.out.println(" | ");
  121. System.out.println(" | ");
  122. System.out.println(" | ");
  123. System.out.println(" | ");
  124. System.out.println(" | ");
  125. System.out.println(" | ");
  126. System.out.println(" | ");
  127. System.out.println(" | ");
  128. System.out.println(" | ");
  129. System.out.println(" | ");
  130. System.out.println(" ______________");
  131. }
  132. else if(lives == 5){
  133. System.out.println(" ---------------------¬");
  134. System.out.println(" | |");
  135. System.out.println(" | |");
  136. System.out.println(" | -------");
  137. System.out.println(" | | - - |");
  138. System.out.println(" | | o |");
  139. System.out.println(" | -------");
  140. System.out.println(" | ");
  141. System.out.println(" | ");
  142. System.out.println(" | ");
  143. System.out.println(" | ");
  144. System.out.println(" | ");
  145. System.out.println(" | ");
  146. System.out.println(" | ");
  147. System.out.println(" | ");
  148. System.out.println(" ______________");
  149. }
  150. else if(lives == 4){
  151. System.out.println(" ---------------------¬");
  152. System.out.println(" | |");
  153. System.out.println(" | |");
  154. System.out.println(" | -------");
  155. System.out.println(" | | - - |");
  156. System.out.println(" | | o |");
  157. System.out.println(" | -------");
  158. System.out.println(" | | ");
  159. System.out.println(" | | ");
  160. System.out.println(" | | ");
  161. System.out.println(" | | ");
  162. System.out.println(" | | ");
  163. System.out.println(" | ");
  164. System.out.println(" | ");
  165. System.out.println(" | ");
  166. System.out.println(" ______________");
  167. }
  168. else if(lives == 3){
  169. System.out.println(" ---------------------¬");
  170. System.out.println(" | |");
  171. System.out.println(" | |");
  172. System.out.println(" | -------");
  173. System.out.println(" | | - - |");
  174. System.out.println(" | | o |");
  175. System.out.println(" | -------");
  176. System.out.println(" | | ");
  177. System.out.println(" | / | ");
  178. System.out.println(" | / | ");
  179. System.out.println(" | / | ");
  180. System.out.println(" | | ");
  181. System.out.println(" | ");
  182. System.out.println(" | ");
  183. System.out.println(" | ");
  184. System.out.println(" ______________");
  185. }
  186. else if(lives == 2){
  187. System.out.println(" ---------------------¬");
  188. System.out.println(" | |");
  189. System.out.println(" | |");
  190. System.out.println(" | -------");
  191. System.out.println(" | | - - |");
  192. System.out.println(" | | o |");
  193. System.out.println(" | -------");
  194. System.out.println(" | | ");
  195. System.out.println(" | / | \ ");
  196. System.out.println(" | / | \ ");
  197. System.out.println(" | / | \ ");
  198. System.out.println(" | | ");
  199. System.out.println(" | ");
  200. System.out.println(" | ");
  201. System.out.println(" | ");
  202. System.out.println(" ______________");
  203. }
  204. else if(lives == 1){
  205. System.out.println(" ---------------------¬");
  206. System.out.println(" | |");
  207. System.out.println(" | |");
  208. System.out.println(" | -------");
  209. System.out.println(" | | - - |");
  210. System.out.println(" | | o |");
  211. System.out.println(" | -------");
  212. System.out.println(" | | ");
  213. System.out.println(" | / | \ ");
  214. System.out.println(" | / | \ ");
  215. System.out.println(" | / | \ ");
  216. System.out.println(" | | ");
  217. System.out.println(" | / ");
  218. System.out.println(" | / ");
  219. System.out.println(" | / ");
  220. System.out.println(" ______________");
  221. }
  222. else if(lives == 0){
  223. System.out.println(" ---------------------");
  224. System.out.println(" | |");
  225. System.out.println(" | |");
  226. System.out.println(" | -------");
  227. System.out.println(" | | X X |");
  228. System.out.println(" | | o |");
  229. System.out.println(" | -------");
  230. System.out.println(" | | ");
  231. System.out.println(" | / | \ ");
  232. System.out.println(" | / | \ ");
  233. System.out.println(" | / | \ ");
  234. System.out.println(" | | ");
  235. System.out.println(" | / \");
  236. System.out.println(" | / \ ");
  237. System.out.println(" | / \ ");
  238. System.out.println(" ______________");
  239. System.out.println("GAME OVER");
  240. }
  241. }
  242. public static String cambiarString(String sentence,char newChar,int index) {
  243. char[] sequence = sentence.toCharArray();
  244. sequence[index] = newChar;
  245. return new String(sequence);
  246. }
  247. }
Add Comment
Please, Sign In to add comment