Я пишу программу для проверки следующих сценариев:
Сценарий 1:
Я использую класс Random из java.util.Случайный класс сгенерирует 10 букв из z и в пределах 10 букв, минимум 2 буквы должны быть гласными.
Сценарий 2:
Когда игрок 1 и игрок 2 образуют слово из AZон наберет несколько очков.Там будет оценка для каждой буквы.Я уже назначил значения для AZ.В конце игры система должна отображать баллы для игрока 1 и игрока 2. Как мне это сделать?
Пожалуйста, помогите.Я опубликую свой код здесь.
Большое спасибо.
===========================================
import java.util.Random;
import java.util.Scanner;
public class FindYourWords {
public static void main(String[] args) {
Random rand = new Random();
Scanner userInput = new Scanner(System.in);
//==================Player object===============================================
Player playerOne = new Player();
playerOne.wordScore = 0;
playerOne.choice = "blah";
playerOne.turn = true;
Player playerTwo = new Player();
playerTwo.wordScore = 0;
playerTwo.choice = "blah";
playerTwo.turn = false;
//================== Alphabet ==================================================
String[] newChars = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
"n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"
}; //values of the 26 alphabets to be used
int [] letterScore = {1,3,3,2,1,4,2,4,1,8,5,1,3,1,1,3,10,1,1,1,1,4,4,8,4,10}; // to assign score to the player1 and player 2
String[] vowel = { "a", "e", "i", "o", "u" }; // values for vowels
int vow=0;
System.out.println("FINDYOURWORDS\n");
int[] arrayRandom = new int[10]; //int array for word limiter
String[] randomLetter = new String[10]; //storing the letters in newChars into this array
//===============================================================================
boolean cont = true;
while (cont) {
if (playerOne.turn) {
System.out.print("Letters of Player 1: ");
}
else if (!playerOne.turn) {
System.out.print("Letters of Player 2: ");
}
for (int i = 0; i < arrayRandom.length; i++) { //running through the array limiter
int r = rand.nextInt(newChars.length); //assigning random nums to the array of letters
randomLetter[i] = newChars[r];
System.out.print(randomLetter[i]+ " ");
}
//input section for player
System.out.println("");
System.out.println("Enter your word (or '@' to pass or '!' to quit): ");
if (playerOne.turn) {
playerOne.choice = userInput.next();
System.out.println(playerOne.turn);
playerOne.turn = false;
}
else if (!playerOne.turn){
playerTwo.choice = userInput.next();
System.out.println(playerOne.turn);
playerOne.turn = true;
}
//System.out.println(choice);
String[] wordList = FileUtil.readDictFromFile("words.txt"); //Still dunno what this is for
if (playerOne.choice.equals("@")) {
playerOne.turn = false;
}
else if (playerTwo.choice.equals("@")) {
playerOne.turn = true;
}
else if (playerOne.choice.equals("!")) {
cont = false;
}
for (int i = 0; i < wordList.length; i++) {
//System.out.println(wordList[i]);
if (playerOne.choice.equalsIgnoreCase(wordList[i]) || playerTwo.choice.equalsIgnoreCase(wordList[i])){
}
}
}
}}