refactor: introduce new CityDimension class to encapsulate width/height

git-svn-id: https://micropolis.googlecode.com/svn/trunk/micropolis-java@842 d9718cc8-9f43-0410-858b-315f434eb58c
This commit is contained in:
jason@long.name 2013-09-05 11:22:40 +00:00
parent b22263b4b6
commit 2af5cf14a7
2 changed files with 64 additions and 7 deletions

View file

@ -0,0 +1,48 @@
// This file is part of MicropolisJ.
// Copyright (C) 2013 Jason Long
// Portions Copyright (C) 1989-2007 Electronic Arts Inc.
//
// MicropolisJ is free software; you can redistribute it and/or modify
// it under the terms of the GNU GPLv3, with additional terms.
// See the README file, included in this distribution, for details.
package micropolisj.engine;
/**
* Encapsulates the width and height of a rectangular section of a Micropolis city.
*/
public class CityDimension
{
public int width;
public int height;
public CityDimension(int width, int height)
{
this.width = width;
this.height = height;
}
@Override
public int hashCode()
{
return width*33+height;
}
@Override
public boolean equals(Object obj)
{
if (obj instanceof CityDimension) {
CityDimension rhs = (CityDimension) obj;
return this.width == rhs.width && this.height == rhs.height;
}
else {
return false;
}
}
@Override
public String toString()
{
return width+"x"+height;
}
}

View file

@ -52,16 +52,13 @@ public class TileSpec
public BuildingInfo getBuildingInfo()
{
String tmp = getAttribute("building");
if (tmp == null) { return null; }
CityDimension buildingSize = getBuildingSize();
if (buildingSize == null) { return null; }
BuildingInfo bi = new BuildingInfo();
String [] parts = tmp.split(",");
String [] p2 = parts[0].split("x");
bi.width = Integer.parseInt(p2[0]);
bi.height = Integer.parseInt(p2[1]);
bi.width = buildingSize.width;
bi.height = buildingSize.height;
bi.members = new short[bi.width*bi.height];
int startTile = tileNumber;
@ -78,6 +75,18 @@ public class TileSpec
return bi;
}
public CityDimension getBuildingSize()
{
String tmp = getAttribute("building");
if (tmp == null) { return null; }
String [] p2 = tmp.split("x");
return new CityDimension(
Integer.parseInt(p2[0]),
Integer.parseInt(p2[1])
);
}
public int getDescriptionNumber()
{
String v = getAttribute("description");