All done
This commit is contained in:
parent
27b81ee5a9
commit
baf8f83855
@ -46,9 +46,31 @@ public class DrawningMonorail {
|
||||
DrawningWheels = new DrawningWheelsCart(_monorailWidth - dif, _monorailHeight,_startPosX,_startPosY,wheelColor,tireColor);
|
||||
else
|
||||
DrawningWheels = new DrawningWheelsOrn(_monorailWidth - dif, _monorailHeight,_startPosX,_startPosY,wheelColor,tireColor);
|
||||
DrawningWheels.ChangeWheelsNumb(rand.nextInt(1, 6));
|
||||
DrawningWheels.ChangeWheelsNumb(rand.nextInt(4));
|
||||
}
|
||||
|
||||
public int GetIDrawType(){
|
||||
if(DrawningWheels instanceof DrawningWheels)
|
||||
return 0;
|
||||
if(DrawningWheels instanceof DrawningWheelsCart)
|
||||
return 1;
|
||||
if(DrawningWheels instanceof DrawningWheelsOrn)
|
||||
return 2;
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void ChangeIDraw(int variant){
|
||||
IDraw cur;
|
||||
int dif = _monorailWidth / 10;
|
||||
if(variant == 0)
|
||||
cur = new DrawningWheels(_monorailWidth - dif, _monorailHeight,_startPosX,_startPosY,Color.GRAY,Color.BLACK);
|
||||
else if(variant == 1)
|
||||
cur = new DrawningWheelsCart(_monorailWidth - dif, _monorailHeight,_startPosX,_startPosY, Color.GRAY,Color.BLACK);
|
||||
else
|
||||
cur = new DrawningWheelsOrn(_monorailWidth - dif, _monorailHeight,_startPosX,_startPosY,Color.GRAY, Color.BLACK);
|
||||
ChangeIDraw(cur);
|
||||
|
||||
}
|
||||
public void ChangeIDraw(IDraw obj){
|
||||
DrawningWheels = obj;
|
||||
obj.ChangeWheelsNumb(_wheelNumb);
|
||||
|
@ -47,17 +47,23 @@ public class ExtentionDrawningMonorail {
|
||||
public static DrawningMonorail CreateDrawningMonorail(String info, char separatorForObject,
|
||||
int width, int height){
|
||||
String[] strs = info.split(Character.toString(separatorForObject));
|
||||
if(strs.length == 5){
|
||||
return new DrawningMonorail(Integer.parseInt(strs[0]),
|
||||
if(strs.length == 7){
|
||||
DrawningMonorail toRet = new DrawningMonorail(Integer.parseInt(strs[0]),
|
||||
Integer.parseInt(strs[1]), getColor(strs[2]),
|
||||
getColor(strs[3]), getColor(strs[4]), width, height);
|
||||
toRet.ChangeWheelsNumb(Integer.parseInt(strs[5]));
|
||||
toRet.ChangeIDraw(Integer.parseInt(strs[6]));
|
||||
return toRet;
|
||||
}
|
||||
if(strs.length == 9){
|
||||
return new DrawningLocomotive(Integer.parseInt(strs[0]),
|
||||
if(strs.length == 10){
|
||||
DrawningMonorail toRet = new DrawningLocomotive(Integer.parseInt(strs[0]),
|
||||
Integer.parseInt(strs[1]), getColor(strs[2]),
|
||||
getColor(strs[3]), getColor(strs[4]),
|
||||
Integer.parseInt(strs[5]), width, height, Boolean.parseBoolean(strs[6]),
|
||||
Boolean.parseBoolean(strs[7]), getColor(strs[8]));
|
||||
4, width, height, Boolean.parseBoolean(strs[7]),
|
||||
Boolean.parseBoolean(strs[8]), getColor(strs[9]));
|
||||
toRet.ChangeWheelsNumb(Integer.parseInt(strs[5]));
|
||||
toRet.ChangeIDraw(Integer.parseInt(strs[6]));
|
||||
return toRet;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -66,16 +72,17 @@ public class ExtentionDrawningMonorail {
|
||||
if(monorail == null)
|
||||
return null;
|
||||
String colName = getName(monorail.BodyColor);
|
||||
var str = String.format("%d%c%d%c%s%c%s%c%s", monorail.Speed(), separatorForObject, (int)monorail.Weight(),
|
||||
var str = String.format("%d%c%d%c%s%c%s%c%s%c%d%c%d", monorail.Speed(), separatorForObject, (int)monorail.Weight(),
|
||||
separatorForObject, getName(monorail.BodyColor), separatorForObject,
|
||||
getName(monorail.WheelColor), separatorForObject, getName(monorail.TireColor));
|
||||
getName(monorail.WheelColor), separatorForObject, getName(monorail.TireColor), separatorForObject,
|
||||
drawningMonorail._wheelNumb, separatorForObject, drawningMonorail.GetIDrawType());
|
||||
if(!(monorail instanceof EntityLocomotive)){
|
||||
return str;
|
||||
}
|
||||
var nstr = String.format("%s%c%d%c%b%c%b%c%s", str, separatorForObject,
|
||||
drawningMonorail._wheelNumb, separatorForObject, ((EntityLocomotive) monorail).SecondCabine(), separatorForObject,
|
||||
var nstr = String.format("%s%c%b%c%b%c%s", str, separatorForObject,
|
||||
((EntityLocomotive) monorail).SecondCabine(), separatorForObject,
|
||||
((EntityLocomotive) monorail).MagniteRail(), separatorForObject,
|
||||
getName(((EntityLocomotive) monorail).AdditionalColor));
|
||||
getName(((EntityLocomotive) monorail).AdditionalColor), separatorForObject);
|
||||
return nstr;
|
||||
}
|
||||
}
|
||||
|
@ -85,7 +85,8 @@ public class FormMonorailCollection {
|
||||
String collectionName = strs[1];
|
||||
MonorailGenericCollection<DrawningMonorail, DrawningObjectMonorail> collection = new MonorailGenericCollection<>(pictureBoxWidth, pictureBoxHeight);
|
||||
String[] monorailsInfo = strs[2].split(Character.toString(MonorailGenericCollection._separatorRecords));
|
||||
for(String data : monorailsInfo){
|
||||
for(int i = monorailsInfo.length-1; i >= 0; i--){
|
||||
String data = monorailsInfo[i];
|
||||
DrawningMonorail monorail = ExtentionDrawningMonorail.CreateDrawningMonorail(data,
|
||||
MonorailGenericCollection._separatorForObject, pictureBoxWidth, pictureBoxHeight);
|
||||
if (monorail != null)
|
||||
@ -156,7 +157,7 @@ public class FormMonorailCollection {
|
||||
saveFile.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JFileChooser fc = new JFileChooser();
|
||||
JFileChooser fc = new JFileChooser("C:\\Users\\frenk\\OneDrive\\Рабочий стол\\lab6saves");
|
||||
fc.addChoosableFileFilter(new TxtSaveFilter());
|
||||
int retrieval = fc.showSaveDialog(null);
|
||||
|
||||
@ -175,7 +176,7 @@ public class FormMonorailCollection {
|
||||
saveCollection.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JFileChooser fc = new JFileChooser();
|
||||
JFileChooser fc = new JFileChooser("C:\\Users\\frenk\\OneDrive\\Рабочий стол\\lab6saves");
|
||||
fc.addChoosableFileFilter(new TxtSaveFilter());
|
||||
int retrieval = fc.showSaveDialog(null);
|
||||
|
||||
@ -198,7 +199,7 @@ public class FormMonorailCollection {
|
||||
loadFile.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JFileChooser fc = new JFileChooser();
|
||||
JFileChooser fc = new JFileChooser("C:\\Users\\frenk\\OneDrive\\Рабочий стол\\lab6saves");
|
||||
int ret = fc.showDialog(null, "Открыть файл");
|
||||
if(ret == JFileChooser.APPROVE_OPTION){
|
||||
File file = fc.getSelectedFile();
|
||||
@ -218,7 +219,7 @@ public class FormMonorailCollection {
|
||||
loadCollection.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JFileChooser fc = new JFileChooser();
|
||||
JFileChooser fc = new JFileChooser("C:\\Users\\frenk\\OneDrive\\Рабочий стол\\lab6saves");
|
||||
int ret = fc.showDialog(null, "Открыть файл");
|
||||
if(ret == JFileChooser.APPROVE_OPTION){
|
||||
File file = fc.getSelectedFile();
|
||||
|
@ -362,7 +362,6 @@ public class FormMonorailConfig {
|
||||
String data = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor);
|
||||
switch (data) {
|
||||
case "Простой":
|
||||
|
||||
_monorail = new DrawningMonorail(speed, weight, Color.WHITE,
|
||||
Color.GRAY, Color.BLACK, _pictureBoxWidth, _pictureBoxHeight);
|
||||
_monorail.ChangeWheelsNumb(wheelNumb);
|
||||
|
@ -61,7 +61,9 @@ public class MonorailGenericStorage {
|
||||
MonorailGenericCollection<DrawningMonorail, DrawningObjectMonorail> collection =
|
||||
new MonorailGenericCollection<>(_pictureWidth, _pictureHeight);
|
||||
String[] set = record[1].split(Character.toString(_separatorRecords));
|
||||
for(String elem : set){
|
||||
|
||||
for(int i = set.length -1; i >=0; i--){
|
||||
String elem = set[i];
|
||||
DrawningMonorail monorail = ExtentionDrawningMonorail.CreateDrawningMonorail(elem,
|
||||
_separatorForObject, _pictureWidth, _pictureHeight);
|
||||
if (monorail != null)
|
||||
|
Loading…
Reference in New Issue
Block a user