Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Settings parser started

  • Loading branch information...
commit 1705359b07d0b2c3a139b84e18b50a804d31d974 1 parent 99b18a1
@txus authored
View
11 lib/classes/game_window.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,8 +35,9 @@ def initialize(w = 640, h = 480)
# Determine speed for each level according to ACCELERATION_FACTOR
set_level_speeds
-
+
end
+
def show
end
@@ -43,6 +45,11 @@ def show
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
View
16 lib/classes/settings.rb
@@ -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
4 lib/txustris.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.