using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace BattleForAllenCreek { class Hexpart { int x, y; int referenceX, referenceY; int hexpartType; String name; String prefix; public Hexpart() { } public Hexpart(String name) { this.name = name; this.calculateHexpart(); } public Hexpart(int x, int y) { this.setXY(x, y); } public void setXY(int x, int y) { this.x = x; this.y = y; this.calculateHexpartType(); this.calculateHexpartName(); } public void calculateHexpartType() { // center = 1, bottom = 2, lower left = 3, upper left = 4 this.hexpartType = 0; // 8 cases switch (this.x % 4) { case 0: switch (this.y % 4) { case 0: this.hexpartType = 1; break; case 2: this.hexpartType = 2; break; } break; case 1: switch (this.y % 4) { case 1: this.hexpartType = 4; break; case 3: this.hexpartType = 3; break; } break; case 2: switch (this.y % 4) { case 0: this.hexpartType = 2; break; case 2: this.hexpartType = 1; break; } break; case 3: switch (this.y % 4) { case 1: this.hexpartType = 3; break; case 3: this.hexpartType = 4; break; } break; } } public void calculateHexpartName() { switch (this.hexpartType) { case 1: this.referenceX = this.x; this.referenceY = this.y; this.prefix = "hexpart:"; break; case 2: this.referenceX = this.x; this.referenceY = this.y - 2; this.prefix = "hexpart_"; break; case 3: this.referenceX = this.x + 1; this.referenceY = this.y - 1; this.prefix = "hexpart\\"; break; case 4: this.referenceX = this.x + 1; this.referenceY = this.y + 1; this.prefix = "hexpart/"; break; } if (this.hexpartType > 0) { Hexagon hexagon = new Hexagon(this.referenceX, this.referenceY); this.name = this.prefix + hexagon.getName(); } else { this.name = "null"; } } private void calculateHexpart() { // center = :, lower = _, lower left = \\, upper left = / // since \ is an escape char, need to check for \\ Hexagon hexagon = new Hexagon(this.name.Substring(8,4)); Char hexpartTypeLetter = (Char) this.name[7]; this.referenceX = hexagon.getX(); this.referenceY = hexagon.getY(); switch (hexpartTypeLetter) { case ':': this.hexpartType = 1; this.x = this.referenceX; this.y = this.referenceY; break; case '_': this.hexpartType = 2; this.x = this.referenceX; this.y = this.referenceY + 2; break; case '\\': this.hexpartType = 3; this.x = this.referenceX - 1; this.y = this.referenceY + 1; break; case '/': this.hexpartType = 4; this.x = this.referenceX - 1; this.y = this.referenceY - 1; break; default: this.hexpartType = 1; this.x = this.referenceX; this.y = this.referenceY; break; } } public String getName() { return (this.name); } public int getX() { return this.x; } public int getY() { return this.y; } public int getType() { return this.hexpartType; } public String getTypeName() { String[] hexpartTypeName = new String[] { "", "center", "lower", "lowerLeft", "upperLeft"}; return hexpartTypeName[this.hexpartType]; } } }