fixed: some bugs

This commit is contained in:
lzh
2024-05-13 01:20:39 +08:00
parent 0d0e19670d
commit 5a5005f68f
7 changed files with 37 additions and 35 deletions
+4
View File
@@ -0,0 +1,4 @@
3*2+1=7
5-3+2=4
9-2+1=8
6/3+4=6
@@ -5,7 +5,7 @@ public interface INumberleModel{
int Attempt = 6;
void StartGame();
void StartGame(String oldTarget);
boolean processInput(String input);
boolean isGameOver();
boolean isGameWon();
@@ -19,10 +19,9 @@ public interface INumberleModel{
StringBuilder getCurrentGuess();
int getRemainingAttempts();
void setRemainingAttempts(int val);
boolean startNewGame();
boolean startNewGame(String oldTarget);
void Delete();
}
+5 -5
View File
@@ -29,22 +29,22 @@ public class Junit {
}
@Test
public void ProcessInput(){
model.StartGame();
model.StartGame("");
assertFalse(model.processInput(""));
assertFalse(model.processInput("3*2=2*8"));
assertFalse(model.isGameWon());
}
@Test
public void Remove_EmptyGuess() {
model.StartGame();
model.StartGame("");
assertEquals(0, model.getCurrentGuess().length());
}
@Test
public void StartNewGame() {
model.StartGame();
model.StartGame("");
String oldTargetWord = model.getTargetWord();
model.startNewGame();
model.startNewGame(oldTargetWord);
assertNotEquals(oldTargetWord, model.getTargetWord());
}
@@ -53,7 +53,7 @@ public class Junit {
@Test
public void testProcessInput_InvalidEquation() {
model.setFlag3(true);
model.StartGame();
model.StartGame("");
assertFalse(model.processInput("1+2=2+3"));
assertFalse(model.isGameWon());
}
+2 -2
View File
@@ -76,7 +76,7 @@ public class NumberleCLI {
return scanner.nextLine();
}
private static void GameStatue() {
System.out.println("the target equation: " + model.getTargetWord());
// System.out.println("the target equation: " + model.getTargetWord());
System.out.println("you have : " + model.getRemainingAttempts()+" "+"chances");
System.out.println("your input guess is : " + model.getCurrentGuess());
printCategories();
@@ -112,7 +112,7 @@ public class NumberleCLI {
return Double.compare(leftResult, rightResult) == 0;
}
public static void main(String[] args) {
model.startNewGame();
model.startNewGame("");
GameStart();
}
}
@@ -2,7 +2,7 @@ package org.example;
public class NumberleController {
private NumberleView view;
private INumberleModel model;
public NumberleController(INumberleModel model) {
@@ -12,13 +12,13 @@ public class NumberleController {
return model.getRemainingAttempts();
}
public void startNewGame() {
model.startNewGame();
model.startNewGame("");
}
public void SetFlag(Boolean Flag3){
model.setFlag3(Flag3);
if (Flag3==true){
if (Flag3){
model.setTargetword("3*2+1=7");
}
@@ -31,14 +31,11 @@ public class NumberleController {
}
public void setFlag2(Boolean Flag){
if (Flag==true){
if (Flag){
System.out.println(getTargetWord());
}
}
public void setView(NumberleView view) {
this.view = view;
}
public String getTargetWord() {
return model.getTargetWord();
}
@@ -55,7 +52,5 @@ public class NumberleController {
return model.isGameWon();
}
public void setTargetWord(){
}
}
+18 -14
View File
@@ -24,14 +24,18 @@ public class NumberleModel extends java.util.Observable implements INumberleMode
//Start new game you should know this function just from txt file to select the words
//which is random to select
public void StartGame(){
public void StartGame(String oldTarget){
this.FileRead();
if (List == null || List.isEmpty()) {
System.out.println("The list is null or empty. Please check and fix it.");
return;
}
if (oldTarget != null && !oldTarget.isEmpty()) {
this.List.removeIf(s -> s.equals(oldTarget));
}
this.FileRead();
Random random = new Random();
// System.out.println(List);
int index = random.nextInt(List.size());
if (Flag1){
@@ -95,7 +99,7 @@ public class NumberleModel extends java.util.Observable implements INumberleMode
public void FileRead(){
try {
File file=new File("C:/Users/93678/IdeaProjects/Numbera/src/equations.txt");
File file=new File("./equations.txt");
assert file.exists():"File should be exists";
Scanner scanner =new Scanner(file);
@@ -174,23 +178,23 @@ public class NumberleModel extends java.util.Observable implements INumberleMode
}
@Override
public boolean startNewGame() {
StartGame();
public boolean startNewGame(String oldTarget) {
StartGame(oldTarget);
return false;
}
@Override
public void Delete() {
if (CurrentGuess.length()>0){
CurrentGuess.deleteCharAt(CurrentGuess.length()-1);
setChanged();
notifyObservers();
}
}
// @Override
// public void Delete() {
//
// if (CurrentGuess.length()>0){
// CurrentGuess.deleteCharAt(CurrentGuess.length()-1);
// setChanged();
// notifyObservers();
// }
// }
}
+2 -2
View File
@@ -58,7 +58,7 @@ public class NumberleView extends JFrame implements Observer {
((NumberleModel) this.model).addObserver(this); // Register this view as an observer to the model
// Set view for controller
this.controller.setView(this); // Set this view instance as the view for the controller
// this.controller.setView(this); // Set this view instance as the view for the controller
// Update view with initial model state
update((NumberleModel) this.model, null); // Call update method to synchronize view with initial model state
@@ -566,7 +566,7 @@ public class NumberleView extends JFrame implements Observer {
JTextArea textArea = new JTextArea();
textArea.setLineWrap(true); // Enable automatic line wrapping
textArea.setWrapStyleWord(true);
textArea.setText("游戏的规则。游戏的目标是在6次尝试内猜出隐藏的数学方程式,并猜出方块的颜色。玩家需要输入一个数学方程式,然后根据提示来猜测正确的方程式以及方块的颜色。例如,如果隐藏的方程式是5+75=40,而玩家输入了5+52=10,那么根据位置正确与否,以及数字正确与否,某些部分的方块会变成绿色来指示正确的部分。 "
textArea.setText("Game Rules. The aim of the game is to guess the hidden mathematical equation and the color of the tiles within 6 attempts. Players need to input a mathematical equation and then make guesses on the correct equation and the color of the tiles based on the hints provided. For example, if the hidden equation is 5 + 75 = 40, and the player inputs 5 + 52 = 10, then according to whether the positions and numbers are correct, certain parts of the tiles will turn green to indicate the correct parts."
);