Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //What is the Word
- //Version 1.0
- //Created By Mitchell Hoyt
- //Created on 04-13-2017
- import hsa.*;
- public class GuesstheWord{
- public static void main(String [] args){
- Console con = new Console();
- int intRand;
- char chrStart;
- con.println(" Guess the Word");
- con.println(" By:Mitchell Hoyt");
- con.println(" Hit enter to begin");
- chrStart = con.readChar();
- int intLength;
- intRand = (int)(Math.random()*20+1);
- String strMystery;
- strMystery = "";
- String strLetterCorrect;
- strLetterCorrect = "";
- String strWord;
- strWord = "";
- String strGuess;
- int intLettersGuessed;
- intLettersGuessed = 0;
- int intPoints;
- //determining what word to choose
- if( intRand == 1){
- strMystery = "uncopyrightable";
- }if(intRand == 2){
- strMystery= "jason";
- }if(intRand == 3){
- strMystery= "mitchell";
- }if(intRand == 4){
- strMystery= "working";
- }if(intRand == 5){
- strMystery= "kingston";
- }if(intRand == 6){
- strMystery= "toronto";
- }if(intRand == 7){
- strMystery= "supercalifragilisticexpialidocious";
- }if(intRand == 8){
- strMystery= "canada";
- }if(intRand == 9){
- strMystery= "montreal";
- }if(intRand == 10){
- strMystery= "pencil";
- }if(intRand == 11){
- strMystery= "eraser";
- }if(intRand == 12){
- strMystery= "water";
- }if(intRand == 13){
- strMystery= "keyboard";
- }if(intRand == 14){
- strMystery= "computer";
- }if(intRand == 15){
- strMystery= "monitor";
- }if(intRand == 16){
- strMystery= "Sodium";
- }if(intRand == 17){
- strMystery= "compsci";
- }if(intRand == 18){
- strMystery = "magnetic";
- }if(intRand == 19){
- strMystery= "hockey";
- }if(intRand == 20){
- strMystery = "guitar";
- }
- intLength = strMystery.length();
- intPoints = intLength;
- //making the loop variable until they runout of points or
- //have that letter read each letter in the word and see if it matches
- int intCount12;
- int intCount;
- int intCount2 = 0;
- String strLetterofWord;
- //con.println(strMystery);
- String strstar;
- String strPrevious = ""; //!!!!!!!mog
- String strNewword = "";
- //the code will keep running until the user will run out of points or guess the letters of the word
- while(intLength > intLettersGuessed && intPoints > 0){
- con.println("you have " +intPoints+ " points");
- con.println("guess a letter which may be apart of the word");
- int intCount1 =0;
- strGuess = con.readLine();
- strstar = "";
- strNewword = ""; //!!!!!!!mog
- //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
- for(intCount = 0; intCount < intLength-1; intCount++){
- strLetterofWord = strMystery.substring(intCount,intCount+1);
- if(strLetterofWord.equals(strGuess)){
- strstar = strGuess;
- con.print(strstar);
- intCount1++;
- intLettersGuessed = intLettersGuessed + 1;
- strNewword = strNewword + strGuess; //!!!!!!!mog
- }else if(strLetterofWord.equals(strPrevious.substring(intCount, intCount+1)) && strPrevious.length() > 1){ //!!!!!!!mog
- strstar = strGuess;//!!!!!!!mog
- strNewword = strNewword + strGuess; //!!!!!!!mog
- }else{
- strstar = "*";
- con.print(strstar);
- strNewword = strNewword + "*"; //!!!!!!!mog
- }
- }
- strPrevious = strNewword; //!!!!!!!mog
- if(!strstar.equals("*")){
- con.print(strGuess);
- }else{
- con.print("*");
- }
- //determines if the user will lose points or not
- if(intCount1 == 0){
- intPoints = intPoints -1;
- }else{
- intPoints = intPoints;
- }if(intLength == intLettersGuessed){
- con.println("you guessed the mystery word which is: " +strMystery);
- }if(intPoints ==0){
- con.println("game over the word was: " +strMystery);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement