Skip to content

Commit 09ed5e6

Browse files
committed
Initial commit
0 parents  commit 09ed5e6

9 files changed

Lines changed: 177 additions & 0 deletions

File tree

‎.gitignore‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.vscode
2+
*.pyc
3+
__pycache__

‎Pipfile‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[[source]]
2+
url = "https://pypi.org/simple"
3+
verify_ssl = true
4+
name = "pypi"
5+
6+
[packages]
7+
8+
[dev-packages]
9+
10+
[requires]
11+
python_version = "3"

‎README.md‎

Whitespace-only changes.

‎src/adv.py‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from room import Room
2+
3+
# Declare all the rooms
4+
5+
room = {
6+
'outside': Room("Outside Cave Entrance",
7+
"North of you, the cave mount beckons"),
8+
9+
'foyer': Room("Foyer", """Dim light filters in from the south. Dusty
10+
passages run north and east."""),
11+
12+
'overlook': Room("Grand Overlook", """A steep cliff appears before you, falling
13+
into the darkness. Ahead to the north, a light flickers in
14+
the distance, but there is no way across the chasm."""),
15+
16+
'narrow': Room("Narrow Passage", """The narrow passage bends here from west
17+
to north. The smell of gold permeates the air."""),
18+
19+
'treasure': Room("Treasure Chamber", """You've found the long-lost treasure
20+
chamber! Sadly, it has already been completely emptied by
21+
earlier adventurers. The only exit is to the south."""),
22+
}
23+
24+
25+
# Link rooms together
26+
27+
room['outside'].n_to = room['foyer']
28+
room['foyer'].s_to = room['outside']
29+
room['foyer'].n_to = room['overlook']
30+
room['foyer'].e_to = room['narrow']
31+
room['overlook'].s_to = room['foyer']
32+
room['narrow'].w_to = room['foyer']
33+
room['narrow'].n_to = room['treasure']
34+
room['treasure'].s_to = room['narrow']
35+
36+
#
37+
# Main
38+
#
39+
40+
# Make a new player object that is currently in the 'outside' room.
41+
42+
# Write a loop that:
43+
#
44+
# * Prints the current room name
45+
# * Prints the current description (the textwrap module might be useful here).
46+
# * Waits for user input and decides what to do.
47+
#
48+
# If the user enters a cardinal direction, attempt to move to the room there.
49+
# Print an error message if the movement isn't allowed.
50+
#
51+
# If the user enters "q", quit the game.

‎src/examples/guessing_game.py‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import random
2+
3+
def guessing_game():
4+
print("Guess the number!")
5+
6+
secret_number = random.randrange(101)
7+
8+
while True:
9+
guess = input("Input your guess: ")
10+
11+
try:
12+
guess = int(guess)
13+
except ValueError:
14+
print("Please enter an integer.")
15+
continue
16+
17+
print(f"You guessed: {guess}")
18+
19+
if guess == secret_number:
20+
print("You win!")
21+
break
22+
elif guess < secret_number:
23+
print("Too small!")
24+
else:
25+
print("Too big!")
26+
27+
if __name__ == '__main__':
28+
guessing_game()

‎src/examples/history.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3,3,0
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#import module we need
2+
import random
3+
4+
#file i/o functions for historical results
5+
def load_results():
6+
text_file = open("history.txt", "r")
7+
history = text_file.read().split(",")
8+
text_file.close()
9+
return history
10+
11+
def save_results( w, t, l):
12+
text_file = open("history.txt", "w")
13+
text_file.write( str(w) + "," + str(t) + "," + str(l))
14+
text_file.close()
15+
16+
#welcome message
17+
results = load_results()
18+
wins = int(results[0])
19+
ties = int( results[1])
20+
losses = int(results[2])
21+
print("Welcome to Rock, Paper, Scissors!")
22+
print("Wins: %s, Ties: %s, Losses: %s" % (wins, ties, losses))
23+
print("Please choose to continue...")
24+
25+
26+
#initialize user, computer choices
27+
computer = random.randint(1,3)
28+
user = int(input("[1] Rock [2] Paper [3] Scissors [9] Quit\n"))
29+
30+
#gamplay loop
31+
while not user == 9:
32+
#user chooses ROCK
33+
if user == 1:
34+
if computer == 1:
35+
print("Computer chose rock...tie!")
36+
ties += 1
37+
elif computer == 2:
38+
print("Computer chose paper...computer wins :(")
39+
losses += 1
40+
else:
41+
print("Computer chose scissors...you wins :)")
42+
wins += 1
43+
44+
#user chooses PAPER
45+
elif user == 2:
46+
if computer == 1:
47+
print("Computer chose rock...you win :)")
48+
wins += 1
49+
elif computer == 2:
50+
print("Computer chose paper...tie!")
51+
ties += 1
52+
else:
53+
print("Computer chose scissors...computer wins :(")
54+
losses += 1
55+
56+
#user chooses SCISSORS
57+
elif user == 3:
58+
if computer == 1:
59+
print("Computer chose rock...computer wins :(")
60+
losses += 1
61+
elif computer == 2:
62+
print("Computer chose paper...you win :)")
63+
wins += 1
64+
else:
65+
print("Computer chose scissors...tie!")
66+
ties += 1
67+
else:
68+
print("Invalid selection. Please try again.")
69+
#print updated stats
70+
print("Wins: %s, Ties: %s, Losses: %s" % (wins, ties, losses))
71+
72+
#prompt user to make another selection
73+
print("Please choose to continue...")
74+
#initialize user, computer choices
75+
computer = random.randint(1,3)
76+
user = int(input("[1] Rock [2] Paper [3] Scissors [9] Quit\n"))
77+
78+
# #game over, save results
79+
save_results(wins, ties, losses)

‎src/player.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Write a class to hold player information, e.g. what room they are in
2+
# currently.

‎src/room.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Implement a class to hold room information. This should have name and
2+
# description attributes.

0 commit comments

Comments
 (0)