Answer the question
In order to leave comments, you need to log in
Console game in Dice, how to implement the ability to choose between exiting the game and continuing it?
Good day. Implemented a simple console dice game, it has a choice between three game modes - One opponent, two opponents, a game with yourself. If you lose, the game gives "Truth or Dare", but it's not that important. The game functions, happy as a cat. Unfortunately, I ran into the problem of completing the last item of the game's feature. Namely, the choice is to continue the game (thus resuming the main method of the game) or exit (not by simply pressing the red cross on the console, but by entering the conditional Yes).
package com.DiceGameTruthOrDare;
import java.util.Scanner;
import static java.lang.System.*;
import static java.lang.Math.*;
public class DiceGameTruthOrDare {
//main method the game
public static void main(String[] args) {
out.println("Welcome to the game!");
//out.println(TruthOrDare.TruthOrDare()); //array chek
GameMode.modeChoice();
}
}
Answer the question
In order to leave comments, you need to log in
Good afternoon.
Inside the method, a while () loop is created, inside which you listen to the input (Scanner) and if the desired command was entered, then do System.exit (n)
Well, do not forget to handle exceptions so that, for example, the application does not exit on an incorrect or non-existent command
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question