Skip to content

Instantly share code, notes, and snippets.

View KGZM's full-sized avatar

KGZM

  • We Have The Web LLC
  • Brooklyn
View GitHub Profile
@KGZM
KGZM / message.py
Last active December 11, 2015 20:19
Sequel to textgame.py: Intrigued by python I decided to take the text game idea a little further. Added server things and multiuser mode. Just experimenting. (I have no idea how to rename a multifile gist or reorder it, so the files are in alphabetical order not in a semantic order.)
class Message(object):
def __init__(self, string):
self.breakdown = []
self.tokens = {}
for part in string.split('{'):
self.breakdown.extend(part.split('}'))
for i, part in enumerate(self.breakdown):
if i % 2 == 1:
@KGZM
KGZM / textgame.py
Created January 24, 2013 22:25
A friend of mine is learning to program with Python and started making a simple text game. He hit on the novel, if impractical solution, of using a function for each room... but was writing them all explicitly. I decided to show him about first class functions and closures with this example here. It's very rough and based on his architecture for…
commands = ["look", "smell"]
def make_room(description, exits):
def room(skip = False, command = ""):
if not skip or command == "look":
print description
print "You can go: " + ",".join(exits.keys())
if command in exits.keys():
return rooms[exits[command]]
if command and command not in commands:
print "I don't understand that."
@KGZM
KGZM / sicp.js
Created January 23, 2013 06:45
Examples From Structure and Interpretation of Computer Programs.. I decided to go through and make some of my previously private gists into public ones.
inc = function(x) {
return x + 1;
};
square = function(x) {
return x * x;
};
cube = function(x) {
return x * x * x;