Java tutorial
/** * Copyright (C) 2013 Rusty Gerard * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package com.callidusrobotics; import java.awt.Font; import java.io.IOException; import org.apache.commons.io.IOUtils; import com.callidusrobotics.swing.Console; import com.callidusrobotics.swing.ConsoleFactory; import com.callidusrobotics.swing.FontFactory; import com.callidusrobotics.util.XmlMarshaller; public final class MythosRL { private MythosRL() { throw new AssertionError("Do not instantiate this class."); } @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") public static void main(final String[] args) throws IOException { final Font font = FontFactory.makeTrueTypeFontResource("/fonts/Custom/Commodore64.ttf", 8.0f); ConsoleFactory.initInstance(font, 50, 80); final Console console = ConsoleFactory.getInstance(); console.setTitle(getImplementationVersion()); final XmlMarshaller xmlMarshaller = new XmlMarshaller(GameData.class); final GameData gameData = (GameData) xmlMarshaller .unMarshal(IOUtils.toString(MythosRL.class.getResourceAsStream("/data/gameData.xml"))); boolean programRunning = true; while (programRunning) { console.clear(); final GameMediator mediator = new GameMediator(console, gameData); mediator.start(); while (mediator.isProgramRunning() && mediator.isGameRunning()) { console.render(); final char input = console.getKeyPress(); mediator.processInput(input); } programRunning = mediator.isProgramRunning(); if (programRunning) { console.render(); console.getKeyPress(); } } console.exit(); } private static String getImplementationVersion() { final Package myPackage = MythosRL.class.getPackage(); if (myPackage.getImplementationTitle() == null || myPackage.getImplementationVersion() == null) { return "Roguelike Debug Version"; } return myPackage.getImplementationTitle() + " " + myPackage.getImplementationVersion(); } }