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

Unit Tests & Minimap Toggle #232

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
5b83f4f
Merge pull request #212 from Stephenson-Software/main
dmccoystephenson Feb 7, 2023
6b93340
Changed version to 0.8.0-SNAPSHOT for development towards next release.
dmccoystephenson Feb 7, 2023
8bcc49f
Merge branch 'develop' of https://github.com/Stephenson-Software/Unti…
dmccoystephenson Feb 7, 2023
8ed5362
Added unit tests for 'src/entity' package.
dmccoystephenson Feb 9, 2023
4c506c1
Modified test.sh
dmccoystephenson Feb 9, 2023
9fcaedc
Added solid check to test_chicken.py
dmccoystephenson Feb 9, 2023
47333c3
Cleaned up test_livingEntity.py a bit.
dmccoystephenson Feb 9, 2023
b94252b
Merge pull request #218 from Stephenson-Software/tests/entity-tests
dmccoystephenson Feb 9, 2023
e3de4ba
Added unit tests for Stats class.
dmccoystephenson Feb 9, 2023
7d63bf1
Merge pull request #219 from Stephenson-Software/tests/stats-tests
dmccoystephenson Feb 9, 2023
2f4b231
Added unit tests for Player class.
dmccoystephenson Feb 9, 2023
6b16877
Merge pull request #220 from Stephenson-Software/tests/player-tests
dmccoystephenson Feb 9, 2023
e4f0320
Made test.sh generate coverage file and display coverage in console.
dmccoystephenson Feb 11, 2023
8938e56
Added python and pip checks to run.sh script.
dmccoystephenson Feb 11, 2023
b357045
Cleaned up run.sh script.
dmccoystephenson Feb 11, 2023
643bc52
Called tests in run.sh script.
dmccoystephenson Feb 11, 2023
64bce82
Added showMiniMap config option toggleable with 'M'
dmccoystephenson Feb 13, 2023
4a6de4f
Merge pull request #222 from Stephenson-Software/feature/minimap-toggle
dmccoystephenson Feb 13, 2023
02c39eb
Moved image assets to 'assets/images'
dmccoystephenson Feb 19, 2023
f586c06
Removed generateMapImage config option and printed a warning if ticks…
dmccoystephenson Feb 19, 2023
1c2d316
Fixed tests not passing due to assets directory reorganization.
dmccoystephenson Feb 20, 2023
33f039e
Added format script & reformatted project files.
dmccoystephenson Feb 27, 2023
6cfae0e
Added unit tests for Inventory & InventorySlot classes.
dmccoystephenson Feb 27, 2023
3959b81
Added tests for InventoryJsonReaderWriter class.
dmccoystephenson Mar 12, 2023
883e76e
Merge pull request #225 from Stephenson-Software/testing/inventory-pa…
dmccoystephenson Mar 12, 2023
437de90
Merge pull request #228 from Preponderous-Software/main
dmccoystephenson Aug 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ saves/*/*.json
saves/*/rooms/*.json
saves/*/roompngs/*.png
saves/*/mapImage.png
output.txt
output.txt
.coverage
tests/stats/*.json
cov.xml
tests/*/*.json
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
4 changes: 4 additions & 0 deletions format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
black src
black tests
autoflake --in-place --remove-all-unused-imports --remove-unused-variables -r src
autoflake --in-place --remove-all-unused-imports --remove-unused-variables -r tests
4 changes: 4 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[pytest]
pythonpath = .
src
src/entity
Binary file modified requirements.txt
Binary file not shown.
70 changes: 56 additions & 14 deletions run.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,60 @@
# get the latest version of the code
echo "Pulling latest version of code from GitHub"
git pull
# /bin/bash
# Usage: ./run.sh

# print branch status
echo "Current branch: $(git branch --show-current)"
getLatest() {
# get the latest version of the code
echo "Pulling latest version of code from GitHub"
git pull
echo ""
}

# read in and print version
echo "Current version: $(cat version.txt)"
printBranchStatus() {
# print the current branch
echo "Current branch: $(git branch --show-current)"
echo ""
}

# check that dependencies are installed
echo "Checking dependencies"
pip install pygame --pre --quiet
pip install -r requirements.txt --quiet
printVersion() {
# print the current version
echo "Current version: $(cat version.txt)"
echo ""
}

# start program
echo "Starting program"
python src/roam.py > output.txt
checkDependencies() {
# check that dependencies are installed
echo "Checking dependencies"
if ! command -v python &> /dev/null
then
echo "Python could not be found. Download it from https://www.python.org/downloads/"
exit
fi
if ! command -v pip &> /dev/null
then
echo "Pip could not be found. Download it from https://pip.pypa.io/en/stable/installation/ or run 'python -m ensurepip' in a terminal"
exit
fi
pip install pygame --pre --quiet
pip install -r requirements.txt --quiet
echo ""
}

runTests() {
# run tests
echo "Running tests"
python -m pytest
echo ""
}

startProgram() {
# start program
echo "Starting program"
python src/roam.py > output.txt
}

# main
getLatest
printBranchStatus
printVersion
checkDependencies
runTests
startProgram
Empty file added src/__init__.py
Empty file.
12 changes: 6 additions & 6 deletions src/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ def __init__(self):
# static (cannot be changed in game)
self.displayWidth = pygame.display.Info().current_h * 0.90
self.displayHeight = pygame.display.Info().current_h * 0.90
self.black = (0,0,0)
self.white = (255,255,255)
self.black = (0, 0, 0)
self.white = (255, 255, 255)
self.playerMovementEnergyCost = 0.2
self.playerInteractionEnergyCost= 0.05
self.playerInteractionEnergyCost = 0.05
self.runSpeedFactor = 2
self.energyDepletionRate = 0.01
self.playerInteractionDistanceLimit = 5
self.ticksPerSecond = 30
self.gridSize = 17
self.worldBorder = 0 # 0 = no border
self.worldBorder = 0 # 0 = no border
self.pathToSaveDirectory = "saves/defaultsavefile"

# dynamic (can be changed in game)
self.debug = True
self.fullscreen = False
self.autoEatFoodInInventory = True
self.generateMapImage = True
self.removeDeadEntities = True
self.removeDeadEntities = True
self.showMiniMap = True
8 changes: 4 additions & 4 deletions src/entity/apple.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
# @since August 8th, 2022
class Apple(Food):
def __init__(self):
Food.__init__(self, "Apple", "assets/apple.png", random.randrange(5, 11))
self.solid = False
Food.__init__(self, "Apple", "assets/images/apple.png", random.randrange(5, 11))
self.solid = False

def isSolid(self):
return self.solid
return self.solid
10 changes: 6 additions & 4 deletions src/entity/banana.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
# @since January 28th, 2023
class Banana(Food):
def __init__(self):
Food.__init__(self, "Banana", "assets/banana.png", random.randrange(10, 20))
self.solid = False

Food.__init__(
self, "Banana", "assets/images/banana.png", random.randrange(10, 20)
)
self.solid = False

def isSolid(self):
return self.solid
return self.solid
7 changes: 3 additions & 4 deletions src/entity/coalOre.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import random
from entity.drawableEntity import DrawableEntity


# @author Daniel McCoy Stephenson
# @since August 18th, 2022
class CoalOre(DrawableEntity):
def __init__(self):
DrawableEntity.__init__(self, "Coal Ore", "assets/coalOre.png")
DrawableEntity.__init__(self, "Coal Ore", "assets/images/coalOre.png")
self.solid = True

def isSolid(self):
return self.solid
return self.solid
6 changes: 3 additions & 3 deletions src/entity/drawableEntity.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ class DrawableEntity(Entity):
def __init__(self, name, imagePath):
Entity.__init__(self, name)
self.imagePath = imagePath

def getImage(self):
return pygame.image.load(self.imagePath)

def getImagePath(self):
return self.imagePath

def setImagePath(self, imagePath):
self.imagePath = imagePath
self.imagePath = imagePath
4 changes: 2 additions & 2 deletions src/entity/food.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ class Food(DrawableEntity):
def __init__(self, name, color, energy):
DrawableEntity.__init__(self, name, color)
self.energy = energy

def getEnergy(self):
return self.energy
return self.energy
4 changes: 2 additions & 2 deletions src/entity/grass.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
# @since August 8th, 2022
class Grass(DrawableEntity):
def __init__(self):
DrawableEntity.__init__(self, "Grass", "assets/grass.png")
DrawableEntity.__init__(self, "Grass", "assets/images/grass.png")
self.solid = False

def isSolid(self):
return self.solid
return self.solid
7 changes: 3 additions & 4 deletions src/entity/ironOre.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import random
from entity.drawableEntity import DrawableEntity


# @author Daniel McCoy Stephenson
# @since August 18th, 2022
class IronOre(DrawableEntity):
def __init__(self):
DrawableEntity.__init__(self, "Iron Ore", "assets/ironOre.png")
DrawableEntity.__init__(self, "Iron Ore", "assets/images/ironOre.png")
self.solid = True

def isSolid(self):
return self.solid
return self.solid
6 changes: 3 additions & 3 deletions src/entity/jungleWood.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
# @since August 8th, 2022
class JungleWood(DrawableEntity):
def __init__(self):
DrawableEntity.__init__(self, "Jungle Wood", "assets/jungleWood.png")
DrawableEntity.__init__(self, "Jungle Wood", "assets/images/jungleWood.png")
self.solid = True

def isSolid(self):
return self.solid
return self.solid
6 changes: 3 additions & 3 deletions src/entity/leaves.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
# @since August 8th, 2022
class Leaves(DrawableEntity):
def __init__(self):
DrawableEntity.__init__(self, "Leaves", "assets/leaves.png")
DrawableEntity.__init__(self, "Leaves", "assets/images/leaves.png")
self.solid = False

def isSolid(self):
return self.solid
return self.solid
Empty file added src/entity/living/__init__.py
Empty file.
11 changes: 9 additions & 2 deletions src/entity/living/bear.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@
# @since December 24th, 2022
class Bear(LivingEntity):
def __init__(self, tickCreated):
LivingEntity.__init__(self, "Bear", "assets/bear.png", random.randrange(20, 30), [Chicken, Player], tickCreated)
LivingEntity.__init__(
self,
"Bear",
"assets/images/bear.png",
random.randrange(20, 30),
[Chicken, Player],
tickCreated,
)
self.solid = False

def isSolid(self):
return self.solid
return self.solid
11 changes: 9 additions & 2 deletions src/entity/living/chicken.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@
# @since July 7th, 2022
class Chicken(LivingEntity):
def __init__(self, tickCreated):
LivingEntity.__init__(self, "Chicken", "assets/chicken.png", random.randrange(20, 30), [Grass], tickCreated)
LivingEntity.__init__(
self,
"Chicken",
"assets/images/chicken.png",
random.randrange(20, 30),
[Grass],
tickCreated,
)
self.solid = False

def isSolid(self):
return self.solid
return self.solid
23 changes: 13 additions & 10 deletions src/entity/living/livingEntity.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def __init__(self, name, color, energy, edibleEntityTypes, tickCreated):
self.targetEnergy = energy
self.tickCreated = tickCreated
self.tickLastReproduced = None

def getEnergy(self):
return self.energy

Expand All @@ -28,7 +28,7 @@ def addEnergy(self, amount):
self.energy = 100
else:
self.energy += amount

def removeEnergy(self, amount):
if self.energy - amount < 0:
self.energy = 0
Expand All @@ -37,30 +37,33 @@ def removeEnergy(self, amount):

def needsEnergy(self):
return self.energy < self.targetEnergy * 0.50

def getTargetEnergy(self):
return self.targetEnergy

def setTargetEnergy(self, targetEnergy):
self.targetEnergy = targetEnergy

def canEat(self, entity):
for entityType in self.edibleEntityTypes:
if type(entity) is entityType:
return True
return False

def kill(self):
self.energy = 0

def getTickCreated(self):
return self.tickCreated

def setTickCreated(self, tick):
self.tickCreated = tick

def getAge(self, tick):
return tick - self.tickCreated

def getTickLastReproduced(self):
return self.tickLastReproduced

def setTickLastReproduced(self, tick):
self.tickLastReproduced = tick
self.tickLastReproduced = tick
6 changes: 3 additions & 3 deletions src/entity/oakWood.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
# @since August 8th, 2022
class OakWood(DrawableEntity):
def __init__(self):
DrawableEntity.__init__(self, "Oak Wood", "assets/oakWood.png")
DrawableEntity.__init__(self, "Oak Wood", "assets/images/oakWood.png")
self.solid = True

def isSolid(self):
return self.solid
return self.solid
7 changes: 3 additions & 4 deletions src/entity/stone.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import random
from entity.drawableEntity import DrawableEntity


# @author Daniel McCoy Stephenson
# @since August 18th, 2022
class Stone(DrawableEntity):
def __init__(self):
DrawableEntity.__init__(self, "Stone", "assets/stone.png")
DrawableEntity.__init__(self, "Stone", "assets/images/stone.png")
self.solid = True

def isSolid(self):
return self.solid
return self.solid
Loading