Skip to content

Commit

Permalink
Change game
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSorb committed Jan 21, 2024
1 parent 0bd30f1 commit 2dacb82
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
22 changes: 22 additions & 0 deletions app/src/main/java/hexlet/code/games/Even.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,42 @@ public Even() {
this.rightAnswer = isEven(currentNumber) ? "yes" : "no";
}

/**
* Method returns the game rule for the GCD game.
* @return game rule.
*/
public String getGameRules() {
return "Answer 'yes' if the number is even, otherwise answer 'no'.";
}

/**
* The method returns a question for the user.
* @return question for user.
*/
public String getQuestion() {
return Integer.toString(currentNumber);
}

/**
* The method returns the correct answer.
* @return right answer
*/
public String getRightAnswer() {
return rightAnswer;
}

/**
* The method returns true if the correct answer is given.
* @param userAnswer
* @return true if the answer is correct
*/
public boolean isRightAnswer(String userAnswer) {
return userAnswer.equalsIgnoreCase(rightAnswer);
}

/**
* The method sets new parameters for the game.
*/
public void changeQuestion() {
currentNumber = Engine.randomIntValue();
rightAnswer = isEven(currentNumber) ? "yes" : "no";
Expand Down
21 changes: 21 additions & 0 deletions app/src/main/java/hexlet/code/games/Progression.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,18 @@ public Progression() {
changeQuestion();
}

/**
* Method returns the game rule for the Progression game.
* @return game rule.
*/
public String getGameRules() {
return "What number is missing in the progression?";
}

/**
* The method returns a question for the user.
* @return question for user.
*/
public String getQuestion() {
StringBuilder result = new StringBuilder();
for (int i = 0; i < progression.length; i++) {
Expand All @@ -27,14 +36,26 @@ public String getQuestion() {
return result.toString().trim();
}

/**
* The method returns the correct answer.
* @return right answer
*/
public String getRightAnswer() {
return Integer.toString(this.rightAnswer);
}

/**
* The method returns true if the correct answer is given.
* @param userAnswer
* @return true if the answer is correct
*/
public boolean isRightAnswer(String userAnswer) {
return userAnswer.equalsIgnoreCase(Integer.toString(this.rightAnswer));
}

/**
* The method sets new parameters for the game.
*/
public void changeQuestion() {
final int leftBorder = 5;
final int rightBorder = 10;
Expand Down

0 comments on commit 2dacb82

Please sign in to comment.