Projects
Python Text-Base Game
This project utilized various software development principles to output a text-based adventure game to the player. The player needs to collect an assortment of items before exiting the scenario.
I utilized many different aspects of the programming language Python, coding and using dictionaries, functions, lists, variables, loops, and if-else statements. while programming I also practiced good commenting and applied the best coding practices for readability.
First you can play around with the program itself to get an understanding of what it does!
In this snippet I utilized a function that would be the start of our main program.
# Function to call in main to start the game and display a menu.
def show_instructions():
print('The Heist at the Museum')
print('Collect 6 items to beat the security, or else spend time in a cell!')
print('Move commands: go South, go North, go East, go West')
print("To add to Inventory: get 'item name'")
print('-' * 20)
In this next snippet I utilized a function to get the status of a player. This included the players locaton, item in that room, and items in their inventory.
# Function to show the player's current room, what item is in that room, and what items they have already collected.
def show_status(currentRoom, inventory):
# This dictionary holds our items and where they're located.
items = {'Entry': 'No Item', 'Main Foyer': 'Key', 'Locked Storage': 'Manuscript',
'Ancient Explorers Exhibit': 'Golden Telescope', 'Ancient Civ Exhibit': 'Stone Statue',
'Art Exhibit': 'Pollock Painting', 'Gem Room': 'Emerald', 'Warrior Exhibit': 'Katana',
'Security Room': 'No Item'}
roomItem = items[currentRoom]
print('You are in the {}.'.format(currentRoom))
print('Current Inventory: {}'.format(inventory))
print('Item in current room: {}'.format(roomItem))
This next snippet shows the use of lists and the intialization of some variables outside our main loop.
# A list to test if entries are valid or not.
valid_list_options = ('go South', 'go North', 'go East', 'go West', 'exit')
# Initialize our variables.
currentRoom = 'Entry'
inventory = []
In this snippet we can see the beginning of our game as well as the main loop to keep the user playing the game. The first if statement can also be seen, the other elif statements that follow are of similar structure based on the current room.
# Print our opening welcome and directions.
show_instructions()
# Outer loop that starts the game.
while True:
if currentRoom == 'exit':
print('Thank you for playing my game!')
break
else:
# This inner while loop keeps the user playing as long as they do not enter exit.
while True:
if currentRoom == list(rooms.keys())[0]:
show_status(currentRoom, inventory)
print('Possible moves: {}'.format(rooms[currentRoom]))
command = input('Enter your move: ')
# This inner while loop is needed in each room so that if invalid commands are entered the user will
# be prompted again without having to reprint the current room.
while True:
# If clauses are in each room to decide where to go next or if it needs another input.
if command == 'go North':
currentRoom = 'Main Foyer'
break
elif command == 'exit':
currentRoom = 'exit'
break
else:
if command in valid_list_options:
command = input('Valid answer but not for this room, please enter a valid command: ')
continue
else:
command = input('Invalid answer, please enter a valid command: ')
continue
Java Pet Grooming Service Portal
Here I used various OOP principles to output an intake portal to customers. The program then stored important information and made decisions based on that information.
While doing this project I utilized various aspects of the Java programming language as well as proper software development techniques. Using multiple Java files or classes, array lists to store information, scanners to take input from the user, variables with varying levels of access, methods to perform operations, constructors, loops, and if-else statements. as well as utilzing concepts such as inheritance.
First some stuff from the beginning of our driver file or our main file that performs most of the main functionality. Within this driver file we can see the declaration of the array lists being used, our main function, the intialization and use of the scanner, as well as a loop to take inputs on the main menu. A catch is also implemented for good measure to catch on bad inputs.
public class Driver {
//Declare our array lists.
private static ArrayList dogList = new ArrayList();
private static ArrayList monkeyList = new ArrayList();
public static void main(String[] args) {
//Initialize scanner so we can take inputs from user.
Scanner scnr = new Scanner(System.in);
initializeDogList();
initializeMonkeyList();
//Declare variable to be used for userInput and run loop for menu.
int userInput;
String userInput1;
do {
displayMenu();
//Using a try statement so we can catch any inputs that are invalid.
try {
if (scnr.hasNextInt()) {
userInput = scnr.nextInt();
if (userInput == 1) {
scnr.nextLine();
intakeNewDog(scnr);
}
else if (userInput == 2) {
scnr.nextLine();
intakeNewMonkey(scnr);
}
else if (userInput == 3) {
scnr.nextLine();
reserveAnimal(scnr);
}
else if (userInput == 4) {
printAnimals(userInput);
}
else if (userInput == 5) {
printAnimals(userInput);
}
else if (userInput == 6) {
printAnimals(userInput);
}
else {
throw new Exception("Invalid option. Try again.");
}
}
else if (scnr.hasNext()) {
userInput1 = scnr.nextLine();
if (userInput1.equals("q")) {
break;
}
else {
throw new Exception("Invalid option. Try again.");
}
}
}
//Here our catch inputs output error messages for wrong inputs.
catch (InputMismatchException e) {
System.out.println("Invalid input. Try again.");
}
catch (Exception e) {
System.out.println(e.getMessage());
}
} while (true);
}
This next snippet is an example of a method used to display the menu.
// This method prints the menu options
public static void displayMenu() {
System.out.println("\n\n");
System.out.println("\t\t\t\tRescue Animal System Menu");
System.out.println("[1] Intake a new dog");
System.out.println("[2] Intake a new monkey");
System.out.println("[3] Reserve an animal");
System.out.println("[4] Print a list of all dogs");
System.out.println("[5] Print a list of all monkeys");
System.out.println("[6] Print a list of all animals that are not reserved");
System.out.println("[q] Quit application");
System.out.println();
System.out.println("Enter a menu selection");
}
Here we can see the program checks to see if the animal is already in the system and if not will go on to add all the necessary information. The outputs that follow the last are similar and each one gets a valuable piece of information.
//Intake new dog method, checks if name is already in system, need to add instantiation of the new dog.
public static void intakeNewDog(Scanner scnr) {
System.out.println("What is the dog's name?");
String name = scnr.nextLine();
//Checks if dog is already in the system.
for(Dog dog: dogList) {
if(dog.getName().equalsIgnoreCase(name)) {
System.out.println("\n\nThis dog is already in our system\n\n");
return; //returns to menu
}
}
//Add instantiation for new dog.
Dog dog4 = new Dog();
//Set name and get inputs from user to add to the system.
dog4.setName(name);
As we move on to another class called Rescue Animal, this class will be the foundation for each specific animal class. In other words, the dog and monkey class will inherit this one.
public class RescueAnimal {
// Instance variables
private String name;
private String animalType;
private String gender;
private String age;
private String weight;
private String acquisitionDate;
private String acquisitionCountry;
private String trainingStatus;
private boolean reserved;
private String inServiceCountry;
// Constructor
public RescueAnimal() {
}
public String getName() {
return name;
}
In this next snippet from the Dog class, we can see that it extends Rescue Animals and also has accessors and mutators to get and change the values. Our last class, the monkey class, looks very similar.
public class Dog extends RescueAnimal {
// Instance variable
private String breed;
public Dog() {
}
// Constructor
public Dog(String name, String breed, String gender, String age,
String weight, String acquisitionDate, String acquisitionCountry,
String trainingStatus, boolean reserved, String inServiceCountry) {
setName(name);
setBreed(breed);
setGender(gender);
setAge(age);
setWeight(weight);
setAcquisitionDate(acquisitionDate);
setAcquisitionLocation(acquisitionCountry);
setTrainingStatus(trainingStatus);
setReserved(reserved);
setInServiceCountry(inServiceCountry);
}
// Accessor Method
public String getBreed() {
return breed;
}
// Mutator Method
public void setBreed(String dogBreed) {
breed = dogBreed;
}