Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
seanchen1991 committed Jan 2, 2019
0 parents commit 09ed5e6
Show file tree
Hide file tree
Showing 9 changed files with 177 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.vscode
*.pyc
__pycache__
11 changes: 11 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]

[dev-packages]

[requires]
python_version = "3"
Empty file added README.md
Empty file.
51 changes: 51 additions & 0 deletions src/adv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from room import Room

# Declare all the rooms

room = {
'outside': Room("Outside Cave Entrance",
"North of you, the cave mount beckons"),

'foyer': Room("Foyer", """Dim light filters in from the south. Dusty
passages run north and east."""),

'overlook': Room("Grand Overlook", """A steep cliff appears before you, falling
into the darkness. Ahead to the north, a light flickers in
the distance, but there is no way across the chasm."""),

'narrow': Room("Narrow Passage", """The narrow passage bends here from west
to north. The smell of gold permeates the air."""),

'treasure': Room("Treasure Chamber", """You've found the long-lost treasure
chamber! Sadly, it has already been completely emptied by
earlier adventurers. The only exit is to the south."""),
}


# Link rooms together

room['outside'].n_to = room['foyer']
room['foyer'].s_to = room['outside']
room['foyer'].n_to = room['overlook']
room['foyer'].e_to = room['narrow']
room['overlook'].s_to = room['foyer']
room['narrow'].w_to = room['foyer']
room['narrow'].n_to = room['treasure']
room['treasure'].s_to = room['narrow']

#
# Main
#

# Make a new player object that is currently in the 'outside' room.

# Write a loop that:
#
# * Prints the current room name
# * Prints the current description (the textwrap module might be useful here).
# * Waits for user input and decides what to do.
#
# If the user enters a cardinal direction, attempt to move to the room there.
# Print an error message if the movement isn't allowed.
#
# If the user enters "q", quit the game.
28 changes: 28 additions & 0 deletions src/examples/guessing_game.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import random

def guessing_game():
print("Guess the number!")

secret_number = random.randrange(101)

while True:
guess = input("Input your guess: ")

try:
guess = int(guess)
except ValueError:
print("Please enter an integer.")
continue

print(f"You guessed: {guess}")

if guess == secret_number:
print("You win!")
break
elif guess < secret_number:
print("Too small!")
else:
print("Too big!")

if __name__ == '__main__':
guessing_game()
1 change: 1 addition & 0 deletions src/examples/history.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3,3,0
79 changes: 79 additions & 0 deletions src/examples/rock_paper_scissors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#import module we need
import random

#file i/o functions for historical results
def load_results():
text_file = open("history.txt", "r")
history = text_file.read().split(",")
text_file.close()
return history

def save_results( w, t, l):
text_file = open("history.txt", "w")
text_file.write( str(w) + "," + str(t) + "," + str(l))
text_file.close()

#welcome message
results = load_results()
wins = int(results[0])
ties = int( results[1])
losses = int(results[2])
print("Welcome to Rock, Paper, Scissors!")
print("Wins: %s, Ties: %s, Losses: %s" % (wins, ties, losses))
print("Please choose to continue...")


#initialize user, computer choices
computer = random.randint(1,3)
user = int(input("[1] Rock [2] Paper [3] Scissors [9] Quit\n"))

#gamplay loop
while not user == 9:
#user chooses ROCK
if user == 1:
if computer == 1:
print("Computer chose rock...tie!")
ties += 1
elif computer == 2:
print("Computer chose paper...computer wins :(")
losses += 1
else:
print("Computer chose scissors...you wins :)")
wins += 1

#user chooses PAPER
elif user == 2:
if computer == 1:
print("Computer chose rock...you win :)")
wins += 1
elif computer == 2:
print("Computer chose paper...tie!")
ties += 1
else:
print("Computer chose scissors...computer wins :(")
losses += 1

#user chooses SCISSORS
elif user == 3:
if computer == 1:
print("Computer chose rock...computer wins :(")
losses += 1
elif computer == 2:
print("Computer chose paper...you win :)")
wins += 1
else:
print("Computer chose scissors...tie!")
ties += 1
else:
print("Invalid selection. Please try again.")
#print updated stats
print("Wins: %s, Ties: %s, Losses: %s" % (wins, ties, losses))

#prompt user to make another selection
print("Please choose to continue...")
#initialize user, computer choices
computer = random.randint(1,3)
user = int(input("[1] Rock [2] Paper [3] Scissors [9] Quit\n"))

# #game over, save results
save_results(wins, ties, losses)
2 changes: 2 additions & 0 deletions src/player.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Write a class to hold player information, e.g. what room they are in
# currently.
2 changes: 2 additions & 0 deletions src/room.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Implement a class to hold room information. This should have name and
# description attributes.

0 comments on commit 09ed5e6

Please sign in to comment.