Friday, November 21, 2014

Cloak: Part I

Cloak is now up on github. It is still very much a work in progress. And it does very little.  You can move the character’s icon (an ‘@’ char) around the screen with the arrow keys, and 'q' just quits.  I'm working on how to structure the data as well as how to make the screen updates faster, and I'm not sure if a vector of vectors is correct or perhaps I should just make it a vector of fixed-length strings and then update the individual chars which describe some portion of the dungeon.

I'm going to want to actually consider these places in the board as tiles and then give each some attributes such as color and type maybe.  Fun! Fun!


Tuesday, November 11, 2014

Cloak: The Clojure Rogue-like Game

Recently I had this urge to play some of my old favorite games like NetHack and other rogue-like games.  I’m also learning the Clojure programming language and so I thought why not write try to write my own rogue-like game and so I am calling it Cloak.

I did a search for for Clojure libraries that might help me create an ANSI text-based interface which is when I found clojure-lanterna, by Steve Losh, which is a Clojure wrapper around the lanterna java library. I then discovered that Steve also had the same idea some time ago when he wrote The Caves of Clojure and a series of blog posts that chronicle his experience in writing the game.  Now I wonder if doing the same thing wouldn’t just be redundant.  But anyhow…

I am, for better or worse, going to create my own rogue-like game in Clojure and write about it here.  And although it is extremely tempting to peek at Steve’s Caves of Clojure while writing Cloak, I think I’ll try to refrain.  Note that I did already study his code, an a number of other rogue-like games in Clojure, because I am still learning Clojure and had (and still have) many questions.  Anyway, I will try to be as original as I can.

By the way, it’s not uncommon for me to say I am going to do something and then get interested in something completely different and not came back to it for some time.  Essentially don’t hold your breath waiting for the next post.

Saturday, October 4, 2014

Scala Snob

Although I hate to admit it, especially because I like to learn new programming languages, I think I've become a Scala snob.  For example, I wanted to learn Groovy so I could mess around with Grails and I simply cannot help but compare Groovy to Scala.  I keep thinking, why didn't they do it like Scala did, or its only one line in Scala, etc.

Sunday, November 11, 2012

Creating A Calculator for My Mac

I've been attempting to learn how to program in objective-c and cocoa so I can write some useful apps. One of the simplest things you can do to get familiar with a new GUI environment and framework is to write a simple calculator application.  I've yet to write code, but here is what it will look like when completed.

Nothing really too exciting here, but Xcode (Apple's IDE for mac, iPhone and iPad apps) makes it pretty simple to drag-and-drop visual components to make what I did here.
Enhanced by Zemanta

Monday, September 10, 2012

A Simple Stopwatch Class in Scala

I'm learning to program in Scala and one easy way I found to learn it is to start by creating unit tests for my java code in Scala using ScalaTest.  Part of what I like to do in testing portions of code is to get some simple performance statistics and traditionally I usually create or find a Stopwatch class library so that I can surround the code under test with it, which lets me see how long in milliseconds something takes to execute.  And so for the fun of it I wrote my own, very small, toy Stopwatch class in Scala.

class Stopwatch {
  var startTime = System.currentTimeMillis
  var elapsedTime: Long = 0

  def start = { startTime = System.currentTimeMillis; elapsedTime = 0 }
  def stop = { elapsedTime = System.currentTimeMillis - startTime }
  
  override def toString = "elapsed time: " + elapsedTime + " milliseconds"
}

object Stopwatch {

  def apply(): Stopwatch = new Stopwatch

  def time(tag: String)(f: => Unit): Stopwatch = {
    val sw = Stopwatch()
    f
    sw.stop
    sw
  }
}

One nice thing about Scala is the ability to create your own control structures so I did that in the Stopwatch singleton object that I created which lets me do something like the following

class StopwatchUnitTest extends FunSuite {
  import Stopwatch._
  test("smoke") {
    val sw = time("timing 'Thread.sleep(1000)'") {
      Thread.sleep(1000)
    }
    println(sw)
  }
}

Well that's that.  More next time.

Wednesday, June 29, 2011

Using CDI in Java SE 6

What I really like about Weld which is the CDI (Context and Dependency Injection) reference implementation used in servers such as Glassfish and JBoss, is that they provide an extension where you can use most of the CDI features within a simple java application.

One of the main benefits for me is that i can test ideas I have for my web and Java EE work in a quick java app without having to wait for long builds and server deployment.  Of course it's also just a great way to write software, and any old java app could benefit from it, and it saves you writing a lot of needless code.

Here is a simple java program that prints out "Hello, Weld!"

@ApplicationScoped
public class WeldSeTest {

 public void sayHello(@Observes ContainerInitialized event) {
  System.out.println("Hello, Weld!");
 }
 
}

Thursday, June 23, 2011

Syntax Highlighting Test

@Inject
 @Any
 Event<IncSessionCount> incSessionCount;

 @Inject
 @Any
 Event<DecSessionCount> decSessionCount;

 @Inject
 private ReviewDocumentTracker tracker;

 /**
  * Default constructor.
  */
 public SessionManagerBean() {
 }