Skip to content

Instantly share code, notes, and snippets.

View damianesteban's full-sized avatar
🎯
Focusing

Damian Esteban damianesteban

🎯
Focusing
View GitHub Profile
# coding: utf-8
from sys import exit
from random import randint
import string
import rooms
# Map
# ▓ ▓ ▓ ▓ ▓
# ▓ ▓ ▓ ▓ ▓
# 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
@damianesteban
damianesteban / war_game.py
Created October 9, 2013 04:14
python war card game oop
import random
################################################################################
def main():
table = Table(['Matthew', 'Mark', 'Luke', 'John'])
table.deal_cards()
table.play_all()
def print_underline(string, line):
@damianesteban
damianesteban / read_it.py
Created October 25, 2013 22:08
Example of reading/writing files in Python.
# 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))
@damianesteban
damianesteban / oop_weapons.py
Created October 25, 2013 22:12
OOP "Weapon Class" for text-based game.
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):
@damianesteban
damianesteban / try_ruby.rb
Created November 12, 2013 03:17
Adaptation of 'Try Ruby'
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.")
@damianesteban
damianesteban / gist:7504249
Created November 16, 2013 19:29
Tomb of Unfathomable Horror (Ruby Text-Based Game)
# 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()
# 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
# 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
# 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