-
Notifications
You must be signed in to change notification settings - Fork 30
Apply design pattern to some classes #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
terry2511
wants to merge
64
commits into
tonysparks:master
Choose a base branch
from
terry2511:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
64 commits
Select commit
Hold shift + click to select a range
63ec1c8
updateCameraForRoamingMovements Method Refactoring
cokacider fb98c87
convert taps to 4 spaces
cokacider f04dd53
Refactoring IS-A Relationship
aikaran 3f6ccf8
Replace the number of weapon classes with a constant
cokacider 49273eb
Extract methods createTitleLabel, createCancelButton
cokacider b46130a
convert tabs to 4 spaces
cokacider b86c248
Rename method
cokacider 9500b91
Merge pull request #10 from aikaran/master
terry2511 f70a11b
Refactoring game/entities and map
terry2511 5991915
Door Update
terry2511 e9bd731
Merge branch 'master' of https://github.com/terry2511/seventh.git
39e527a
Extract Method
aikaran 39bdfdd
Extract methods from refreshButtons method
cokacider 0aeb486
Refactoring refreshButtons method
cokacider 82e78a5
Refactoring Seventh.game.type.obj.ObjectiveScript.java
GardenHee 113af0b
Refactoring getClassDescription method
cokacider 2672475
convert all tabs in WeaponClassDescription.java to 4 spaces
cokacider 05a1c3b
1.extract method, move method
virginbabylon d5814e2
add function comment
aikaran f52efe1
Refactoring : Extract Method
aikaran 7c3b799
1.
4140406
1.Replace Temp with Query
virginbabylon 02d040b
Extract printBitArray method to remove duplicate code.
26f6245
Refactoring dumptBytes.
87cc6ab
Refactoring ClientGame.java
terry2511 2881403
Merge pull request #11 from aikaran/master
terry2511 213bbc1
Merge pull request #13 from GardenHee/master
terry2511 fc6b3d7
Merge pull request #14 from cokacider/master
terry2511 091ef68
Merge pull request #16 from bananapizza/master
terry2511 32c8b17
1.extract method, move method
virginbabylon eb745b9
1.extract method, move method
virginbabylon 2dbea2d
1.extract method, move method
virginbabylon 1b6bb5c
1.extract method, move method
virginbabylon cf0ae61
Merge branch 'master' into master
terry2511 cf1231d
Merge pull request #19 from virginbabylon/master
terry2511 04631b3
correct the function type
aikaran cba0073
Merge branch 'master' of https://github.com/terry2511/seventh.git
aikaran c170b80
Design Pattern : Strategy Pattern
aikaran 9069b99
fix some error
aikaran bb1153f
Apply a design pattern (Template Method Pattern)
cokacider 1d2f4c8
all tabs in World.java convert to 4 spaces
cokacider d487313
Apply a design pattern (Abstract Factory Pattern)
cokacider 8f2fe16
Merge pull request #1 from cokacider/master
terry2511 4bd1aae
StrategyPattern
aikaran 12b61fd
Fork again
aikaran f701c0b
Factory Method Pattern
aikaran 94bd189
fix syntax error
aikaran 1eeefd6
Singleton Pattern
aikaran 2479d4c
replace all tabs to 4 spaces
aikaran 65e372a
Merge pull request #2 from aikaran/master
terry2511 ce9f243
Strategy Pattern
b27aca5
Strategy Pattern
terry2511 54b7970
Merge branch 'master' of https://github.com/terry2511/seventh.git
d5031ce
Strategy Pattern
terry2511 08b730f
Design Pattern: Factory Method Pattern
GardenHee c01c276
ai/basic/memory
virginbabylon 2d82709
Merge pull request #3 from GardenHee/master
terry2511 fc7e7bb
Merge pull request #5 from virginbabylon/master
terry2511 fd81bf8
Apply design patterns - Observer, Template Method, Factory Method
26527e8
Merge pull request #6 from bananapizza/master
terry2511 adb6954
tab -> 4 spaces
virginbabylon a16fb1a
Merge pull request #7 from virginbabylon/master
terry2511 913256b
Change tab to 4 spaces
2d70d94
Merge pull request #8 from bananapizza/master
terry2511 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
|
|
||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
|
|
||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very similar to the |
||
|
|
||
| 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); | ||
| } | ||
|
|
||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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,Statementand the concrete classes ofBitStatementandByteStatement(along with grappling the inheritance).