This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
from sys import exit | |
from random import randint | |
import string | |
import rooms | |
# Map | |
# ▓ ▓ ▓ ▓ ▓ | |
# ▓ ▓ ▓ ▓ ▓ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Base room object, for other rooms to inherit from. | |
class Room(object): | |
def __init__(self): | |
self.brief = "" | |
self.description = "" | |
self.exits = {} | |
self.room_number = -1 | |
def look(self): | |
print self.description |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
################################################################################ | |
def main(): | |
table = Table(['Matthew', 'Mark', 'Luke', 'John']) | |
table.deal_cards() | |
table.play_all() | |
def print_underline(string, line): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Read It | |
# Demonstrates reading from a text file | |
print("Opening and closing the file.") | |
text_file = open("read_it.txt", "r") | |
text_file.close() | |
print("\nReading characters and closing the file.") | |
text_file = open("read_it.txt", "r") | |
print(text_file.read(1)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Weapon(object): | |
def __init__(self, name): | |
self.name = name | |
self.parent = None | |
def destroy(self): | |
if self.parent: | |
self.parent.weaponDestroyed() | |
def WeaponRef(): | |
def getWeapon(self): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BlogEntry | |
def initialize( title, mood, fulltext ) | |
@time = Time.now | |
@title, @mood, @fulltext = title, mood, fulltext | |
end | |
end | |
entry_one = BlogEntry.new("Yay Ruby!", :happy, "Ruby is the bomb.") | |
entry_two = BlogEntry.new("Yay Rails!", :confused, "Rails is the bomb.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# creates an empty array for the user's inventory | |
@inventory = [] | |
# this is the command prompt method | |
def prompt() | |
print "Enter command > " | |
end | |
# shows a list of viable commands when a user enters "help" at the command prompt | |
def help() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Week One Exercise One | |
# Before executing the code given below, guess the results. Next, execute the code. | |
# Did you get it right? If you did not get it right, can you think of why? | |
# Discuss your first guess and what you got when running the code. Goal: Understanding | |
# operator precedence and association. | |
y = false | |
z = true | |
x = y or z | |
puts x # false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Week One Exercise 2 | |
# Read the sprintf documentation and the % documentation in the | |
# String class and figure out the output being printed by of this Ruby code. | |
puts "%05d" % 123 | |
# The output is 00123 | |
# Similar to Python, % can be used as a formatter. | |
# I looked up the usage of 'd' as an argument formatter in the |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Write a program in Ruby that tells you how old I am | |
# if I am 979000000 seconds old. Display the result as a floating point (decimal) number to two | |
# decimal places (for example, 17.23). Note: To format the output to say 2 decimal | |
# places, we can use the Kernel's format method. For example, if x = 45.5678 then format("%.2f", x) | |
# will return the string 45.57 | |
def seconds_to_years(seconds) | |
seconds_in_year = 31536000 | |
age = seconds.to_f / seconds_in_year.to_f | |
printf "You are %.2f years old.", age |