Skip to content
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

Test player #26

Merged
merged 15 commits into from
Apr 29, 2023
4 changes: 2 additions & 2 deletions game/controllers/movement_controller.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from game.controllers.controller import Controller
from game.common.player import Player
from game.common.map.game_board import GameBoard
from game.common.map.tile import Tile
from game.common.enums import *
from game.utils.vector import Vector
from game.controllers.controller import Controller


class MovementController(Controller):
Expand Down Expand Up @@ -44,4 +44,4 @@ def handle_actions(self, action: ActionType, client: Player, world: GameBoard):
temp = temp.occupied_by

temp.occupied_by = None
client.avatar.position = (temp_vec.x, temp_vec.y)
client.avatar.position = Vector(temp_vec.x, temp_vec.y)
11 changes: 11 additions & 0 deletions game/test_suite/tests/test_master_controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import unittest

from game.controllers.master_controller import MasterController
from game.controllers.movement_controller import MovementController
from game.controllers.interact_controller import InteractController

class TestMasterController(unittest.TestCase):
def setUp(self) -> None:
self.master_controller = MasterController()


Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import unittest

from game.common.action import ActionType
from game.common.avatar import Avatar
from game.common.map.game_board import GameBoard
from game.common.map.wall import Wall
from game.common.player import Player
from game.common.stations.occupiable_station import OccupiableStation
from game.controllers.movement_controller import MovementController
from game.utils.vector import Vector
from game.common.stations.station import Station


class TestMovementControllerIfOccupiableStations(unittest.TestCase):
def setUp(self) -> None:
self.movement_controller = MovementController()

# (1, 0), (2, 0), (0, 1), (0, 2), (1, 3), (2, 3), (3, 1), (3, 2)
self.locations: dict = {(Vector(1, 0), Vector(2, 0), Vector(0, 1), Vector(0, 2), Vector(1, 3), Vector(2, 3),
Vector(3, 1), Vector(3, 2)): [OccupiableStation(None, Wall()),
OccupiableStation(None, Wall()),
OccupiableStation(None, Wall()),
OccupiableStation(None, Wall()),
OccupiableStation(None, Wall()),
OccupiableStation(None, Wall()),
OccupiableStation(None, Wall()),
OccupiableStation(None, Station())]}
self.game_board = GameBoard(0, Vector(4, 4), self.locations, False)
self.occ_station = OccupiableStation()
self.occ_station = OccupiableStation()
self.wall = Wall()
# test movements up, down, left and right by starting with default 3,3 then know if it changes from there \/
self.avatar = Avatar(None, Vector(2, 2), [], 1)
self.client = Player(None, None, [], self.avatar)
self.game_board.generate_map()

# it is not occupied, so you can move there
def test_move_up(self):
# 2, 2
self.movement_controller.handle_actions(ActionType.MOVE_UP, self.client, self.game_board)
self.assertEqual((str(self.client.avatar.position)), str(Vector(2, 1)))

# it is able to move up because it is not occupied,
# but technically still failed since we are only testing it move up once
def test_move_up_fail(self):
self.movement_controller.handle_actions(ActionType.MOVE_UP, self.client, self.game_board)
self.movement_controller.handle_actions(ActionType.MOVE_UP, self.client, self.game_board)
self.movement_controller.handle_actions(ActionType.MOVE_UP, self.client, self.game_board)
self.assertEqual((str(self.client.avatar.position)), str(Vector(2, 1)))

def test_move_down(self):
self.movement_controller.handle_actions(ActionType.MOVE_UP, self.client, self.game_board)
self.movement_controller.handle_actions(ActionType.MOVE_DOWN, self.client, self.game_board)
self.assertEqual((str(self.client.avatar.position)), str(Vector(2, 2)))

def test_move_down_fail(self):
self.movement_controller.handle_actions(ActionType.MOVE_DOWN, self.client, self.game_board)
self.assertEqual((str(self.client.avatar.position)), str(Vector(2, 2)))

def test_move_left(self):
self.movement_controller.handle_actions(ActionType.MOVE_LEFT, self.client, self.game_board)
self.assertEqual((str(self.client.avatar.position)), str(Vector(1, 2)))

def test_move_left_fail(self):
self.movement_controller.handle_actions(ActionType.MOVE_LEFT, self.client, self.game_board)
self.assertEqual((str(self.client.avatar.position)), str(Vector(1, 2)))

def test_move_right(self):
self.movement_controller.handle_actions(ActionType.MOVE_LEFT, self.client, self.game_board)
self.movement_controller.handle_actions(ActionType.MOVE_RIGHT, self.client, self.game_board)
self.assertEqual((str(self.client.avatar.position)), str(Vector(2, 2)))

def test_move_right_fail(self):
self.movement_controller.handle_actions(ActionType.MOVE_RIGHT, self.client, self.game_board)
self.assertEqual((str(self.client.avatar.position)), str(Vector(2, 2)))

63 changes: 63 additions & 0 deletions game/test_suite/tests/test_movement_controller_if_stations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import unittest

from game.controllers.movement_controller import MovementController
from game.common.map.game_board import GameBoard
from game.common.stations.station import Station
from game.common.stations.occupiable_station import OccupiableStation
from game.common.map.wall import Wall
from game.utils.vector import Vector
from game.common.player import Player
from game.common.avatar import Avatar
from game.common.action import ActionType
from game.common.game_object import GameObject


class TestMovementControllerIfStations(unittest.TestCase):
def setUp(self) -> None:
self.movement_controller = MovementController()
# (1, 0), (2, 0), (0, 1), (0, 2), (1, 3), (2, 3), (3, 1), (3, 2)
self.locations: dict = {(Vector(1, 0), Vector(2, 0), Vector(0, 1), Vector(0, 2), Vector(1, 3), Vector(2, 3),
Vector(3, 1), Vector(3, 2)): [Station(None), Station(None), Station(None),
Station(None), Station(None), Station(None),
Station(None), Station(None)]}

self.occ_station = OccupiableStation()
self.game_board = GameBoard(0, Vector(4, 4), self.locations, True)
self.wall = Wall()
# test movements up, down, left and right by starting with default 3,3 then know if it changes from there \/
self.avatar = Avatar(None, Vector(2, 2), [], 1)
self.client = Player(None, None, [], self.avatar)
self.game_board.generate_map()

# if there is a station
def test_move_up(self):
self.movement_controller.handle_actions(ActionType.MOVE_UP, self.client, self.game_board)
self.assertEqual((str(self.client.avatar.position)), str(Vector(2, 1)))

def test_move_up_fail(self):
self.movement_controller.handle_actions(ActionType.MOVE_UP, self.client, self.game_board)
self.assertEqual((str(self.client.avatar.position)), str(Vector(2, 1)))

def test_move_down(self):
self.movement_controller.handle_actions(ActionType.MOVE_DOWN, self.client, self.game_board)
self.assertEqual((str(self.client.avatar.position)), str(Vector(2, 2)))

def test_move_down_fail(self):
self.movement_controller.handle_actions(ActionType.MOVE_DOWN, self.client, self.game_board)
self.assertEqual((str(self.client.avatar.position)), str(Vector(2, 2)))

def test_move_left(self):
self.movement_controller.handle_actions(ActionType.MOVE_LEFT, self.client, self.game_board)
self.assertEqual((str(self.client.avatar.position)), str(Vector(1, 2)))

def test_move_down_fail(self):
self.movement_controller.handle_actions(ActionType.MOVE_LEFT, self.client, self.game_board)
self.assertEqual((str(self.client.avatar.position)), str(Vector(1, 2)))

def test_move_right(self):
self.movement_controller.handle_actions(ActionType.MOVE_RIGHT, self.client, self.game_board)
self.assertEqual((str(self.client.avatar.position)), str(Vector(2, 2)))

def test_move_right_fail(self):
self.movement_controller.handle_actions(ActionType.MOVE_RIGHT, self.client, self.game_board)
self.assertEqual((str(self.client.avatar.position)), str(Vector(2, 2)))
71 changes: 71 additions & 0 deletions game/test_suite/tests/test_movement_controller_if_wall.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import unittest

from game.common.map.game_board import GameBoard
from game.controllers.movement_controller import MovementController
from game.common.stations.station import Station
from game.common.stations.occupiable_station import OccupiableStation
from game.common.map.wall import Wall
from game.utils.vector import Vector
from game.common.player import Player
from game.common.action import ActionType
from game.common.avatar import Avatar
from game.common.game_object import GameObject


class TestMovementControllerIfWall(unittest.TestCase):
def setUp(self) -> None:
self.movement_controller = MovementController()
self.avatar = Avatar(None, Vector(2, 2), [], 1)
self.locations: dict[tuple[Vector]: list[GameObject]] = {
(Vector(2, 2),): [self.avatar]
}
self.game_board = GameBoard(0, Vector(4, 4), self.locations, True)
self.station = Station()
self.occupiable_station = OccupiableStation()
self.occupiable_station = OccupiableStation()
self.wall = Wall()
# test movements up, down, left and right by starting with default 3,3 then know if it changes from there \/
self.client = Player(None, None, [], self.avatar)
self.game_board.generate_map()

# if there is a wall
def test_move_up(self):
self.movement_controller.handle_actions(ActionType.MOVE_UP, self.client, self.game_board)
self.assertEqual((str(self.client.avatar.position)), str(Vector(2, 1)))

def test_move_up_fail(self):
self.movement_controller.handle_actions(ActionType.MOVE_UP, self.client, self.game_board)
self.assertEqual((str(self.client.avatar.position)), str(Vector(2, 1)))

def test_move_down(self):
self.movement_controller.handle_actions(ActionType.MOVE_DOWN, self.client, self.game_board)
self.assertEqual((str(self.client.avatar.position)), str(Vector(2, 2)))

def test_move_down_fail(self):
self.movement_controller.handle_actions(ActionType.MOVE_DOWN, self.client, self.game_board)
self.assertEqual((str(self.client.avatar.position)), str(Vector(2, 2)))

def test_move_left(self):
self.movement_controller.handle_actions(ActionType.MOVE_LEFT, self.client, self.game_board)
self.assertEqual((str(self.client.avatar.position)), str(Vector(1, 2)))

def test_move_down_fail(self):
self.movement_controller.handle_actions(ActionType.MOVE_LEFT, self.client, self.game_board)
self.assertEqual((str(self.client.avatar.position)), str(Vector(1, 2)))

def test_move_right(self):
self.movement_controller.handle_actions(ActionType.MOVE_RIGHT, self.client, self.game_board)
self.assertEqual((str(self.client.avatar.position)), str(Vector(2, 2)))

def test_move_right_fail(self):
self.movement_controller.handle_actions(ActionType.MOVE_RIGHT, self.client, self.game_board)
self.assertEqual((str(self.client.avatar.position)), str(Vector(2, 2)))