generated from acm-ndsu/byte_le_engine
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Create grenade object #52
Merged
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b8c6d68
created damaging folder for damaging_object and its cchildren
amanda-f-ndsu 60e38d9
added damaging enums to enums.py
amanda-f-ndsu bc6b0e7
fixed conflict in enums
amanda-f-ndsu 8af832b
fixed enums for realsies this time and started grenade object and uni…
amanda-f-ndsu 1ec97e0
moved grenade test cases into object folder, updated enums, fixed gre…
amanda-f-ndsu 956368c
Updated grenade object and added the to_json and from_json methods
amanda-f-ndsu 4943236
Fixed syntax error in grenade stats and resolved errors/fails from un…
amanda-f-ndsu 18c9b11
updated Grenade name change in TestInit and removed the name mangling…
amanda-f-ndsu 3dd36a9
removed breakpoint from TestInit, added invalid high value to grenade…
amanda-f-ndsu fc66398
changed attributes so that they use the property setter
amanda-f-ndsu 9143cc1
Merge branch 'dev' into Create-Grenade-Object
erickbickler 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 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
File renamed without changes.
This file contains 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,33 @@ | ||
from game.common.moving.damaging.damaging_object import DamagingObject | ||
from game.common.stats import GameStats | ||
from game.common.enums import * | ||
|
||
|
||
class Grenade(DamagingObject): | ||
def __init__(self, fuse_time = GameStats.grenade_stats['min_fuse_time'], range= None, damage= None, | ||
heading = None, speed = None, health=None, coordinates=None, hitbox=None, collidable=None): | ||
super().__init__(range, damage, heading, speed, health, coordinates, hitbox, collidable) | ||
self.__fuse_time = fuse_time | ||
self.object_type = ObjectType.grenade | ||
|
||
@property | ||
def fuse_time(self): | ||
return self.__fuse_time | ||
|
||
@fuse_time.setter | ||
def fuse_time(self, val): | ||
if val >= GameStats.grenade_stats['min_fuse_time']: | ||
self.__fuse_time = val | ||
else: | ||
raise Exception("fuse time value outside bounds, Not set") | ||
|
||
|
||
def to_json(self): | ||
data = super().to_json() | ||
data['fuse_time'] = self.fuse_time | ||
|
||
return data | ||
|
||
def from_json(self, data): | ||
super().from_json(data) | ||
self.fuse_time = data['fuse_time'] |
This file contains 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 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 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 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,51 @@ | ||
import unittest | ||
from game.common.moving.damaging import grenade | ||
from game.common.moving.damaging.grenade import Grenade | ||
from game.common.stats import GameStats | ||
|
||
class TestGrenade(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.grnObj = Grenade(10) | ||
|
||
def test_set_get_fuse_time_valid(self): | ||
self.grnObj.fuse_time = 20 | ||
self.assertEqual(self.grnObj.fuse_time, 20) | ||
|
||
|
||
def test_set_get_fuse_time_invalid_low(self): | ||
HagenSR marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self.assertRaises(Exception, lambda : self.grnObj.fuse_time(0)) | ||
|
||
def test_set_get_fuse_time_boundary_low(self): | ||
self.grnObj.fuse_time = GameStats.grenade_stats['min_fuse_time'] | ||
self.assertEqual(self.grnObj.fuse_time, GameStats.grenade_stats['min_fuse_time']) | ||
|
||
|
||
def test_set_get_fuse_time_boundary_high(self): | ||
self.grnObj.fuse_time = GameStats.grenade_stats['max_fuse_time'] | ||
self.assertEqual(self.grnObj.fuse_time, GameStats.grenade_stats['max_fuse_time']) | ||
|
||
|
||
def test_grenade_obj_parent_params(self): | ||
|
||
testGrn = Grenade(fuse_time = 20, range = 10, damage = 10, heading = 10, speed = 10, health = 1, coordinates=[{'x': 450, 'y': 450}, {'x': 50, 'y': 50}], | ||
hitbox={'width': 10, 'height': 10}, collidable=True) | ||
|
||
self.assertIsNotNone(testGrn.range) | ||
self.assertIsNotNone(testGrn.damage) | ||
self.assertIsNotNone(testGrn.heading) | ||
self.assertIsNotNone(testGrn.speed) | ||
self.assertIsNotNone(testGrn.coordinates) | ||
self.assertIsNotNone(testGrn.hitbox) | ||
self.assertIsNotNone(testGrn.collidable) | ||
|
||
self.assertIsNone(self.grnObj.range) | ||
self.assertIsNone(self.grnObj.damage) | ||
self.assertIsNone(self.grnObj.heading) | ||
self.assertIsNone(self.grnObj.speed) | ||
self.assertIsNone(self.grnObj.coordinates) | ||
self.assertIsNone(self.grnObj.hitbox) | ||
self.assertIsNone(self.grnObj.collidable) | ||
|
||
if __name__ == '__main__': | ||
unittest.main |
This file contains 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
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 should use the property setting so it uses validation
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.
could you clarify which line you're talking about? (I'm assuming you're talking about line 10, but just making sure). I'm looking at damaging_object and moving_object's def init statements and they're pretty much the same- so changes will need to be made to them as well if they weren't already fixed in dev.
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.
Yeah, line 10. The other objects need to be changed as well. If you do self.fuse_time = fuse_time that should use the property setter
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.
Ah, about that- when Sean was working on the clean-up refactor branch, he had initially done that for damaging_object and moving_object, but eventually switched them back to name mangling. We actually had a discussion on that in the pull request if you wanted to pull that up and take a read. For now, I'll wait to proceed until I get a general consensus from you and Sean on how the attributes should be done. The fixes would only take a few moments anyway so it isn't a big rush.
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.
Just looked at the example I posted in dis. The backing variable comes from the property, you can use the property setter in the I init I think. I'll do some testing tonight or early tomorrow tho to double check
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.
Mk. I'll make the changes early tomorrow if need be. Sean mentioned something about problems with a recursive overflow, so it would be good to test and make sure that isn't happening prior to making the changes.
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.
@erickbickler I think name mangling is still needed. In the example you can directly call the backing variable _temperature and change it to whatever without the property being invoked. The name mangling will prevent this and will ensure there are no "Accidental" accesses to the backing field.
test.txt
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.
It's not a question of name mangling it's whether you need to set the internal name mangled variable in the init or if you can use the property setter, if you look at the example init, it uses the property setter. ie self.temperature = temperature
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.
attributes should be fixed now