Difference between revisions of "Java Roguelike Tutorial Lesson Two Code"

From RogueBasin
Jump to navigation Jump to search
(Created page with "<center><table border="0" cellpadding="10" cellspacing="0" style="background:#F0E68C"><tr><td><center> This is part of the '''code''' for a series of tutorials; the main page can...")
 
 
(One intermediate revision by one other user not shown)
Line 13: Line 13:
import java.util.Properties;
import java.util.Properties;


public class Game{
public class HelloDungeon{


public static void main(String[] args){
public static void main(String[] args){
Line 57: Line 57:
  }
  }
</syntaxhighlight></div>
</syntaxhighlight></div>
[[Category:Developing]]

Latest revision as of 00:50, 11 October 2012

This is part of the code for a series of tutorials; the main page can be found here.


HelloDungeon.java

import net.slashie.libjcsi.CSIColor;
import net.slashie.libjcsi.CharKey;
import net.slashie.libjcsi.ConsoleSystemInterface;
import net.slashie.libjcsi.wswing.WSwingConsoleInterface;
import java.util.Properties;

public class HelloDungeon{

	public static void main(String[] args){
	
		Properties text = new Properties();
		text.setProperty("fontSize","12");
		text.setProperty("font", "Courier");
		ConsoleSystemInterface csi = null;
		try{
			csi = new WSwingConsoleInterface("My little Java Roguelike - Programming is fun", text);
		}
		catch (ExceptionInInitializerError eiie) {
			System.out.println("*** Error: Swing Console Box cannot be initialized. Exiting...");
			eiie.printStackTrace();
			System.exit(-1);
		}
		int x = 0;
		int y = 0;
		boolean stop = false;
		while(!stop){
			csi.cls();
			csi.print(x,y, '@', CSIColor.WHITE);
			csi.refresh();
			CharKey dir = csi.inkey();
			if(dir.isUpArrow()&& (y-1 >= 0)){
				y--;
			}
			if(dir.isDownArrow() && (y+1 < 25)){
				y++;
			}
			if(dir.isLeftArrow() && (x-1 >= 0)){
				x--;
			}
			if(dir.isRightArrow() && (x+1 < 80)){
				x++;
			}
			if(dir.code == CharKey.Q){
				stop = true;
			}
		}
		System.exit(0);
	}
 }