小编Jam*_*mes的帖子

Java服务器猜测游戏

我正在创建一个服务器,客户端连接它来玩猜谜游戏,他们也是为了获得积分.

我目前唯一的问题是每当我的客户端正确猜出数字时,它会跳转到服务器并说'server null'.我希望猜测游戏能够继续,直到客户输入'再见' - 他/她得分.

这是我的代码,你可以指出我出错的地方,并告诉我如何实现我想要的.我认为问题出在协议中我可能只需要将时间放在正确的位置,这样就可以了.谢谢大家!只是添加,变量名称奇怪我知道它以前是一个敲敲笑话服务器

协议

import java.util.*;

        public class KKProtocol {
    int guess = 0, number = new Random().nextInt(100) + 1;
    int score = 0;
    Scanner scan = new Scanner(System.in);


    public String processInput(String theInput) {
        String theOutput = null;

        System.out.println("Please guess the number between 1 and 100.");

        while (guess != number) {
          try {
            if ((guess = Integer.parseInt(scan.nextLine())) != number) {
              System.out.println(guess < number ? "Higher..." : "Lower...");
            }
            else {
              System.out.println("Correct!");
              score = 1;
            }
          }   
          catch …
Run Code Online (Sandbox Code Playgroud)

java repeat

6
推荐指数
1
解决办法
1779
查看次数

标签 统计

java ×1

repeat ×1