我已經花了近3小時內觀察堆棧的論壇,有同樣的問題,但更多的方式複雜的例子文件主要方法...貯藏INT []從一個文件中的數據,包含
此代碼是隻是一個大項目的一小部分。這是一種DnD類型的遊戲,這樣你的角色的許多不同方面的統計數據會影響你可能遇到的遊戲流動/情況的方式。
目標不談,現在我只想把所有的玩家數據到個人類,在文件中,並且能夠檢索/存儲條所述數據的(在main方法的獨立文件)進入臨時變量供進一步使用。
這段代碼是完全由用戶「Xynariz」完成的。 //縱觀所有的研究,我做到了,這讓我最接近我想要的東西。] [1]
public class Driver{
public static void Main(String[] args){
int[] array = {1, 2, 3};
CustomObject otherObject = new CustomObject(array);
}
}
/// And, in a different file....
public class CustomObject{
public CustomObject(int[] array){
int x = array[2];
//etc...
}
}
這是Game.java與主要方法。試圖從file.java得到這裏的陣列數據
import java.util.Arrays;
public class Game {
public static void main(String[] args, int[] str) {
int x = str[1];
int[] y = str;
System.out.println(x);
System.out.println(y);
}
}
public class file {
public static void enemy_1(String[] args, int[] var){
//{health, stamina, magika, speed};
int[] stats = {50 , 3 , 0 , 2 };
//{strength, athletics };
int[] str = {3 , 5 };
// {acrobatics, sleight_of_hand, stealth};
int[] dex = {8 , 2 , 1 };
// {arcana, history, investigation, nature};
int[] intel = {0 , 0 , 0 , 5 };
// {animal_handling, insight, medicine, perception, survival};
int[] wis = {4 , 1 , 0 , 4 , 6 };
// {deception, intimidation, performance, persuasion};
int[] charis = {0 , 0 , 0 , 0 };
Game object = new Game(str);
}
public void player_1(String[] args, int[] var){
// rogue character
//{health, stamina, magika, speed};
int[] stats = {70 , 7 , 0 , 9 };
//and so on...
}
//list of entities would continue.
}
我能球員數據存儲到臨時變量,然後通過方法,但只能運行,它當播放器數據在類主文件中時工作,臨時變量存儲在輔助文件中。 (我必須從輔助存儲臨時變量 - >主文件,所以我可以讓這些變量與主要的其他方法一起運行)。
[請不要將您的代碼作爲圖像發佈。](// meta.stackoverflow.com/q/285551) – Henry
感謝Henry!對不起,沒有意識到。我會盡快解決它 – Zaki