<!-- A Dark Room (v1.2) ================== A minimalist text adventure by Michael Townsend. Inspired by Candy Box (http://candies.aniwey.net/) Please don't steal me. -->
Person *person = [[Person alloc] init]; person.firstName = @"Amir"; person.lastName = @"Rajan"; NSLog([person sayHello]);
person = Person.alloc.init person.firstName = "Amir" person.lastName = "Rajan" NSLog(person.sayHello)
//Person.h @interface Person : NSObject @property NSString *firstName; @property NSString *lastName; - (NSString*)sayHello; @end //Person.m #import "Person.h" @implementation Person - (NSString*)sayHello { return [NSString stringWithFormat:@"Hello, %@ %@.", _firstName, _lastName]; } @end
class Person attr_accessor :firstName, :lastName def sayHello "Hello, #{@firstName} #{@lastName}" end end
- (void)setDobWithMonth:(NSInteger)month withDay:(NSInteger)day withYear:(NSInteger)year { } [person setDobWithMonth:1 withDay:1 withYear:2013];
def setDobWithMonth(month, withDay: day, withYear: year) end person.setDobWithMonth(1, withDay: 1, withYear: 2013)
- (void) post:(NSDictionary *)objectToPost toUrl:(NSString *)toUrl success:(void (^)(RKMappingResult *mappingResult))success { } [client post: @{ @"firstName": @"Amir", @"lastName": @"Rajan" } toUrl: @"http://localhost/people" success:^(RKMappingResult *result) { //callback code here }];
def post(objectToPost, toUrl: toUrl, success: success) end client post({ firstName: "Amir", lastName: "Rajan" }, toUrl: "http://localhost/people", success: lambda { |result| #callback code here })
_label.layer.backgroundColor = [UIColor whiteColor].CGColor; [UIView animateWithDuration:2.0 animations:^{ _label.layer.backgroundColor = [UIColor greenColor].CGColor; } completion:NULL];
@label.layer.backgroundColor = UIColor.whiteColor.CGColor UIView.animateWithDuration(2.0, animations: lambda { @label.layer.backgroundColor = UIColor.greenColor.CGColor }, completion: nil)
class UIView def animate duration = 0.5, &block UIView.beginAnimations(nil, context:nil) UIView.setAnimationDuration(duration) instance_eval &block UIView.commitAnimations end end label.setAlpha 0 label.animate 1 { label.setAlpha 1 }
@interface UIView (UIViewExtensions) - (void)animate:(double)duration block:(void (^)(void))block; - (void)animate:(void (^)(void))block; @end @implementation UIView (UIViewExtensions) - (void)animate:(void (^)(void))block { [self animate:0.5 block:block]; } - (void)animate:(double)duration block:(void (^)(void))block { [UIView beginAnimations:NULL context:NULL]; [UIView setAnimationDuration:duration]; block(); [UIView commitAnimations]; } @end [label setAlpha:0]; [label animate:1 block:^{ [label setAlpha:1]; }];
class SnarlingBeastEvent < EncounterEvent title "a snarling beast" text "a snarling beast leaps out of the underbrush." damage 1 def loot { fur: { min: 3, max: 7, chance: 1.0 } } end end
class EncounterEvent def self.title title define_method("title") { title } end def self.text text define_method("text") { text } end def self.health health define_method("health") { health } end end
@interface SnarlingBeastEvent : EncounterEvent + (id)initNew; - (NSDictionary *)loot; @end @implementation SnarlingBeastEvent + (id)initNew { return [super initWithAttributes: @{ @"health": [[NSNumber alloc]initWithInt: 1], @"title": @"a snarling beast", @"text": @"a snarling beast leaps out of the underbrush." }]; } - (NSDictionary *)loot { return @{ @"fur": @{ @"min": [[NSNumber alloc]initWithDouble:3.0], @"max": [[NSNumber alloc]initWithDouble:7.0], @"chance": [[NSNumber alloc]initWithDouble:1.7] } }; } @end
@interface EncounterEvent : NSObject @property NSString *title; @property NSString *text; @property NSInteger health; + (id)initWithAttributes:(NSDictionary *)attributes; @end @implementation EncounterEvent + (id)initWithAttributes:(NSDictionary *)attributes { EncounterEvent *e = [[EncounterEvent alloc] init]; e.title = [attributes valueForKey:@"title"]; e.text = [attributes valueForKey:@"text"]; NSNumber *num = [attributes valueForKey:@"health"]; e.health = [num integerValue]; return e; } @end
describe "population" do before do end it "kills population (except for one dude)" do end end
SPEC_BEGIN(PopulationSpec) describe(@"population", ^{ before(^{ }); it(@"kills population (except for one dude)", ^{ }); } SPEC_END
class AppDelegate def application(application, didFinishLaunchingWithOptions:launchOptions) @window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds) @window.makeKeyAndVisible room_controller = RoomViewController.alloc.init navigation_controller = UINavigationController.alloc.initWithRootViewController(room_controller) @window.rootViewController = navigation_controller true end end class RoomViewController < UIViewController def viewDidLoad setTitle "a dark room" view.backgroundColor = UIColor.whiteColor @button = UIButton.buttonWithType(UIButtonTypeRoundedRect) @button.setTitle "light fire", forState: UIControlStateNormal @button.frame = CGRectMake(0, 100, 320, 40) @button.addTarget(self, action: :button_clicked, forControlEvents: UIControlEventTouchUpInside) view.addSubview @button end def button_clicked end end
class AppDelegate < PM::Delegate def on_load(app, options) open RoomScreen.new(nav_bar: true) end end class RoomScreen < PM::Screen title "a dark room" def on_load @button = UIButton.buttonWithType(UIButtonTypeRoundedRect) view.backgroundColor = UIColor.whiteColor @button.setTitle "light fire", forState: UIControlStateNormal @button.frame = CGRectMake(0, 100, 320, 40) add @button @button.when(UIControlEventTouchUpInside) { } end end
Use a spacebar or arrow keys to navigate