Skip to content

Instantly share code, notes, and snippets.

View tmountain's full-sized avatar

Travis Whitton tmountain

View GitHub Profile
public class DivZero {
public static void main(String[] args) {
try {
int result = 5 / 0;
} catch (ArithmeticException e) {
System.out.println("Caught a DIV/0!");
throw e;
}
System.out.println("Alive?!");
public class DivZero {
public static void main(String[] args) {
try {
int result = 5 / 0;
} catch (ArithmeticException e) {
System.out.println("Caught a DIV/0!");
throw e;
}
System.out.println("Alive?!");
// Vehicle.java
public interface Vehicle {
public int wheels();
}
// Test.java
public class Test {
public static void main(String[] args) {
Vehicle car = new Vehicle() {
public int wheels() {
#!/usr/bin/perl -w
use strict;
my $message = shift;
qx/gmessage -display :0.0 -center -geometry 800x400 -borderless -bg "#000000" -fg "#00ff00" -font 40 "$message"/;
(ns combat)
(defn roll
"roll the dice (roll 1 6) => 1d6, (roll 2 6) => 2d6"
[dice max]
(apply + (for [x (range dice)] (inc (rand-int max)))))
(defn weapon-dmg
"calculates a damage roll for the given weapon"
[weapon]
(ns monsters
(:use weapons)
(:use abilities))
(def grid-bug
{:level 0,
:exp 4,
:ac 9,
:mr 0,
:weapon (bite 1 1),
(ns experience
(:use combat))
; experience table handling progression between levels
(def xp-table
{1 0,
2 20,
3 40,
4 80,
5 160,
(ns weapons)
(def dagger
; 1d3 dagger
{:dmg [1 3],
:name "dagger"})
(def short-sword
; 1d6 short sword
{:dmg [1 6]
(ns util)
(defn pickup
"generic helper to pickup an item"
[entity item slot]
(dosync (alter entity assoc slot item)))
(defn take-weapon
"set an entity to wield a weapon"
[entity weapon]
(ns id-gen)
(def ids "abcdefghijklmnopqrstuvwxyz")
(defn create-generator []
"returns a generator ref"
(ref {:ids ids, :pos 0}))
(defn- inc-gen
"increments generator counter