generated from acm-ndsu/byte_le_engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from HagenSR/Create-Grenade-Object
Create grenade object
- Loading branch information
Showing
9 changed files
with
115 additions
and
13 deletions.
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
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,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'] and val <= GameStats.grenade_stats['max_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
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,54 @@ | ||
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): | ||
self.assertRaises(Exception, lambda : self.grnObj.fuse_time(0)) | ||
|
||
def test_set_get_fuse_time_invalid_high(self): | ||
self.assertRaises(Exception, lambda : self.grnObj.fuse_time(100)) | ||
|
||
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