Kontakt

Fakturační údaje

IČ: 87189224, BÚ: 1958653063/0800

Contact info in QR code

Siege (Obkličovačka)

Informace

Stáhni a hraj!

  • Spustitelný soubor hry si stáhnou oba hráči
  • Zakladatel hry
    • V nabídce "Game > Create" vytvoří novou hru
    • Pošle protihráči svou IP adresu (zjistí ji v levém dolním rohu okna)
  • Protihráč
    • Jakmile obdrží IP adresu zakladatele hry, v nabídce "Game > Join" se připojí ke hře
  • Cílem je zabrat co nejvíce soupeřových polí.
  • Pozn.: Síťové spojení funguje na LAN (lokální) síťi a na počítačích s veřejnou IP adresou.

Zdrojové kódy (zip)

Zdrojové kódy (prohlížení)

  1: package siege.core;
  2: 
  3: import java.util.HashSet;
  4: import java.util.Observable;
  5: import siege.util.Log;
  6: 
  7: /**
  8:  * Point that belong to playboard. Holds information about its position, owner,
  9:  * current state, parent territories.
 10:  *
 11:  * Observers:
 12:  *  - are notified of changes in position, ownership, parent territories
 13:  *  - Playboard, PointView, Territory
 14:  *
 15:  * @author Ondrej Macoszek, ondra@macoszek.cz
 16:  */
 17: public class PlayboardPoint extends Observable implements Positionable, Ownable
 18: {
 19:     /**
 20:      * Positionable properties
 21:      */
 22:     private int x;
 23:     private int y;
 24: 
 25:     /**
 26:      * Ownable properties
 27:      */
 28:     private Player owner;
 29: 
 30:     /**
 31:      * Parent teritories having this point as part of borderline
 32:      */
 33:     private HashSet<Territory> parentTerritoriesBorder = new HashSet<Territory>(3);
 34: 
 35:     /**
 36:      * Parent territories having this point as inner point
 37:      */
 38:     private HashSet<Territory> parentTerritoriesInner = new HashSet<Territory>(3);
 39: 
 40:     /**
 41:      * Initialize point on specified coordinates
 42:      * 
 43:      * @param x coord
 44:      * @param y coord
 45:      */
 46:     public PlayboardPoint(int x, int y)
 47:     {
 48:         super();
 49:         this.x = x;
 50:         this.y = y;
 51:     }
 52: 
 53:     /**
 54:      * Test if this point is occupied (has an owner)
 55:      * @return true if point is occupied
 56:      */
 57:     public boolean isOccupied()
 58:     {
 59:         return (hasOwner()==true) ? true : false;
 60:     }
 61: 
 62: 
 63: 
 64:     /**
 65:      * Test if this point is occupied and is not inside territory
 66:      * @return true if point is active
 67:      */
 68:     public boolean isActive()
 69:     {
 70:         return (hasOwner() && parentTerritoriesInner.isEmpty()) ? true : false;
 71:     }
 72: 
 73: 
 74:     /**
 75:      * Set parent territory 
 76:      * @param territory
 77:      * @param status can be only PointStatus.BORDER or PointStatus.INNER
 78:      */
 79:     public void setParentTerritory(Territory territory, PointStatus status)
 80:     {
 81:         switch(status) {
 82:             case BORDER:
 83:                 parentTerritoriesBorder.add(territory);
 84:                 parentTerritoriesInner.remove(territory);
 85:                 break;
 86:             case INNER:
 87:                 parentTerritoriesInner.add(territory);
 88:                 parentTerritoriesBorder.remove(territory);
 89:                 break;
 90:         }
 91:         setChanged();
 92:         notifyObservers();
 93:     }
 94: 
 95:     /**
 96:      * Test if point has any parent territory
 97:      * @return true if has any parent territory
 98:      */
 99:     public boolean hasParentTerritory()
100:     {
101:         return (parentTerritoriesBorder.isEmpty()
102:                 && parentTerritoriesInner.isEmpty())
103:                 ? false : true;
104:     }
105:    
106:     /**
107:      * Test if point has any parent territory with specific status
108:      * @param status 
109:      * @return true if has any parent territory with specific status
110:      */
111:     public boolean hasParentTerritory(PointStatus status)
112:     {
113:         boolean result = false;
114: 
115:         switch(status) {
116:             case BORDER:
117:                 if(parentTerritoriesBorder.isEmpty()==false) {
118:                     result = true;
119:                 }
120:                 break;
121:             case INNER:
122:                 if(parentTerritoriesInner.isEmpty()==false) {
123:                     result = true;
124:                 }
125:                 break;
126:         }
127: 
128:         return result;
129:     }
130: 
131:     /**
132:      * Test if point has specific parent territory
133:      * @param territory
134:      * @return true if has given territory as parent
135:      */
136:     public boolean hasParentTerritory(Territory territory)
137:     {
138:         return (parentTerritoriesBorder.contains(territory)
139:                 || parentTerritoriesInner.contains(territory))
140:                 ? true : false;
141:     }
142: 
143:     /**
144:      * Test if point has specific parent territory under specific PointStatus
145:      * @param territory
146:      * @param status can be only PointStatus.BORDER or PointStatus.INNER
147:      * @return treu if point has given territory as parent under specific point
148:      */
149:     public boolean hasParentTerritory(Territory territory, PointStatus status)
150:     {
151:         boolean result = false;
152:         switch(status) {
153:             case BORDER:
154:                 if(parentTerritoriesBorder.contains(territory)) {
155:                     result = true;
156:                 }
157:                 break;
158:             case INNER:
159:                 if(parentTerritoriesInner.contains(territory)) {
160:                     result = true;
161:                 }
162:                 break;
163:         }
164:         return result;
165:     }
166: 
167:     public boolean isNearbyOf(PlayboardPoint point)
168:     {
169:         boolean result = false;
170: 
171:         int dx = Math.abs(this.x - point.x);
172:         int dy = Math.abs(this.y - point.y);
173: 
174:         if(dx > 1 || dy > 1) {
175:             // is one of coordinates is too far from current point
176:             result = false;
177:         } else if(dx == 1 || dy ==1) {
178:             // distances are close: 1,1 or 1,0 or 0,1
179:             result = true;
180:         } else if(dx == 0 && dy == 0) {
181:             // same point is not nearby, error
182:             throw new IllegalArgumentException("Cannot compare point itself as nearby");
183:         }
184: 
185:         return result;
186:     }
187: 
188:     /**
189:      * Positionable implementation
190:      * @see Positionable
191:      */
192: 
193:     public int getX()
194:     {
195:         return x;
196:     }
197: 
198:     public void setX(int x)
199:     {
200:         this.x = x;
201:         setChanged();
202:         notifyObservers();
203:     }
204: 
205:     public int getY()
206:     {
207:         return y;
208:     }
209: 
210:     public void setY(int y)
211:     {
212:         this.y = y;
213:         setChanged();
214:         notifyObservers();
215:     }
216: 
217: 
218: 
219:     /**
220:      * Ownable implementation
221:      * @see Ownable
222:      */
223: 
224:     public void setOwner(Player owner)
225:     {
226:         Log.message(this, "("+x+","+y+") has owner");
227:         this.owner = owner;
228:         setChanged();
229:         notifyObservers();
230:     }
231: 
232:     public Player getOwner()
233:     {
234:         return owner;
235:     }
236: 
237:     public boolean hasOwner()
238:     {
239:         boolean result = false;
240:         if(owner != null) {
241:             result = true;
242:         }
243:         return result;
244:     }
245: 
246:     public boolean hasOwner(Player owner)
247:     {
248:         boolean result = false;
249:         if(this.owner != null && this.owner.equals(owner)) {
250:             result = true;
251:         }
252:         return result;
253:     }
254: 
255:     @Override
256:     public String toString()
257:     {
258:         return "PlayboardPoint with coords ("+x+","+y+")";
259:     }
260: }