Permalink
Browse files

Settings parser started

  • Loading branch information...
1 parent 99b18a1 commit 1705359b07d0b2c3a139b84e18b50a804d31d974 @txus committed May 16, 2009
Showing with 27 additions and 4 deletions.
  1. +9 −2 lib/classes/game_window.rb
  2. +14 −2 lib/classes/settings.rb
  3. +4 −0 lib/txustris.rb
@@ -6,6 +6,7 @@ def initialize(w = 640, h = 480)
@height = h
self.caption = "Txustris"
+ Settings.load
# Create a GUI for score and other data to be displayed during the game
@GUI = GUI.new
@@ -34,15 +35,21 @@ def initialize(w = 640, h = 480)
# Determine speed for each level according to ACCELERATION_FACTOR
set_level_speeds
-
+
end
+
def show
end
private
def set_level_speeds
-
+ initial_speed = INITIAL_SPEED
+ factor = 0.95
+ (1..20).each do |num|
+ #@speed_per_level.merge!(num => (initial_speed *= factor).to_i)
+ factor *= 0.988
+ end
end
end
@@ -1,4 +1,16 @@
class Settings
-
-
+ def self.load
+ xml = File.read('settings.xml')
+ file = REXML::Document.new(xml)
+ posts = []
+ file.elements.each('settings/setting') do |p|
+ name = p.elements.entries.values_at(0)[0].text # <name> ... </name>
+ value = p.elements.entries.values_at(1)[0].text # <value> ... </value>
+ self.class.send(:define_method, name) { puts value }
+ end
+ self.CONSTANT7
+ end
+ def self.reload
+ initialize
+ end
end
View
@@ -1,5 +1,6 @@
require 'rubygems'
require 'gosu'
+require 'rexml/document'
require 'classes/settings'
require 'classes/game_window'
require 'classes/player'
@@ -9,6 +10,9 @@
require 'classes/grid'
require 'classes/z_order'
+
+INITIAL_SPEED = 4
+
window = GameWindow.new
window.show

0 comments on commit 1705359

Please sign in to comment.