sách gpt4 ai đã đi

Java 游戏错误(数组、this.、方法)

In lại 作者:行者123 更新时间:2023-12-01 16:40:20 hai mươi bốn 4
mua khóa gpt4 Nike

import java.util.Scanner;

public class Game

{

private String startYorN;
private int generateTestValues;
private int rows;
private int cols;
private int minCanisters;
private int maxCanisters;
private int numOfDarkies;
private int minimumLifePoints;
private String name;
private String type1;
private int sPosition1, sPosition2;
private int tPosition1, tPosition2;
private int iLifePoints;
Scanner scan = new Scanner(System.in);

public void gameSetting()
{

System.out.print ("Would you like to play? (y/n):");
startYorN = scan.nextLine();
//if (startYorN =="n" || startYorN =="N")
//quit the game(?)

System.out.print ("Would you want to generate test values for world? 1- yes: ");
generateTestValues =scan.nextInt();
System.out.println ("");

System.out.print ("Enter a number of rows for world: ");
rows = scan.nextInt ();
System.out.println ("");

System.out.print ("Enter a number of cols for world: ");
cols = scan.nextInt ();
System.out.println ("");

System.out.print ("Enter minimum energy canisters in each planet: ");
minCanisters = scan.nextInt ();
System.out.println ("");

System.out.print ("Enter maximum energy canisters in each planet: ");
maxCanisters = scan.nextInt ();
System.out.println ("");

System.out.print ("Enter number of planets with darkies: ");
numOfDarkies = scan.nextInt ();
System.out.println ("");

System.out.print ("Enter minimum life points for players to replenish: ");
minimumLifePoints = scan.nextInt ();
System.out.print ("\n");
World w = new World(rows,cols,minCanisters, maxCanisters, numOfDarkies);
w.display();

Alien[] alien = new Alien [2];

for (int i = 0; i<=1;i++)
{
name = scan.nextLine ();
System.out.print ("\n");
System.out.print ("Enter name for player #" + i + ": ");
name = scan.nextLine ();

System.out.print ("Enter kind Player #" + i + ", (n- naive, g- greedy, a- aggressive, u- naive user, w-aggressive user): ");
type = scan.nextLine ();

System.out.print ("Enter: row (space) column for start position for player #" + i + ": ");
sPosition1 = scan.nextInt ();
sPosition2 = scan.nextInt ();

System.out.print ("Enter: row (space) column for target position for player #" + i + ": ");
tPosition1 = scan.nextInt ();
tPosition2 = scan.nextInt ();

System.out.print ("Enter initial life points for player #" + i + ": ");
iLifePoints = scan.nextInt ();
}
}
public void setInfo(Alien alien[i], String name, String type, int sPosition1, int sPosition2,
int tPosition1, int tPosition2, int iLifePoints)
{
this.name = name;
this.type = type;
this.sPosition1 = sPosition1;
this.sPosition2 = sPosition2;
this.tPosition1 = tPosition1;
this.tPosition2 = tPosition2;
this.iLifePoints = iLifePoints;
}
}

我知道 setInfo 方法有问题,可能 gameSetting 方法也有问题。我想从两个玩家(外星人)中获取信息。有人可以告诉我我应该做什么吗?

1 Câu trả lời

一个问题是您应该删除 setInfo() 参数列表中 Alien Alien[i] TRONG Tôi。您可能还需要考虑将其从参数列表中完全删除,因为您不使用它,或者不使用它可能是您需要修复的另一个错误。

您还需要更改变量 type1 的声明,将其称为 kiểu,因为您将在下面的几个地方使用它。

修复这两个问题可以消除除 Scanner/Alien/World 的“未找到类”之外的所有编译器错误,但您有望修复这些问题。请参阅http://ideone.com/PNqb2

关于Java 游戏错误(数组、this.、方法),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4362253/

hai mươi bốn 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com