-
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.
* Balancing Added values to the already existing active abilities to add basic balancing * Ability setup Started the setup for creating the new active ability * Ability tests Created tests that should've been there for other abilities and a test for trap defusal * Create test_defuse_controller.py Tested the defuse controller * Mining cap Implemented check in the mine controller that prevents the avatar from mining when inventory is full
- Loading branch information
1 parent
32baf64
commit 307eaaa
Showing
16 changed files
with
318 additions
and
35 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
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,10 @@ | ||
from game.quarry_rush.ability.active_ability import ActiveAbility | ||
from game.common.enums import ObjectType | ||
|
||
|
||
class TrapDefusalActiveAbility(ActiveAbility): | ||
def __init__(self, cooldown: int = 0, fuse: int = 0): | ||
super().__init__() | ||
self.object_type = ObjectType.TRAP_DEFUSAL_ACTIVE_ABILITY | ||
self.cooldown = cooldown # default = 0 to always be available | ||
self.fuse = fuse # default = 0 to be available right after purchase |
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,63 @@ | ||
import unittest | ||
|
||
from game.common.action import ActionType | ||
from game.common.avatar import Avatar | ||
from game.common.game_object import GameObject | ||
from game.common.map.game_board import GameBoard | ||
from game.common.player import Player | ||
from game.controllers.defuse_controller import DefuseController | ||
from game.quarry_rush.entity.placeable.traps import Landmine, EMP | ||
from game.utils.vector import Vector | ||
|
||
|
||
class TestDefuseController(unittest.TestCase): | ||
def setUp(self): | ||
self.avatar: Avatar = Avatar() | ||
self.avatar.science_points = 5000 # to unlock trap defusal | ||
self.avatar.buy_new_tech('Improved Mining') | ||
self.avatar.buy_new_tech('Dynamite') | ||
self.avatar.buy_new_tech('Landmines') | ||
self.avatar.buy_new_tech('Trap Defusal') | ||
|
||
self.defuse_controller: DefuseController = DefuseController() | ||
self.locations: dict[tuple[Vector], list[GameObject]] = { | ||
(Vector(1, 0),): [Landmine()], # above avatar | ||
(Vector(0, 1),): [EMP()], # left of avatar | ||
(Vector(1, 1),): [self.avatar], # center | ||
(Vector(2, 1),): [EMP()], # right of avatar | ||
(Vector(1, 2),): [Landmine()] # below avatar | ||
} | ||
|
||
# make a 3x3 game board | ||
self.world: GameBoard = GameBoard(0, Vector(3, 3), self.locations, False) | ||
self.client = Player(None, None, [], self.avatar) | ||
self.world.generate_map() | ||
|
||
# test defusing a trap above works | ||
def test_defuse_trap_above(self): | ||
self.assertTrue(self.world.game_map[0][1].is_occupied_by_game_object(Landmine)) | ||
self.defuse_controller.handle_actions(ActionType.DEFUSE_UP, self.client, self.world) | ||
self.assertFalse(self.world.game_map[0][1].is_occupied_by_game_object(Landmine)) # remember (y, x) coordinates | ||
|
||
# test defusing a trap to the right works | ||
def test_defuse_trap_to_right(self): | ||
self.assertTrue(self.world.game_map[1][2].is_occupied_by_game_object(EMP)) | ||
self.defuse_controller.handle_actions(ActionType.DEFUSE_RIGHT, self.client, self.world) | ||
self.assertFalse(self.world.game_map[1][2].is_occupied_by_game_object(EMP)) | ||
|
||
# test defusing a trap below works | ||
def test_defuse_trap_below(self): | ||
self.assertTrue(self.world.game_map[2][1].is_occupied_by_game_object(Landmine)) | ||
self.defuse_controller.handle_actions(ActionType.DEFUSE_DOWN, self.client, self.world) | ||
self.assertFalse(self.world.game_map[2][1].is_occupied_by_game_object(Landmine)) | ||
|
||
# test defusing a trap to the left works | ||
def test_defuse_trap_to_left(self): | ||
self.assertTrue(self.world.game_map[1][0].is_occupied_by_game_object(EMP)) | ||
self.defuse_controller.handle_actions(ActionType.DEFUSE_LEFT, self.client, self.world) | ||
self.assertFalse(self.world.game_map[1][0].is_occupied_by_game_object(EMP)) | ||
|
||
# test defusing the same spot causes no errors | ||
def test_defuse_twice(self): | ||
self.test_defuse_trap_above() | ||
self.assertFalse(self.world.game_map[0][1].is_occupied_by_game_object(Landmine)) |
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,67 @@ | ||
import unittest | ||
from game.quarry_rush.ability.emp_active_ability import EMPActiveAbility | ||
|
||
|
||
class TestEMPActiveAbility(unittest.TestCase): | ||
""" | ||
This is class that tests the Trap Defusal Active Ability | ||
""" | ||
|
||
# set up | ||
def setUp(self) -> None: | ||
self.emp_active_ability: EMPActiveAbility = EMPActiveAbility() | ||
|
||
# test: cooldown | ||
def test_cooldown(self): | ||
self.emp_active_ability.cooldown = 1 | ||
self.assertEqual(self.emp_active_ability.cooldown, 1) | ||
|
||
# fail test: cooldown CANT be null | ||
def test_cooldown_fail_null(self): | ||
with self.assertRaises(ValueError) as e: | ||
self.emp_active_ability.cooldown = None | ||
self.assertEqual(str(e.exception), 'EMPActiveAbility.cooldown must be an int') | ||
|
||
# fail test: cooldown cant be anything else | ||
def test_cooldown_fail_str(self): | ||
with self.assertRaises(ValueError) as e: | ||
self.emp_active_ability.cooldown = "" | ||
self.assertEqual(str(e.exception), 'EMPActiveAbility.cooldown must be an int') | ||
|
||
# fail test: cooldown cannot be negative | ||
def test_cooldown_fail_negative(self): | ||
with self.assertRaises(ValueError) as e: | ||
self.emp_active_ability.cooldown = -1 | ||
self.assertEqual(str(e.exception), 'EMPActiveAbility.cooldown cannot be negative') | ||
|
||
# test: fuse | ||
def test_fuse(self): | ||
self.fuse = 1 | ||
self.emp_active_ability.fuse = 1 | ||
self.assertEqual(self.emp_active_ability.fuse, self.fuse) | ||
|
||
# fail test: fuse CANT be null | ||
def test_fuse_fail_null(self): | ||
with self.assertRaises(ValueError) as e: | ||
self.emp_active_ability.fuse = None | ||
self.assertEqual(str(e.exception), 'EMPActiveAbility.fuse must be an int') | ||
|
||
# fail test: fuse cannot be anything else | ||
def test_fuse_fail_str(self): | ||
with self.assertRaises(ValueError) as e: | ||
self.emp_active_ability.fuse = "" | ||
self.assertEqual(str(e.exception), 'EMPActiveAbility.fuse must be an int') | ||
|
||
# fail test: fuse cannot be negative | ||
def test_fuse_fail_negative(self): | ||
with self.assertRaises(ValueError) as e: | ||
self.emp_active_ability.fuse = -1 | ||
self.assertEqual(str(e.exception), 'EMPActiveAbility.fuse cannot be negative') | ||
|
||
# test: json | ||
def test_emp_active_ability_json(self): | ||
data: dict = self.emp_active_ability.to_json() | ||
emp_active_ability: EMPActiveAbility = EMPActiveAbility().from_json(data) | ||
self.assertEqual(self.emp_active_ability.cooldown, emp_active_ability.cooldown) | ||
self.assertEqual(self.emp_active_ability.fuse, emp_active_ability.fuse) | ||
self.assertEqual(self.emp_active_ability.object_type, emp_active_ability.object_type) |
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,68 @@ | ||
import unittest | ||
from game.quarry_rush.ability.landmine_active_ability import LandmineActiveAbility | ||
from game.utils.vector import Vector | ||
|
||
|
||
class TestLandmineActiveAbility(unittest.TestCase): | ||
""" | ||
This is class that tests the Landmine Active Ability | ||
""" | ||
|
||
# set up | ||
def setUp(self) -> None: | ||
self.landmine_active_ability: LandmineActiveAbility = LandmineActiveAbility() | ||
|
||
# test: cooldown | ||
def test_cooldown(self): | ||
self.landmine_active_ability.cooldown = 1 | ||
self.assertEqual(self.landmine_active_ability.cooldown, 1) | ||
|
||
# fail test: cooldown CANT be null | ||
def test_cooldown_fail_null(self): | ||
with self.assertRaises(ValueError) as e: | ||
self.landmine_active_ability.cooldown = None | ||
self.assertEqual(str(e.exception), 'LandmineActiveAbility.cooldown must be an int') | ||
|
||
# fail test: cooldown cant be anything else | ||
def test_cooldown_fail_str(self): | ||
with self.assertRaises(ValueError) as e: | ||
self.landmine_active_ability.cooldown = "" | ||
self.assertEqual(str(e.exception), 'LandmineActiveAbility.cooldown must be an int') | ||
|
||
# fail test: cooldown cannot be negative | ||
def test_cooldown_fail_negative(self): | ||
with self.assertRaises(ValueError) as e: | ||
self.landmine_active_ability.cooldown = -1 | ||
self.assertEqual(str(e.exception), 'LandmineActiveAbility.cooldown cannot be negative') | ||
|
||
# test: fuse | ||
def test_fuse(self): | ||
self.fuse = 1 | ||
self.landmine_active_ability.fuse = 1 | ||
self.assertEqual(self.landmine_active_ability.fuse, self.fuse) | ||
|
||
# fail test: fuse CANT be null | ||
def test_fuse_fail_null(self): | ||
with self.assertRaises(ValueError) as e: | ||
self.landmine_active_ability.fuse = None | ||
self.assertEqual(str(e.exception), 'LandmineActiveAbility.fuse must be an int') | ||
|
||
# fail test: fuse cannot be anything else | ||
def test_fuse_fail_str(self): | ||
with self.assertRaises(ValueError) as e: | ||
self.landmine_active_ability.fuse = "" | ||
self.assertEqual(str(e.exception), 'LandmineActiveAbility.fuse must be an int') | ||
|
||
# fail test: fuse cannot be negative | ||
def test_fuse_fail_negative(self): | ||
with self.assertRaises(ValueError) as e: | ||
self.landmine_active_ability.fuse = -1 | ||
self.assertEqual(str(e.exception), 'LandmineActiveAbility.fuse cannot be negative') | ||
|
||
# test: json | ||
def test_landmine_active_ability_json(self): | ||
data: dict = self.landmine_active_ability.to_json() | ||
landmine_active_ability: LandmineActiveAbility = LandmineActiveAbility().from_json(data) | ||
self.assertEqual(self.landmine_active_ability.cooldown, landmine_active_ability.cooldown) | ||
self.assertEqual(self.landmine_active_ability.fuse, landmine_active_ability.fuse) | ||
self.assertEqual(self.landmine_active_ability.object_type, landmine_active_ability.object_type) |
Oops, something went wrong.