Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
63ec1c8
updateCameraForRoamingMovements Method Refactoring
cokacider May 2, 2018
fb98c87
convert taps to 4 spaces
cokacider May 2, 2018
f04dd53
Refactoring IS-A Relationship
aikaran May 2, 2018
3f6ccf8
Replace the number of weapon classes with a constant
cokacider May 3, 2018
49273eb
Extract methods createTitleLabel, createCancelButton
cokacider May 3, 2018
b46130a
convert tabs to 4 spaces
cokacider May 3, 2018
b86c248
Rename method
cokacider May 3, 2018
9500b91
Merge pull request #10 from aikaran/master
terry2511 May 4, 2018
f70a11b
Refactoring game/entities and map
terry2511 May 4, 2018
5991915
Door Update
terry2511 May 4, 2018
e9bd731
Merge branch 'master' of https://github.com/terry2511/seventh.git
May 4, 2018
39e527a
Extract Method
aikaran May 5, 2018
39bdfdd
Extract methods from refreshButtons method
cokacider May 6, 2018
0aeb486
Refactoring refreshButtons method
cokacider May 6, 2018
82e78a5
Refactoring Seventh.game.type.obj.ObjectiveScript.java
GardenHee May 6, 2018
113af0b
Refactoring getClassDescription method
cokacider May 6, 2018
2672475
convert all tabs in WeaponClassDescription.java to 4 spaces
cokacider May 6, 2018
05a1c3b
1.extract method, move method
virginbabylon May 6, 2018
d5814e2
add function comment
aikaran May 6, 2018
f52efe1
Refactoring : Extract Method
aikaran May 6, 2018
7c3b799
1.
May 7, 2018
4140406
1.Replace Temp with Query
virginbabylon May 7, 2018
02d040b
Extract printBitArray method to remove duplicate code.
May 7, 2018
26f6245
Refactoring dumptBytes.
May 7, 2018
87cc6ab
Refactoring ClientGame.java
terry2511 May 7, 2018
2881403
Merge pull request #11 from aikaran/master
terry2511 May 7, 2018
213bbc1
Merge pull request #13 from GardenHee/master
terry2511 May 7, 2018
fc6b3d7
Merge pull request #14 from cokacider/master
terry2511 May 7, 2018
091ef68
Merge pull request #16 from bananapizza/master
terry2511 May 7, 2018
32c8b17
1.extract method, move method
virginbabylon May 7, 2018
eb745b9
1.extract method, move method
virginbabylon May 7, 2018
2dbea2d
1.extract method, move method
virginbabylon May 7, 2018
1b6bb5c
1.extract method, move method
virginbabylon May 7, 2018
cf0ae61
Merge branch 'master' into master
terry2511 May 7, 2018
cf1231d
Merge pull request #19 from virginbabylon/master
terry2511 May 7, 2018
04631b3
correct the function type
aikaran May 8, 2018
cba0073
Merge branch 'master' of https://github.com/terry2511/seventh.git
aikaran May 8, 2018
c170b80
Design Pattern : Strategy Pattern
aikaran Jun 4, 2018
9069b99
fix some error
aikaran Jun 4, 2018
bb1153f
Apply a design pattern (Template Method Pattern)
cokacider Jun 4, 2018
1d2f4c8
all tabs in World.java convert to 4 spaces
cokacider Jun 4, 2018
d487313
Apply a design pattern (Abstract Factory Pattern)
cokacider Jun 5, 2018
8f2fe16
Merge pull request #1 from cokacider/master
terry2511 Jun 5, 2018
4bd1aae
StrategyPattern
aikaran Jun 5, 2018
12b61fd
Fork again
aikaran Jun 5, 2018
f701c0b
Factory Method Pattern
aikaran Jun 5, 2018
94bd189
fix syntax error
aikaran Jun 5, 2018
1eeefd6
Singleton Pattern
aikaran Jun 7, 2018
2479d4c
replace all tabs to 4 spaces
aikaran Jun 7, 2018
65e372a
Merge pull request #2 from aikaran/master
terry2511 Jun 7, 2018
ce9f243
Strategy Pattern
Jun 7, 2018
b27aca5
Strategy Pattern
terry2511 Jun 7, 2018
54b7970
Merge branch 'master' of https://github.com/terry2511/seventh.git
Jun 7, 2018
d5031ce
Strategy Pattern
terry2511 Jun 7, 2018
08b730f
Design Pattern: Factory Method Pattern
GardenHee Jun 7, 2018
c01c276
ai/basic/memory
virginbabylon Jun 9, 2018
2d82709
Merge pull request #3 from GardenHee/master
terry2511 Jun 9, 2018
fc7e7bb
Merge pull request #5 from virginbabylon/master
terry2511 Jun 9, 2018
fd81bf8
Apply design patterns - Observer, Template Method, Factory Method
Jun 9, 2018
26527e8
Merge pull request #6 from bananapizza/master
terry2511 Jun 9, 2018
adb6954
tab -> 4 spaces
virginbabylon Jun 11, 2018
a16fb1a
Merge pull request #7 from virginbabylon/master
terry2511 Jun 12, 2018
913256b
Change tab to 4 spaces
Jun 12, 2018
2d70d94
Merge pull request #8 from bananapizza/master
terry2511 Jun 12, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 7 additions & 50 deletions src/harenet/BitPacker.java
Original file line number Diff line number Diff line change
Expand Up @@ -530,61 +530,18 @@ public BitPacker pad() {

return this;
}


public static void dumpBytes(byte[] value) {
System.out.println("+--------------- ------------- ------- ------ --- -- -- - -- -- --");
System.out.println("| Dumping bytes, length: " + (value.length * 8) + " (" + value.length + " byte(s))");
System.out.println("+--------------- ------------- ------- ------ --- -- -- - -- -- --");

int count = 0;
for (int j = 0; j < value.length; j++) {

byte v = value[j];

for (int i = 0; i < Byte.SIZE; i++) {
if (((v >> i) & 1) == 1) {
System.out.print("1");
}
else {
System.out.print("0");
}
}

System.out.print(" ");
count++;
if (count == 12) {
System.out.println();
count = 0;
}

}
System.out.println();
System.out.println("+--------------- ------------- ------- ------ --- -- -- - -- -- --");
StatementFactory statementFactory = new StatementFactory();

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a lot of extra code for not a lot of benefit. You want to create Factories when there a lot of different types or configurations.

This also adds in an extra layers of complexity -- instead of reading the code inlined, the reader has to now understand StatementFactory, Statement and the concrete classes of BitStatement and ByteStatement (along with grappling the inheritance).

Statement statement = statementFactory.getInstance(value);
statement.print();
}

public void dump() {
System.out.println("+--------------- ------------- ------- ------ --- -- -- - -- -- --");
System.out.println("| Dumping bitset, length: " + numBits);
System.out.println("+--------------- ------------- ------- ------ --- -- -- - -- -- --");

int count = 0;

for (int i = 0; i < numBits; i++) {
System.out.print(data.getBit(i) ? "1" : "0");
if ((i != 0) && (i % 8 == 7)) {
System.out.print(" ");
count++;
if (count == 12) {
System.out.println();
count = 0;
}

}

}
System.out.println();
System.out.println("+--------------- ------------- ------- ------ --- -- -- - -- -- --");
StatementFactory statementFactory = new StatementFactory();
Statement statement = statementFactory.getInstance(numBits,data);
statement.print();
}

}
27 changes: 27 additions & 0 deletions src/harenet/BitStatement.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package harenet;

public class BitStatement extends Statement {
private int numBits;
private BitArray data;

public BitStatement(int number,BitArray bitData) {
numBits = number;
data = bitData;
}

protected void printHeaderContents() {
System.out.println("| Dumping bitset, length: " + numBits);
}

public void printBody() {
int count = 0;

for (int i = 0; i < numBits; i++) {
printBit(data.getBit(i));
if ((i != 0) && (i % 8 == 7)) {
count = countProcess(count);
}

}
}
}
28 changes: 28 additions & 0 deletions src/harenet/ByteStatement.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package harenet;

public class ByteStatement extends Statement {
private byte[] value;

public ByteStatement(byte[] byteValue) {
value = byteValue;
}

protected void printHeaderContents() {
System.out.println("| Dumping bytes, length: " + (value.length * 8) + " (" + value.length + " byte(s))");
}

public void printBody() {
int count = 0;
for (int j = 0; j < value.length; j++) {

byte v = value[j];

for (int i = 0; i < Byte.SIZE; i++) {
printBit(((v >> i) & 1) == 1);
}

count = countProcess(count);

}
}
}
48 changes: 48 additions & 0 deletions src/harenet/Statement.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package harenet;

public abstract class Statement {
public void print() {
printHeader();
printBody();
printFooter();
}

public void printHeader() {
printLine();
printHeaderContents();
printLine();
}

public abstract void printBody();

public void printFooter() {
System.out.println();
printLine();
}

private void printLine() {
System.out.println("+--------------- ------------- ------- ------ --- -- -- - -- -- --");
}

protected abstract void printHeaderContents();

protected void printBit(boolean isOne) {
if (isOne) {
System.out.print("1");
}
else {
System.out.print("0");
}
}

protected int countProcess(int count) {
int tempCount = count;
System.out.print(" ");
tempCount++;
if (tempCount == 12) {
System.out.println();
tempCount = 0;
}
return tempCount;
}
}
10 changes: 10 additions & 0 deletions src/harenet/StatementFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package harenet;

public class StatementFactory {
public Statement getInstance(byte[] value) {
return new ByteStatement(value);
}
public Statement getInstance(int numBits, BitArray data) {
return new BitStatement(numBits,data);
}
}
26 changes: 5 additions & 21 deletions src/seventh/ai/basic/DefaultAISystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
import seventh.ai.basic.commands.AICommands;
import seventh.ai.basic.teamstrategy.CaptureTheFlagTeamStrategy;
import seventh.ai.basic.teamstrategy.CommanderTeamStrategy;
import seventh.ai.basic.teamstrategy.DefaultAISystemTeamStrategyFactory;
import seventh.ai.basic.teamstrategy.ObjectiveTeamStrategy;
import seventh.ai.basic.teamstrategy.TDMTeamStrategy;
import seventh.ai.basic.teamstrategy.TeamStrategy;
import seventh.ai.basic.teamstrategy.TeamStrategyFactory;
import seventh.game.GameInfo;
import seventh.game.PlayerInfo;
import seventh.game.PlayerInfos;
Expand Down Expand Up @@ -169,27 +171,9 @@ public void init(final GameInfo game) {

GameType gameType = game.getGameType();

switch(gameType.getType()) {
case CTF:
this.alliedAIStrategy = new CaptureTheFlagTeamStrategy(this, gameType.getAlliedTeam());
this.axisAIStrategy = new CaptureTheFlagTeamStrategy(this, gameType.getAxisTeam());
break;
case OBJ:
this.alliedAIStrategy = new ObjectiveTeamStrategy(this, gameType.getAlliedTeam());
this.axisAIStrategy = new ObjectiveTeamStrategy(this, gameType.getAxisTeam());
break;
case CMD:
this.alliedAIStrategy = new CommanderTeamStrategy((CommanderGameType)gameType, this, gameType.getAlliedTeam());
this.axisAIStrategy = new CommanderTeamStrategy((CommanderGameType)gameType, this, gameType.getAxisTeam());
break;
case TDM:
default:
this.alliedAIStrategy = new TDMTeamStrategy(this, gameType.getAlliedTeam());
this.axisAIStrategy = new TDMTeamStrategy(this, gameType.getAxisTeam());
break;

}

TeamStrategyFactory teamStrategyFactory = new DefaultAISystemTeamStrategyFactory();
this.alliedAIStrategy = teamStrategyFactory.createAlliedAIStrategy(this, gameType);
this.axisAIStrategy = teamStrategyFactory.createAxisAIStrategy(this, gameType);

PlayerInfos players = game.getPlayerInfos();
players.forEachPlayerInfo(new PlayerInfoIterator() {
Expand Down
2 changes: 1 addition & 1 deletion src/seventh/ai/basic/FeelSensor.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class FeelSensor implements Sensor, OnDamageListener {
private FeelMemory memory;
private TimeStep timeStep;
private Brain brain;

/**
* @param brain
*/
Expand Down
42 changes: 42 additions & 0 deletions src/seventh/ai/basic/SensorFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package seventh.ai.basic;

import seventh.shared.TimeStep;

public class SensorFactory {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very similar to the Statement comment -- I don't see the added benefit of SensorFactory. The Sensors class already houses all available Sensors -- which negates the need for this class.


protected SightSensor sightSensor;
protected SoundSensor soundSensor;
protected FeelSensor feelSensor;

public SensorFactory(Brain brain){
this.sightSensor = new SightSensor(brain);
this.soundSensor = new SoundSensor(brain);
this.feelSensor = new FeelSensor(brain);
}

public FeelSensor getFeelSensor() {
return feelSensor;
}

public SightSensor getSightSensor() {
return sightSensor;
}

public SoundSensor getSoundSensor() {
return soundSensor;
}

public void reset(Brain brain) {
this.sightSensor.reset(brain);
this.soundSensor.reset(brain);
this.feelSensor.reset(brain);
}

public void update(TimeStep timeStep) {
this.sightSensor.update(timeStep);
this.soundSensor.update(timeStep);
this.feelSensor.update(timeStep);
}


}
22 changes: 7 additions & 15 deletions src/seventh/ai/basic/Sensors.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,12 @@
*/
public class Sensors {

private SightSensor sightSensor;
private SoundSensor soundSensor;
private FeelSensor feelSensor;
private SensorFactory sensorfactory;



public Sensors(Brain brain) {
this.sightSensor = new SightSensor(brain);
this.soundSensor = new SoundSensor(brain);
this.feelSensor = new FeelSensor(brain);
this.sensorfactory = new SensorFactory(brain);
}


Expand All @@ -32,40 +28,36 @@ public Sensors(Brain brain) {
* @param brain
*/
public void reset(Brain brain) {
this.sightSensor.reset(brain);
this.soundSensor.reset(brain);
this.feelSensor.reset(brain);
this.sensorfactory.reset(brain);
}

/**
* @return the feelSensor
*/
public FeelSensor getFeelSensor() {
return feelSensor;
return this.sensorfactory.getFeelSensor();
}

/**
* @return the sightSensor
*/
public SightSensor getSightSensor() {
return sightSensor;
return this.sensorfactory.getSightSensor();
}

/**
* @return the soundSensor
*/
public SoundSensor getSoundSensor() {
return soundSensor;
return this.sensorfactory.getSoundSensor();
}

/**
* Poll each sensor
* @param timeStep
*/
public void update(TimeStep timeStep) {
this.sightSensor.update(timeStep);
this.soundSensor.update(timeStep);
this.feelSensor.update(timeStep);
this.sensorfactory.update(timeStep);
}

}
2 changes: 1 addition & 1 deletion src/seventh/ai/basic/SightSensor.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class SightSensor implements Sensor {
private Timer updateSight;

private List<PlayerEntity> entitiesInView;

/**
* @param width
* @param height
Expand Down
3 changes: 1 addition & 2 deletions src/seventh/ai/basic/SoundSensor.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
* @author Tony
*
*/
public class SoundSensor implements Sensor {

public class SoundSensor implements Sensor{
/**
* Less important sounds
*/
Expand Down
Loading