dass-ass-2's People
dass-ass-2's Issues
Ambigous Townhall import and use in game.py
- Townhall class is imported twice in game.py
- It is also used as a singleton(?) in
Line 146 in 407bae3
Suggested refractoring
- Find use of both the classes
- Name them properly and/or remove unused stuff
- Fix import
Barbarians don't change target after destroying a wall
Barbarians choose the same wall as the new target after they destroy a Townhall wall. The result of this is that all the Barbarians don't move and are stuck when their target wall is destroyed.
The reason for this is that we don't set self.death
property of wall to be True
when a wall is destroyed unlike other buildings
dass-ass-2/old-code/building.py
Lines 134 to 135 in d55a7e0
Fix:
Set the self.death
property to be True
:
if(self.health <= 0):
self.color = Back.LIGHTGREEN_EX + " " + Style.RESET_ALL
self.death = True
Unused abstraction
Buildings like cannon, townhall etc. inherit from the Building
class, but this abstraction is not used properly. The aim was to have a static list of all buildings and all its base types for easy querying.
Lines 81 to 84 in 407bae3
Line 89 in 407bae3
Code smell: Unexploited encapsulation, duplicated code
Suggested refractor
- Base abstract entity class, which has
init
,render(colorArray, idArray)
andtick()
function Game
class should support querying active entities by their type
Maybe incorrect colorama init
Colorama should be initialized only once, and by setting autoreset
to True
.
excessive use of literals
In many places all over the code, lines like this exist
dass-ass-2/old-code/building.py
Lines 157 to 172 in 344c0cc
The code assumes height and width, instead it should be using values rows
and columns
.
This issue is the single place for all instances like this.
Code smell: Excessive use of literals
Duplicated code in Townhall render function
There is a lot of duplicated code with just the color changed for each health level in the Townhall
class render
function
dass-ass-2/old-code/townhall.py
Lines 12 to 31 in 23b10dc
Suggested Refactor:
- Make a new function which takes the color as input and marks the
colorarray
forTownhall
to that color
Duplicate renderX functions in game.py
Code smell: Duplicate code
Lines 88 to 106 in 9be8b76
Suggested refractor
- One function which takes a list as input, or,
- Base class for objects that can be rendered, then we keep just one list for all active objects and render them
git workflow
- do a fork
- add this repo as
upstream
usinggit remote add upstream [email protected]:Kyrylo-Shyvam/dass-ass-2.git
- do
git pull --rebase upstream master
- work in master/feature branch
- do
git push origin branch
- squash(in case many commits) merge PR yourself if small or wait for review
- after merging do
git pull --rebase upstream master
because the history will be different
Do only meaningful commits, dont make a commit after every change. If you do then squash them in one.
Terminal settings are not reset after game exits
The following lines modify the terminal to enable raw mode. But the game doesn't reset the settings.
Lines 10 to 19 in 407bae3
Fix: keep the old_settings
and set them when exiting.
Mysterious name for the Game Class
The game class only prints the colors filled with other classes. It does nothing else. All the other functionality is in game.py
.
Code Smell: Lazy class/freeloader and Mysterious name
Suggested Refractor
- Rename this class to something like
Renderer
or, - Move actual game logic to this class, making the
game.py
just create an instance ofGame
and call itsplay()
orrun()
function
Broken Rendering
- King sometimes is rendered as two blocks at different positions instead of one long rectangle.
- Size of the map changes after some time.
- Weird rendering of right boundaries.
- Moving king also moves other objects
Fix: I think the screen isn't cleared properly before rendering. We should first investigate that, and then investigate individual classes. We can also make a class which contains methods for filling a specified area on the console with a specified color. So the rendering code is at one place only.
King movement broken after touching boundaries
When king touches any boundary, then it wont be able to move in the direction opposite to the boundary. Lets say the king is touching the left boundary, then it wont be able to move right. Similar for boundaries in all direction. Touching any corner will disable movement all together.
Fix: Read and fix kings movement code.
Ambiguous function definition
A method called spawn
is imported on line 2:
Line 2 in 9860e82
But this method is defined again on line 115:
Line 115 in 9860e82
Also, this function has a lot of duplicate code which can easily be fixed.
Lines 116 to 130 in 9860e82
Code Smell: ambiguous definition and Repetitive code.
Suggestion: Delete the unused import and remove repetitions.
Pressing 'h' key crashes the game
healStart
function is invoked when h
key is pressed:
Lines 229 to 231 in 21d7c31
The following code is run inside healStart
which crashes the game:
Lines 147 to 150 in 21d7c31
The reason for the crash is that Townhall
has no attribute health
which we are trying to access
Fix:
Change Townhall
to townhall
in the above code because Townhall
is the class while townhall
is an instance of that class with health
property
Large conditional block and repetitive code
Inside move method in barbarians.py.
dass-ass-2/old-code/barbarians.py
Lines 56 to 74 in 23b10dc
Code Smell: Conditional complexity and repetitive code.
Suggested Refactoring:
- Remove the large code block inside the if statement and keep and if statement at the top with a return inside.
if(self.target == None):
return idArray
- Use a for loop to iterate through all the possible movements instead of repetitive conditional code.
many branches and long lines in kingclass
Lines 64 to 252 in 407bae3
Code smell: Many branches(cyclomatic complexity), long lines(god lines)
Suggested refractor
- Find and refractor common code into functions
- Format properly
Game is not visible after spawning many barbarians
Hold c
to spawn barbarians. Due to the print statements the game is no longer or partially visible.
Fix: Remove the print statements
input method shouldn't be in king class
dass-ass-2/old-code/kingclass.py
Line 23 in 6a7702e
This function has no relation to king class. It can just be a utility function.
Suggested Refractor
- Move it out of king class into some utility class.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.