Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.24 KB | None | 0 0
  1. //What is the Word
  2. //Version 1.0
  3. //Created By Mitchell Hoyt
  4. //Created on 04-13-2017
  5. import hsa.*;
  6. public class GuesstheWord{
  7. public static void main(String [] args){
  8. Console con = new Console();
  9. int intRand;
  10. char chrStart;
  11. con.println(" Guess the Word");
  12. con.println(" By:Mitchell Hoyt");
  13. con.println(" Hit enter to begin");
  14. chrStart = con.readChar();
  15. int intLength;
  16. intRand = (int)(Math.random()*20+1);
  17. String strMystery;
  18. strMystery = "";
  19. String strLetterCorrect;
  20. strLetterCorrect = "";
  21. String strWord;
  22. strWord = "";
  23. String strGuess;
  24. int intLettersGuessed;
  25. intLettersGuessed = 0;
  26. int intPoints;
  27.  
  28. //determining what word to choose
  29. if( intRand == 1){
  30. strMystery = "uncopyrightable";
  31. }if(intRand == 2){
  32. strMystery= "jason";
  33. }if(intRand == 3){
  34. strMystery= "mitchell";
  35. }if(intRand == 4){
  36. strMystery= "working";
  37. }if(intRand == 5){
  38. strMystery= "kingston";
  39. }if(intRand == 6){
  40. strMystery= "toronto";
  41. }if(intRand == 7){
  42. strMystery= "supercalifragilisticexpialidocious";
  43. }if(intRand == 8){
  44. strMystery= "canada";
  45. }if(intRand == 9){
  46. strMystery= "montreal";
  47. }if(intRand == 10){
  48. strMystery= "pencil";
  49. }if(intRand == 11){
  50. strMystery= "eraser";
  51. }if(intRand == 12){
  52. strMystery= "water";
  53. }if(intRand == 13){
  54. strMystery= "keyboard";
  55. }if(intRand == 14){
  56. strMystery= "computer";
  57. }if(intRand == 15){
  58. strMystery= "monitor";
  59. }if(intRand == 16){
  60. strMystery= "Sodium";
  61. }if(intRand == 17){
  62. strMystery= "compsci";
  63. }if(intRand == 18){
  64. strMystery = "magnetic";
  65. }if(intRand == 19){
  66. strMystery= "hockey";
  67. }if(intRand == 20){
  68. strMystery = "guitar";
  69. }
  70.  
  71.  
  72.  
  73. intLength = strMystery.length();
  74. intPoints = intLength;
  75. //making the loop variable until they runout of points or
  76.  
  77.  
  78. //have that letter read each letter in the word and see if it matches
  79. int intCount12;
  80. int intCount;
  81. int intCount2 = 0;
  82. String strLetterofWord;
  83. //con.println(strMystery);
  84. String strstar;
  85. String strPrevious = ""; //!!!!!!!mog
  86. String strNewword = "";
  87.  
  88. //the code will keep running until the user will run out of points or guess the letters of the word
  89. while(intLength > intLettersGuessed && intPoints > 0){
  90.  
  91. con.println("you have " +intPoints+ " points");
  92. con.println("guess a letter which may be apart of the word");
  93. int intCount1 =0;
  94. strGuess = con.readLine();
  95. strstar = "";
  96. strNewword = ""; //!!!!!!!mog
  97.  
  98. //when the person guess' the letter it will run through a for loop and will run through each letter to see if it is a match
  99. for(intCount = 0; intCount < intLength-1; intCount++){
  100.  
  101.  
  102. strLetterofWord = strMystery.substring(intCount,intCount+1);
  103.  
  104. if(strLetterofWord.equals(strGuess)){
  105. strstar = strGuess;
  106. con.print(strstar);
  107. intCount1++;
  108. intLettersGuessed = intLettersGuessed + 1;
  109. strNewword = strNewword + strGuess; //!!!!!!!mog
  110. }else if(strLetterofWord.equals(strPrevious.substring(intCount, intCount+1)) && strPrevious.length() > 1){ //!!!!!!!mog
  111. strstar = strGuess;//!!!!!!!mog
  112. strNewword = strNewword + strGuess; //!!!!!!!mog
  113. }else{
  114.  
  115. strstar = "*";
  116. con.print(strstar);
  117. strNewword = strNewword + "*"; //!!!!!!!mog
  118.  
  119. }
  120. }
  121.  
  122. strPrevious = strNewword; //!!!!!!!mog
  123.  
  124. if(!strstar.equals("*")){
  125. con.print(strGuess);
  126. }else{
  127. con.print("*");
  128. }
  129. //determines if the user will lose points or not
  130. if(intCount1 == 0){
  131. intPoints = intPoints -1;
  132. }else{
  133. intPoints = intPoints;
  134.  
  135. }if(intLength == intLettersGuessed){
  136. con.println("you guessed the mystery word which is: " +strMystery);
  137. }if(intPoints ==0){
  138. con.println("game over the word was: " +strMystery);
  139. }
  140.  
  141.  
  142. }
  143.  
  144.  
  145.  
  146. }
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement