Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Abdi Danny 2019 ZHAC232 100938755 FINAL YEAR PROJECT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Abdi Danny (2019) ZHAC232
Abdi Danny 2019 ZHAC232 100938755 FINAL YEAR PROJECT
Commits
0a6bfc83
Commit
0a6bfc83
authored
1 year ago
by
DannyAbdi
Browse files
Options
Downloads
Patches
Plain Diff
Created enemy class to represent enemy agents in the maze
parent
af00288d
Branches
Branches containing commit
Tags
Tags containing commit
Loading
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
button_dfs.png
+0
-0
0 additions, 0 deletions
button_dfs.png
enemy.py
+45
-0
45 additions, 0 deletions
enemy.py
with
45 additions
and
0 deletions
button_dfs.png
deleted
100644 → 0
+
0
−
0
View file @
af00288d
1.8 KiB
This diff is collapsed.
Click to expand it.
enemy.py
0 → 100644
+
45
−
0
View file @
0a6bfc83
import
random
from
config
import
*
"""
Class representing an enemy agent in the game.
"""
class
Enemy
:
"""
Initialise the Enemy object.
:param maze (Maze): The maze object representing the game environment.
:param x (int): The x-coordinate of the enemy
'
s position.
:param y (int): The y-coordinate of the enemy
'
s position.
"""
def
__init__
(
self
,
maze
):
self
.
maze
=
maze
self
.
x
,
self
.
y
=
self
.
reset_position
()
"""
Reset the position of the enemy to a valid starting position in the maze.
:return: tuple: A tuple containing the x and y coordinates of the enemy
'
s position.
"""
def
reset_position
(
self
):
while
True
:
num_rows
=
self
.
maze
.
num_rows
()
num_cols
=
self
.
maze
.
num_columns
()
random_row
=
random
.
randint
(
0
,
num_rows
-
1
)
start_col
=
num_cols
-
2
self
.
x
=
start_col
*
TILE_SIZE
self
.
y
=
random_row
*
TILE_SIZE
if
self
.
maze
[
random_row
][
start_col
]
!=
1
:
return
self
.
x
,
self
.
y
"""
Draw the enemy on the screen.
:param screen: The Pygame screen surface to draw on.
"""
def
draw
(
self
,
screen
):
pygame
.
draw
.
rect
(
screen
,
'
blue
'
,
(
self
.
x
,
self
.
y
,
TILE_SIZE
,
TILE_SIZE
))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment