Untitled
unknown
plain_text
5 months ago
3.6 kB
5
Indexable
import java.util.*; public class DDA { public static final String[] ACTIONS = {"☔", "⛲", "🐾", "🍒", "🏈"}; public static final String[] RESPONSES = {"UMBRELLA", "FOUNTAIN", "PAWS", "CHERRIES", "FOOTBALL"}; public static final String STAR = "⭐"; public static void main(String[] args) { Scanner console = new Scanner(System.in); Random rand = new Random(); creativeExtention(console, rand); showActions(); String[] moves = makeMoves(console, rand); double score = playGame(console, moves); endScreen(score, moves.length); } public static void showActions() { System.out.println("Welcome to Dance Dance Arrayvolution!"); System.out.println(); System.out.println("These are the possible actions and their correct responses:"); for(int i = 0; i < ACTIONS.length; i++) { System.out.println(ACTIONS[i] + ": " + RESPONSES[i]); } System.out.println(); } public static String[] makeMoves(Scanner console, Random moves, int mode) { System.out.print("How many moves would you like to play? "); int num = console.nextInt(); System.out.println(); String[] numMoves = new String[num]; for(int i = 0; i < numMoves.length; i++) { int randMove = moves.nextInt(ACTIONS.length); numMoves[i] = ACTIONS[randMove]; } return numMoves; } public static int getActionIndex(String matchAction) { for(int i = 0; i < ACTIONS.length; i++) { if(ACTIONS[i].equals(matchAction)) { return i; } } return -1; } public static double playGame(Scanner console, String[] playMoves) { double score = 0; System.out.println("Let's Dance!"); for(int i = 0; i < playMoves.length; i++) { System.out.print("("+ (i+1) + ") " + playMoves[i] + ": "); String userInput = console.next().toUpperCase(); int actionIndex = getActionIndex(playMoves[i]); String correctResponse = RESPONSES[actionIndex].toUpperCase(); if(userInput.equals(correctResponse)) { score += 1.0; } else if(userInput.contains(correctResponse)) { score += 0.5; } } System.out.println(); return score; } public static void endScreen(double score, int maxScore){ double percentage = (score/maxScore) * 100; int stars; if(percentage == 100) { stars = 5; } else if(percentage >= 80) { stars = 4; } else if(percentage >= 60) { stars = 3; } else if(percentage >= 40) { stars = 2; } else if(percentage >= 20) { stars = 1; } else { stars = 1; } System.out.println("Woah that was groovy!"); System.out.print("You Scored: "); for(int i = 0; i < stars; i++) { System.out.print(STAR); } System.out.print(" (" + score + "/" + maxScore + ")"); System.out.println(); System.out.println("Thanks for playing!"); } public static String[] creativeExtention(Scanner console, Random actions) { System.out.print("Enter 1 to play the easy mode or enter 2 to play the hard mode: "); int mode = console.nextInt(); System.out.println(); makeMoves() } }
Editor is loading...
Leave a Comment