-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRegion.java
116 lines (95 loc) · 3.12 KB
/
Region.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package primary;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.Random;
/**
* This class generates different regions that inhabit the space trader universe
*/
public class Region {
protected String name;
private int techLevel;
private int xCoordinate;
private int yCoordinate;
private String description;
private boolean hasBeenVisited = false;
private static int numberOfRegions = 0;
private int regionID;
private Market regionMarket = new Market();
private boolean winningRegion = false;
private Random rand = new Random();
public Region() {
name = generateName();
techLevel = rand.nextInt(5) + 1;
xCoordinate = rand.nextInt(1000);
yCoordinate = rand.nextInt(700);
if (rand.nextInt(1000) % 2 == 0) {
xCoordinate = -xCoordinate;
}
if (rand.nextInt(1000) % 2 == 0) {
yCoordinate = -yCoordinate;
}
description = name + ", a level " + techLevel
+ " civilization \r located at X:" + xCoordinate
+ " | Y:" + yCoordinate;
regionID = numberOfRegions;
numberOfRegions++;
//System.out.print(this.regionID + " Generated");
}
private String generateName() {
ArrayList<String> nameDictionary = new ArrayList<>();
ArrayList<String> classDictionary = new ArrayList<>();
Scanner regionNameSC = null;
Scanner classNameSC = null;
try {
File regionName = new File("src/resources/RegionNames.txt");
regionNameSC = new Scanner(regionName);
File className = new File("src/resources/RegionClassName.txt");
classNameSC = new Scanner(className);
} catch (FileNotFoundException e) {
System.out.println("primary.Region's names "
+ "files are missing from the resources folder");
}
assert regionNameSC != null;
while (regionNameSC.hasNext()) {
nameDictionary.add(regionNameSC.next());
}
assert classNameSC != null;
while (classNameSC.hasNext()) {
classDictionary.add(classNameSC.nextLine());
}
return nameDictionary.get(rand.nextInt(nameDictionary.size()))
+ classDictionary.get(rand.nextInt(classDictionary.size()));
}
public String getDescription() {
return description;
}
public int getxCoordinate() {
return xCoordinate;
}
public int getyCoordinate() {
return yCoordinate;
}
public boolean hasBeenVisited() {
return hasBeenVisited;
}
public void setBeenVisited(boolean v) {
hasBeenVisited = v;
}
public String getName() {
return name;
}
public int getTechLevel() {
return techLevel;
}
public Market getRegionMarket() {
return regionMarket;
}
public boolean isWinningRegion() {
return winningRegion;
}
public void setWinningRegion(boolean winningRegion) {
this.winningRegion = winningRegion;
}
}