0

I am new to programming and I'm trying to make a Hangman game with the console in Java for the High School but I'm having difficulties... I have a problem, because I made a Scanner for putting the film but when I put the film, if the film contain spaces it gives me an error... I need a hand please, write me for more information and suggestions please and thanks.

Sorry for my English, I think it's not very good. :/

I know that is missing a lot to finish but here's all the code:

package proyectoFinal;

import java.util.Scanner;

public class Proyecto {

public static void main(String[] args) {
    Scanner input = new Scanner(System.in);

    int opcionMenu = 10;
    String pelicula = "No hay pelicula";
    char letra;
    String espacios;


    while (opcionMenu != 0){
        System.out.println("...............................................\n"
                        + "\tOpcion \"1\" --- Ingresar Pelicula \n"
                        + "\tOpcion \"2\" --- Jugar \n"
                        + "\tOpcion \"3\" --- Salir \n"
                        + "...............................................");
        opcionMenu = input.nextInt();



        switch (opcionMenu){
            case 1 :    System.out.println("Ingresar pelicula.");
                        pelicula = (String) input.next();


                        System.out.println("la pelicula es: " + pelicula + ".");
                        System.out.println("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
                                        +  "\n\n\n\n\n\n\n\n\n");
                        System.err.println("El nombre de la pelicula esta arriba ");
                        break;
            case 2 :    if(pelicula != "No hay pelicula"){


                            System.out.println("La pelicula tiene " + pelicula.length() + " letras");

                            for (int i = 0; i < pelicula.length(); i++) {
                                letra = pelicula.charAt(i);
                            }


                        }else{
                            System.out.println("Se debe ingresar la pelicula antes de JUGAR.");
                        }
                        break;

            case 3 : break ;

            default: System.err.println("LA OPCION ELEGIDA NO ES CORRECTA");
        }

    }




    System.out.println("Se ha salido del juego");




}

private static void dibujar(int i) {
    switch (i) {
        case 6:
            System.out.println("------"
                            +  "|    "
                            +  "|   "
                            +  "|   "
                            +  "|"
                            +  "--------");
            break;

        case 5:
            System.out.println("------"
                            +  "|    O"
                            +  "|"
                            +  "|"
                            +  "|"
                            +  "--------");
            break;

        case 4:
            System.out.println("------"
                            +  "|    O"
                            +  "|    |"
                            +  "|"
                            +  "|"
                            +  "--------");               break;

        case 3:
            System.out.println("------"
                            +  "|    O"
                            +  "|    |\\"
                            +  "|"
                            +  "|"
                            +  "--------");
            break;

        case 2:System.out.println("------"
                                + "|     O"
                                + "|    /|\\"
                                + "|"
                                + "|"
                                + "--------");
           break;

        case 1:System.out.println("------"
                                + "|     O"
                                + "|    /|\\"
                                + "|      \\"
                                + "|"
                                + "--------");
           break;

        case 0:System.out.println("------"
                                + "|     O"
                                + "|    /|\\"
                                + "|    / \\"
                                + "|"
                                + "--------");
            System.out.println("\n"
                                +"_____________________");
            System.err.println("GAME OVER");
            break;
    }
}   
}

0 Answers0