public
Description: A game on the lines of commercial game called CakeMania. The idea is to make an exciting free game which runs on GNU/linux and mac as well.
Homepage: http://codehunk.wordpress.com/
Clone URL: git://github.com/janmejay/bakery.git
bakery / src / bakery_wizard.rb
4a500ce4 » janmejay 2008-08-21 Played another refactoring ... 1 class BakeryWizard
2
3 class BaseWindow < Gosu::Window
4
5 WIDTH, HEIGHT = 1024, 768
6
7 def listner= listner
8 @listner = listner
9 end
10
11 def draw
12 draw_quad(0, 0, 0xffffffff, WIDTH, 0, 0xffffffff, 0, HEIGHT, 0xffffffff, WIDTH, HEIGHT, 0xffffffff)
13 @listner && @listner.draw
14 end
15
16 def update
17 @listner && @listner.update
18 end
19
20 end
21
22 class Window
856cb580 » janmejay 2008-08-23 Tried serialization... this... 23
24 module Buildable
25 def build context, window, from = nil, caption = 'Bakery'
26 instance = from ? Marshal.load(File.open(from, 'r').read) : new(context)
27 instance.window= window
28 window.caption = caption
29 window.listner = instance
30 instance
31 end
32 end
4a500ce4 » janmejay 2008-08-21 Played another refactoring ... 33
34 def self.REL map
35 {:x => (BaseWindow::WIDTH - self::WIDTH)/2 + map[:x], :y => (BaseWindow::HEIGHT - self::HEIGHT)/2 + map[:y]}
36 end
37
856cb580 » janmejay 2008-08-23 Tried serialization... this... 38 def self.inherited subclass
39 subclass.extend Buildable
4a500ce4 » janmejay 2008-08-21 Played another refactoring ... 40 end
41
42 def update; end
43 def draw; end
44
45 def window
46 @window
47 end
48
49 def method_missing *args
50 @window.send(*args)
51 end
52 end
53
54 def initialize
55 @screens = []
56 @current_screen = nil
57 @context = {}
58 @window = BaseWindow.new(1024, 768, false)
59 end
60
61 def add screen
62 @screens << screen
63 end
64
041b3b7f » janmejay 2008-08-24 Added some flow in the game... 65 def go_to requested_screen, *args
66 @current_screen && @current_screen.close
67 arguments = [@context, @window] + args
68 @current_screen = @screens.find { |screen| screen == requested_screen }.build(*arguments)
f29ed1ea » janmejay 2008-08-23 Got serialization of quite ... 69 @current_screen.show
4a500ce4 » janmejay 2008-08-21 Played another refactoring ... 70 end
71 end