\subsection{cutter/QUAD\_CUTTER.e}
\begin{lstlisting}
indexing
	description: "Factory to cut images into a puzzle"
	author: "Stefan Hildenbrand and Team UC"
	date: "$Date: 2005/06/20 13:51:31 $"
	revision: "$Revision: 1.3 $"

class 
	QUAD_CUTTER

inherit 

	ESDL_SHARED_BITMAP_FACTORY

create 

	make
			-- initialize cutter


feature -- Initialization

	make
			-- initialize cutter
	

feature -- Factory

	make_from_image (image_name: STRING; number_of_parts: INTEGER)
			-- create number_of_parts of image given by image_name (name of file)
		require
			name_valid: image_name /= Void and then not image_name.is_empty
		ensure
			puzzle_created: last_puzzle /= Void
	

feature -- Access

	last_puzzle: UC_PUZZLE
		-- the puzzle that was cutted

	last_image: ESDL_BITMAP
		-- and the image, that was used to cut it
	

feature {NONE} -- Implementation
		
	calculate_num_p(number_of_parts: INTEGER) : TUPLE[INTEGER, INTEGER] is
			-- calculate number of parts in row and col
			require
				image_not_void: image /= void
				meaningfull_number: number_of_parts > 0
			nsure
				result_created: result /= Void
				result_meaningful:  result.integer_item (1) > 0 and result.integer_item(2) > 0
				result_in_intervall_lower: (result.integer_item (1) * result.integer_item(2)) > 0.9*number_of_parts
				result_in_intervall_upper: (result.integer_item (1) * result.integer_item(2)) < 1.1*number_of_parts
				ratio_reflects_image: true -- todo

	calculate_part_size(row_col_number: TUPLE[INTEGER, INTEGER]) : TUPLE[INTEGER, INTEGER] is
			-- calculate size of parts
			require
				image_not_void: last_image /= void
				input_meaningful: row_col_number /= Void and then ( row_col_number.integer_item(1) > 0 and row_col_number.integer_item(2) > 0 )
				ratio_reflects_image: true -- todo
			ensure
				result_created: result /= Void
				result_meaningful: result /= Void and then ( result.integer_item(1) > 0 and result.integer_item(2) > 0 )
				size_somewhat_quadratic_1: result.integer_item(1) < 2* result.integer_item(2)
				size_somewhat_quadratic_2: result.integer_item(2) < 2* result.integer_item(1)
			
	create_parts(row_col_number: TUPLE[INTEGER, INTEGER]; size: TUPLE[INTEGER, INTEGER]) is
			-- does the actual cutting
			require
				image_not_void: last_image /= void
				last_puzzle_not_void: last_puzzle /= void
				number_useful: row_col_number /= Void and then ( row_col_number.integer_item(1) > 0 and row_col_number.integer_item(2) > 0 )
				size_useful: size /= Void and then ( size.integer_item(1) > 0 and size.integer_item(2) > 0 )
			ensure
				puzzle_created: last_puzzle /= void

	scale(x,y : INTEGER) : DOUBLE is 
			-- calculate zoom-factor such that x*y fits in max_width*max_height


feature {NONE} -- constants
	
	max_width : INTEGER is 400
	max_height : INTEGER is 600
		-- this denotes the maximal size, the image should have
		-- the image is zoomed to fit in this area


end -- class QUAD_CUTTER
\end{lstlisting}
\vspace*{1cm}

\subsection{cutter/SHARED\_QUAD\_CUTTER.e}
\begin{lstlisting}
indexing
	description: "Shared access to cutter singleton."
	author: "Stefan Hildenbrand and Team UC"
	date: "$Date: 2005/06/20 13:51:31 $"
	revision: "$Revision: 1.3 $"

class
	SHARED_QUAD_CUTTER


feature  -- Singleton Access

	cutter: QUAD_CUTTER is
		-- cutter singleton
		once
			create Result.make
		ensure
			cutter_not_void: Result /= Void
	
	
end -- class SHARED_QUAD_CUTTER
\end{lstlisting}
\vspace*{1cm}

\subsection{gui\_elements/BUTTON.e}
\begin{lstlisting}
indexing
	description: "Objects that implements a button"
	author: "Beat Steiger and UC Team"
	date: "$Date: 2005/06/20 13:51:31 $"
	revision: "$Revision: 1.3 $"

class
	BUTTON

inherit
	ESDL_DRAWABLE_CONTAINER[ESDL_DRAWABLE]
		rename
			make as make_container,
			initialize_events as initialize_container_events
		end

	UC_SHARED_ITEMS
		rename
			width as window_width,
			height as window_height
		export
			{NONE} all
		undefine
			copy,
			is_equal
		end

creation
	make,
	make_with_name,
	make_with_icon

feature -- Access

	font : ESDL_FONT

	active_color, normal_color, prelight_color, highlight_color : ESDL_COLOR

	border_color : ESDL_COLOR
	
	border_width : INTEGER

	name : STRING
	
	icon : ESDL_BITMAP
	
	min_width, min_height : INTEGER

	horizontal_margin, vertical_margin : INTEGER

	button_clicked_event : EVENT_TYPE [TUPLE []]
	
	mouse_over_button_event : EVENT_TYPE [TUPLE []]

	has_icon, has_name : BOOLEAN
	
	corners_rounded : BOOLEAN
	
	is_active, change_color_on_toggle_active : BOOLEAN

	is_prelighted, is_highlighted, is_pressed : BOOLEAN

feature -- Status setting

	set_width (a_width : INTEGER) is
			-- set the `width' of the button
		require
			not_too_small : a_width >= min_width

	set_height (a_height : INTEGER) is
			-- set the `height' of the button
		require
			not_too_small : a_height >= min_height

	set_vertical_margin (a_vertical_margin : INTEGER) is
			-- set the `vertical_margin' of the button
		require
			not_negative : a_vertical_margin >= 0

	set_horizontal_margin (a_horizontal_margin : INTEGER) is
			-- set the `horizontal_margin' of the button
		require
			not_negative : a_horizontal_margin >= 0

	set_name (a_name : STRING) is
			-- set the `name' of the button
		require
			a_name_not_void: a_name /= void

	set_icon (an_icon : ESDL_BITMAP) is
			-- set the `icon' of the button
		require
			an_icon_not_void: an_icon /= void

	set_font (a_font : ESDL_FONT) is
			-- set the `font' of the button
		require
			a_font_not_void: a_font /= void

	set_normal_color (a_normal_color : ESDL_COLOR) is
			-- set the `normal_color' of the button
		require
			a_normal_color_not_void: a_normal_color /= void

	set_prelight_color (a_prelight_color : ESDL_COLOR) is
			-- set the `prelight_color' of the button
		require
			a_prelight_color_not_void: a_prelight_color /= void

	set_highlight_color (a_highlight_color : ESDL_COLOR) is
			-- set the `highlight_color' of the button
		require
			a_highlight_color_not_void: a_highlight_color /= void

	set_border_color (a_border_color : ESDL_COLOR) is
			-- set the `border_color' of the button-border
		require
			a_border_color_not_void: a_border_color /= void
	
	set_border_width (a_border_width : INTEGER) is
			-- set the `border_width' to `a_border_width'
		require
			not_too_small: a_border_width >= 0

	set_corners_rounded is
			-- make the corners round

	set_corners_square is
			-- make the corners square

	toggle_active is
			-- toggle `active' state of this button.
			-- right after creation the state is false

	toggle_change_color_on_toggle_active is
			-- toggle `change_color_on_toggle_active' state of this button.
			-- right after the creation the state is true


feature {NONE} -- Creation

	make (an_event_loop : ESDL_EVENT_LOOP) is
			-- create a button
		require
			an_event_loop_not_void : an_event_loop /= void

	make_with_name (a_name : STRING; an_event_loop : ESDL_EVENT_LOOP) is
			-- create a button with the `name' set to `a_name'
		require
			a_name_not_void : a_name /= void
			an_event_loop_not_void : an_event_loop /= void

	make_with_icon (an_icon : ESDL_BITMAP; an_event_loop : ESDL_EVENT_LOOP) is
			-- create a button with `an_icon' on it
		require
			an_icon_not_void : an_icon /= void
			an_event_loop_not_void : an_event_loop /= void


feature {NONE} -- Implementation

	drawable_name : ESDL_STRING

	icon_cell : DS_BILINKABLE [ESDL_DRAWABLE]

	body : ESDL_RECTANGLE

	event_loop : ESDL_EVENT_LOOP

	set_default_values is
			-- set some values to their default

	initialize_events is
			-- initialize requred mouse_events

	button_clicked (ev : ESDL_MOUSEBUTTON_EVENT) is
			-- perform button-clicked actions

	button_released (ev : ESDL_MOUSEBUTTON_EVENT) is
			-- perform button-released actions

	button_prelight (ev : ESDL_MOUSEMOTION_EVENT) is
			-- perform prelight-button actions when mouse is over button


end -- class BUTTON
\end{lstlisting}
\vspace*{1cm}

\subsection{gui\_elements/TEXT\_FIELD.e}
\begin{lstlisting}
indexing
	description: "Object that implements a TextField"
	author: "Steiger Beat"
	date: "Fri 10 June 2005"

class
	TEXT_FIELD

inherit
	UC_SHARED_ITEMS
		rename
			width as screen_width,
			height as screen_height
		export
			{NONE} all
		undefine
			copy,
			is_equal,
			default_create
		end

	ESDL_DRAWABLE_CONTAINER [ESDL_DRAWABLE]
		rename
			make as make_container
		end

	ESDL_ANIMATABLE
		undefine
			default_create,
			copy,
			is_equal
		end


creation
	make


feature -- Access

	background_color : ESDL_COLOR
		-- the color of the background

	cursor_color : ESDL_COLOR
		-- the color of the cursor

	border_color : ESDL_COLOR
		-- the color of the border

	value : STRING
		-- the string-value of the text-field

	border_width : INTEGER
		-- the width of the border

	font : ESDL_FONT
		-- the font in which the text will be displayed

	focused : BOOLEAN
		-- is the text-field focused?

	cursor_blinkrate : INTEGER
		-- the blinking rate of the cursor
		-- (eg a cursor_blinkrate of 2 means that the cursor blinks twice a second)

	return_key_pressed_event : EVENT_TYPE [TUPLE[STRING]]

	set_font (a_font : ESDL_FONT) is
			-- sets the `font' of the TEXT_FIELD object to `a_color'
		require
	
	set_background_color (a_color : ESDL_COLOR) is
			-- sets the `background_color' of the TEXT_FIELD object to `a_color'
		require
			a_color_exists : a_color /= void
		do

	set_cursor_color (a_color : ESDL_COLOR) is
			-- sets the `cursor_color' of the cursor to `a_color'
		require
			a_color_exists : a_color /= void
	
	set_border_color (a_color : ESDL_COLOR) is
			-- sets the `border_color' of the TEXT_FIELD object to `a_color'
		require
			a_color_exists : a_color /= void
		
	set_border_width (a_border_width : INTEGER) is
			-- sets the `border_width' of the TEXT_FIELD object to `a_border_width'

	set_width (a_width : INTEGER) is
			-- sets the `width' of the TEXT_FIELD object to `a_width'
		require
			width_not_too_small: width >= border_width

	set_cursor_blinkrate (br : INTEGER) is
			-- sets the `cursor_blinkrate' of the cursor to `a_cursor_blinkrate'
		require
			blinkrate_not_zero : br /= 0
		
	set_value (v : STRING) is
			-- sets the `value' of the TEXT_FIELD object to `a_value'
		require
			v_not_void : v /= void

	go_to_time (a_time: INTEGER) is
			-- Go to the frame corresponding to `a_time' (in milliseconds) of the `cursor' animation.
	

feature {NONE} -- Initialisation

	make (an_event_loop : ESDL_EVENT_LOOP) is
			-- Create a textfield with default values
		require
			an_event_loop_not_void : an_event_loop /= void


feature {NONE} -- Implementation

	field : ESDL_RECTANGLE

	cursor : ESDL_SPRITE

	anim : ARRAY[ESDL_POLYLINE]

	e_string : ESDL_STRING

	event_loop : ESDL_EVENT_LOOP

	keyboard : ESDL_KEYBOARD

	subscribed_procedures : LINKED_LIST[PROCEDURE[ANY,TUPLE]] is
			-- linked-list to hold agents which were subscribed to the
			-- key_down_event of the `event_loop'
		once
			Result := create {LINKED_LIST[PROCEDURE[ANY,TUPLE]]}.make
		end

	set_focused (ev : ESDL_MOUSEBUTTON_EVENT) is
			-- set the focus on this textfield if left-mouse-button
			-- is clicked on it

	set_unfocused (ev : ESDL_MOUSEBUTTON_EVENT) is
			-- set the focus away from this textfield if left-mouse-button
			-- is clickt somewhere but on this textfield.

	get_key (ev : ESDL_KEYBOARD_EVENT) is
			-- Capture pressed keys

	display_value is
			-- generate the `e_string' which will be displayed in the textfield

	is_modifier_key (a_key_code : INTEGER) : BOOLEAN is
			-- returns true if `a_key_code' denotes a modifier_key (alt, ctrl, etc.)
		do
		

end -- class TEXT_FIELD
\end{lstlisting}
\vspace*{1cm}

\subsection{menus/CREDITS.e}
\begin{lstlisting}
indexing
	description: "Objects that represents the credits menu"
	author: "Benno Baumgartner, benno@student.ethz.ch"
	date: "$Date: 2005/06/20 13:51:31 $"
	revision: "$Revision: 1.3 $"

class 
	CREDITS

inherit

	MENU
		redefine
			initialize_scene
		end

	UC_SHARED_ITEMS
		export
			{NONE} all
		undefine
			default_create
		end
	
	
feature 

	initialize_scene
			-- Initialize the scene
	
	
feature {NONE} -- Event handler

	on_select is
			-- Set the `next_scene' according to `selected_nr' here
		
		
end -- class CREDITS
\end{lstlisting}
\vspace*{1cm}

\subsection{menus/LOAD\_GAME.e}
\begin{lstlisting}
indexing
	description: "load a game"
	author: "Markus Neidhart and UC Team"
	date: "$Date: 2005/06/20 13:51:31 $"
	revision: "$Revision: 1.3 $"

class
	LOAD_GAME
	
inherit
	MENU
		redefine
			initialize_scene
		end


feature -- Initialize

	load: UC_LOAD_PUZZLE
	
	initialize_scene is
			-- Initialize the scene
		
	set_situation (sit: PUZZLE_START_WINDOW) is
			-- set situation to `sit'
		require
			sit_not_void: sit /= Void
		ensure
			situation_set: situation = sit
		
		

feature {NONE} -- Implementation

	situation: PUZZLE_START_WINDOW 
			-- actual situation, will be set in UC_INTERFACE, which have it as last_scene

	text_field: TEXT_FIELD

	load_button: BUTTON

	psw: PUZZLE_START_WINDOW


feature {NONE} -- Event handler

	load_puzzle (val: STRING) is
			-- load the puzzle
		require
			val_not_Void: val /= Void
		
	load_button_clicked is
			-- click on load button		

	on_select is
			-- Set the `next_scene' according to `selected_nr' here
	
		
feature -- Input checking

	input_check : INTEGER is
			-- checks given input and returns error_code
			
	error_message(error_code: INTEGER) is
			-- put error message to given error_code on screen
	
	error_string : ESDL_STRING
			-- this is the error message
		

end -- class LOAD_GAME
\end{lstlisting}
\vspace*{1cm}

\subsection{menus/MENU.e}
\begin{lstlisting}
indexing

	description: "[
					MENU contains functionalities used by all menus in the
					game.
				]"
	author: "Benno Baumgartner, benno@student.ethz.ch, Mouse-Support by Stefan Hildenbrand and Team UC"
	date: "$Date: 2005/06/20 13:51:31 $"
	revision: "$Revision: 1.3 $"

deferred class

	MENU

inherit

	ESDL_SCENE
		redefine
			handle_key_down_event, handle_mouse_motion_event, handle_mouse_button_up_event
		end

	UC_SHARED_ITEMS
		undefine
			default_create
		end


feature

	initialize_scene is
			-- Initialize the scene
		

feature {NONE} -- Event handler

	handle_key_down_event (a_keyboard_event: ESDL_KEYBOARD_EVENT) is
			-- Handle keyboard events.

	handle_mouse_motion_event (mme: ESDL_MOUSEMOTION_EVENT) is
			-- handle mouse motion
		
	handle_mouse_button_up_event (a_mouse_button_event: ESDL_MOUSEBUTTON_EVENT) is
			-- handle mouse click

	on_select is
			-- Set the `next_scene' according to `selected_nr' here
		deferred
		end


feature {MENU,PUZZLE_START_WINDOW} -- Implementation

	scene: ESDL_DRAWABLE_CONTAINER [ESDL_DRAWABLE]
			-- The scene
		
	last_scene: ESDL_SCENE
		
	set_last_scene(ls: ESDL_SCENE) is
			-- create an instruction menu
		
	set_next_scene(ns: ESDL_SCENE) is
			-- set the next scene

	select_font: ESDL_BITMAPFONT
			-- The font used to display a selected menu entry

	normal_font: ESDL_BITMAPFONT
			-- The font used to display the not selected menu entries

	menu_entries: ARRAY [ESDL_STRING]
			-- The menu entries

	selected_nr: INTEGER
			-- The number of the selected entry

	update_menu_entries is
			-- Updates the `menu_entry'

	add_menu_entries_to_scene is
			-- Add menu entries to `scene'.
		
	restart_event_loop is
			-- restart the event loop
		
	empty_main_container is
			-- empty the main container


end -- Class Menu
\end{lstlisting}
\vspace*{1cm}

\subsection{menus/NEW\_GAME.e}
\begin{lstlisting}
indexing
	description: "lets the user set an image and a number of parts and starts the game with these parameters"
	author: "Markus Neidhart and UC Team"
	date: "$Date: 2005/06/20 13:51:31 $"
	revision: "$Revision: 1.3 $"

class
	NEW_GAME
	
inherit
	MENU
		redefine
			initialize_scene
		end
		
	ESDL_SHARED_BITMAP_FACTORY
		undefine
			copy, is_equal, default_create
		end


feature -- Initialize

	save: UC_SAVE_PUZZLE
	
	initialize_scene is
			-- Initialize the scene
	
		
feature {NONE} -- Implementation

	situation: PUZZLE_START_WINDOW 
			-- actual situation, will be set in UC_INTERFACE, which have it as last_scene

	text_field: TEXT_FIELD

	text_field2:TEXT_FIELD

	start_button: BUTTON

	psw: PUZZLE_START_WINDOW


feature {NONE} -- Event handler
		
	start_button_clicked is
			-- click on start button

	on_select is
			-- Set the `next_scene' according to `selected_nr' here
	

feature -- Input checking

	input_check : INTEGER is
			-- checks given input and returns error_code
					
	error_message(error_code: INTEGER) is
			-- put error message to given error_code on screen

	error_string : ESDL_STRING
			-- this is the error message
		

end -- class NEW_GAME
\end{lstlisting}
\vspace*{1cm}

\subsection{menus/PREDEFINED\_GAME.e}
\begin{lstlisting}
indexing
	description: "play a predefined game"
	author: "Markus Neidhart and UC Team"
	date: "$Date: 2005/06/20 13:51:31 $"
	revision: "$Revision: 1.3 $"

class
	PREDEFINED_GAME
	
inherit
	MENU
		redefine
			initialize_scene
		end


feature -- Initialize
	
	initialize_scene is
			-- Initialize the scene


feature {NONE} -- Event handler

	on_select is
			-- Set the `next_scene' according to `selected_nr' here
	

end -- class OPTIONS
\end{lstlisting}
\vspace*{1cm}

\subsection{menus/SAVE\_GAME.e}
\begin{lstlisting}
indexing
	description: "Objects that saves the uc puzzle"
	author: "Markus Neidhart and UC Team"
	date: "$Date: 2005/06/20 13:51:31 $"
	revision: "$Revision: 1.3 $"

class
	SAVE_GAME
	
inherit
	MENU
		redefine
			initialize_scene
		end


feature -- Initialize

	save: UC_SAVE_PUZZLE
	
	initialize_scene is
			-- Initialize the scene
		
	set_situation (sit: PUZZLE_START_WINDOW) is
			-- set situation to `sit'
		require
			sit_not_void: sit /= Void
		ensure
			situation_set: situation = sit
		

feature {NONE} -- Implementation

	situation: PUZZLE_START_WINDOW 
		-- actual situation, will be set in UC_INTERFACE, which have it as last_scene

	text_field: TEXT_FIELD

	save_button: BUTTON


feature {NONE} -- Event handler

	save_puzzle (val: STRING) is
			-- save the puzzle
		require
			val_not_Void: val /= Void
		
	save_button_clicked is
			-- click on save button
		
	on_select is
			-- Set the `next_scene' according to `selected_nr' here


end -- class SAVE_GAME
\end{lstlisting}
\vspace*{1cm}


\subsection{menus/SELECT\_GAME.e}
\begin{lstlisting}
indexing
	description: "user choose if play a game with his own parameters or a fixed modus game"
	author: "Markus Neidhart and UC Team"
	date: "$Date: 2005/06/20 13:51:31 $"
	revision: "$Revision: 1.3 $"

class
	SELECT_GAME
	
inherit
	MENU
		redefine
			initialize_scene
		end


feature -- Initialize
	
	initialize_scene is
			-- Initialize the scene


feature {NONE} -- Event handler

	on_select is
			-- Set the `next_scene' according to `selected_nr' here
	

end -- class SELECT_GAME
\end{lstlisting}
\vspace*{1cm}

\subsection{menus/UC\_INTERFACE.e}
\begin{lstlisting}
indexing
	description: "Main Menu for Game UC."
	author: "Team UC with thanks to Benno Baumgartner"
	date: "$Date: 2005/06/20 13:51:31 $"
	revision: "$Revision: 1.3 $"

class
	UC_INTERFACE

inherit

	MENU
		redefine
			initialize_scene
		end


feature -- commands

	initialize_scene is
			-- Initialize the scene
		

feature {NONE} -- Event handler

	on_select is
			-- Set the `next_scene' according to `selected_nr' here
		

end
\end{lstlisting}
\vspace*{1cm}

\subsection{model\_view/UC\_PUZZLE.e}
\begin{lstlisting}
indexing
	description: "This contains all puzzle_parts of a puzzle."
	author: "Stefan Hildenbrand and Team UC"
	date: "$Date: 2005/06/20 13:51:31 $"
	revision: "$Revision: 1.3 $"

class
	UC_PUZZLE

create
	make_empty
	

feature -- initialization
	make_empty is
			-- creates an empty puzzle.
			-- use a cutter to make puzzles
		
		
feature -- Access

	get_puzzle_part (pos_x: INTEGER; pos_y: INTEGER): UC_PUZZLE_PART is
			-- get the puzzle_part with pos_x and pos_y, Void when not found
		
	image_width: INTEGER
			-- width of the image, this puzzle was made of
			
	image_height: INTEGER
			-- height of the image, this puzzle was made of
			
	part_width: INTEGER
			-- width of one part of this puzzle
	
	part_height: INTEGER
			-- height of one part of this puzzle
			
	num_parts_width: INTEGER
			-- number of parts in width
	
	num_parts_height: INTEGER
			-- number of parts in height		
			
	
feature {QUAD_CUTTER} -- Status setting

	set_image_size (size : TUPLE[INTEGER, INTEGER]) is
			-- set size of the image to size=(width, height)
			require
				size_not_void: size /= void
			
	set_part_size (size : TUPLE[INTEGER, INTEGER]) is
			-- set size of the parts to size=(width, height)
			require
				size_not_void: size /= void
	
	set_part_num (num : TUPLE[INTEGER, INTEGER]) is
			-- set number of parts to num=(num in width, num in height)
			require
				num_not_void: num /= void

			
feature {QUAD_CUTTER} -- Element change
	
	extend (new_part : UC_PUZZLE_PART) is
			-- put new part in part_list
			require
				new_part_not_void: new_part /= void
		

feature -- Element Change
	mix_up is
			-- mixes given list up
		
			
feature {UC_PUZZLE_VIEW} -- Parts

	part_list: DS_BILINKED_LIST[ESDL_DRAWABLE]
			-- the list of all puzzle_parts in this puzzle


end -- class UC_PUZZLE
\end{lstlisting}
\vspace*{1cm}

\subsection{model\_view/UC\_PUZZLE\_PART.e}
\begin{lstlisting}
indexing
	description: "This class denotes the model of the puzzle parts in game UC."
	author: "Stefan Hildenbrand and Team UC"
	date: "$Date: 2005/06/20 13:51:31 $"
	revision: "$Revision: 1.3 $"

class
	UC_PUZZLE_PART

inherit
	ESDL_DRAWABLE
		redefine default_create, is_equal end
		-- altough a puzzle_part is itself drawable, one should use a uc_puzzle_part_view to actually draw a uc_puzzle_part

	ESDL_SHARED_BITMAP_FACTORY
		export {NONE} all
		undefine default_create, copy, is_equal end
		-- we need the bitmapfactory to rotate the pictures

create
	make_from_bitmap


feature {NONE} -- Creation

	default_create is
			-- initialize object
			-- DO NOT USE THIS ONE
			
	make_from_bitmap(bitmap: ESDL_BITMAP) is
			-- initialize object
			

feature -- Comparison

	is_equal (other : like current) : BOOLEAN is
			-- tow puzzle_parts are equal, if they show the same part of the picture
					
			
feature -- Status

	width: INTEGER
			-- width of this part

	height: INTEGER
			-- height of this part

	pos_x : INTEGER
			-- position of this part in the whole puzzle
			-- coords start at top right
			-- pos_x gives col

	pos_y : INTEGER
			-- position of this part in the whole puzzle
			-- coords start at top left
			-- pos_y gives row

	locked: BOOLEAN
			-- may this part be moved, that means, is part already placed correctly ?

	correct(ax,ay:INTEGER): BOOLEAN is
			-- is this part at its correct place ?
			-- x,y denote the top left corner of to_field
	

feature -- Drawing

	draw(a_surface: ESDL_SURFACE) is
			-- draw part on a_surface
			-- for compatibility. use a view of this part instead and then call draw_oriented

	draw_oriented(a_surface: ESDL_SURFACE; orient,an_x,an_y : INTEGER) is
			-- draw this part on a_surface with given orient
			require
				orient_feasible: (orient>0 and orient<5)
				surface_there: a_surface /= void


feature -- Element change

	lock  is
			-- lock this part

	set_pos (an_x, an_y: INTEGER) is
			-- set pos of this part in the puzzle


feature -- Pictures
	picture: ESDL_BITMAP
		-- the picture of the part

	-- following singleton access to rotated images
	picture2: ESDL_BITMAP is

	pic2: ESDL_BITMAP

	picture3: ESDL_BITMAP is

	pic3: ESDL_BITMAP

	picture4: ESDL_BITMAP is

	pic4: ESDL_BITMAP


invariant
	pic_not_void : picture /= void
	

end -- class UC_PUZZLE_PART
\end{lstlisting}
\vspace*{1cm}

\subsection{model\_view/UC\_PUZZLE\_PART\_VIEW.e}
\begin{lstlisting}
indexing
	description: "This is a view of a puzzle_part.."
	author: "Stefan Hildenbrand and Team UC"
	date: "$Date: 2005/06/20 13:51:31 $"
	revision: "$Revision: 1.3 $"

class
	UC_PUZZLE_PART_VIEW

inherit
	ESDL_DRAWABLE
		redefine is_equal end

create
	make_from_puzzle_part


feature -- Initialization

	make_from_puzzle_part(puzz_part: UC_PUZZLE_PART) is			
				-- create a new view of given puzz_part
			require
				puzz_part_not_void: puzz_part /= void
	

feature -- Comparison

	is_equal (other: like current) : BOOLEAN is
			-- two puzzle_part_views are equal if they show the same part
			

feature -- Status report

	save: STRING is
			-- give all the information that are required to save this ppv

	orientation: INTEGER
		-- how is this view oriented, 1 is normal, 2 rotated by 90 deg clockwise usw

	width: INTEGER is
			-- width of this view

	height: INTEGER is
			-- height of this part

	locked: BOOLEAN is
			-- is part locked
			
	correct(ax, ay: INTEGER): BOOLEAN is
			-- is part correctly set
			-- ax, ay denote coordination transformation
		

feature -- Element change

	rotate is
			-- rotate view
			
	lock is
			-- lock this part


feature -- Drawing

	draw(a_surface: ESDL_SURFACE) is
		-- draw part on a_surface
			
	draw_solved(a_surface: ESDL_SURFACE; ax,ay : INTEGER) is
			-- draw part on a_surface
			require
				puzzle_part.locked
			

feature -- Implementation

	puzzle_part: UC_PUZZLE_PART
		-- the part this view shows


end -- class UC_PUZZLE_PART_VIEW
\end{lstlisting}
\vspace*{1cm}

\subsection{model\_view/UC\_PUZZLE\_VIEW.e}
\begin{lstlisting}
indexing
	description: "this is a view of a puzzle."
	author: "Stefan Hildenbrand and Team UC"
	date: "$Date: 2005/06/20 13:51:31 $"
	revision: "$Revision: 1.3 $"

class
	UC_PUZZLE_VIEW

inherit
	ESDL_DRAWABLE_CONTAINER[ESDL_DRAWABLE]

create
	make_from_puzzle, make_from_other, make


feature -- Initialization
	make_from_other(other: UC_PUZZLE_VIEW) is
			-- initialize this puzzle_view
			-- copy the parts-list from given puzzle_view
			require 
				other_not_void: other /= void
		
	make_from_puzzle(a_puzzle: UC_PUZZLE) is
			-- initialize this puzzle_view with given puzzle
			require
				a_puzzle_is_not_void: a_puzzle /= void
	

feature -- Status

	parts_in_row : INTEGER
		-- how many parts are drawn in a row ?
		
	copy_parameter_from(other: UC_PUZZLE_VIEW) is
			-- set the parameters according to other
		
		
feature -- Element change

	set_parts_in_row (i: INTEGER) is
			-- set parts_in_row to i
			require
				i_useful : i > 0
	
		
feature -- puzzle attributes

	image_width : INTEGER
	image_height: INTEGER
		-- size of the image this view was made of

	part_width: INTEGER
	part_height: INTEGER
		-- size of the parts this puzzle was made of

	
end -- class UC_PUZZLE_VIEW
\end{lstlisting}
\vspace*{1cm}

\subsection{sound/ESDL\_AUDIO\_CONSTANTS.e}
\begin{lstlisting}
indexing
	description: "Some audio constants"
	author: "Yann Mueller muelleya@student.ethz.ch"
	date: "$Date: 2005/06/20 13:51:31 $"
	revision: "$Revision: 1.3 $"

class
	ESDL_AUDIO_CONSTANTS

feature
	Esdl_audio_format_u8: INTEGER is
			-- Unsigned 8-bit samples
		external
			"C macro use <esdl.h>"
		alias
			"AUDIO_U8"
		end

	Esdl_audio_format_s8: INTEGER is
			-- Signed 8-bit samples
		external
			"C macro use <esdl.h>"
		alias
			"AUDIO_S8"
		end

	Esdl_audio_format_u16lsb: INTEGER is
			-- Unsigned 16-bit samples
		external
			"C macro use <esdl.h>"
		alias
			"AUDIO_U16LSB"
		end

	Esdl_audio_format_s16lsb: INTEGER is
			-- Signed 16-bit samples
		external
			"C macro use <esdl.h>"
		alias
			"AUDIO_S16LSB"
		end

	Esdl_audio_format_u16msb: INTEGER is
			-- As above, but big-endian byte order
		external
			"C macro use <esdl.h>"
		alias
			"AUDIO_U16MSB"
		end

	Esdl_audio_format_s16msb: INTEGER is
			-- As above, but big-endian byte order
		external
			"C macro use <esdl.h>"
		alias
			"AUDIO_S16MSB"
		end
		
	Esdl_audio_format_u16: INTEGER is
			-- 
		external
			"C macro use <esdl.h>"
		alias
			"AUDIO_U16"
		end
		
	Esdl_audio_format_s16: INTEGER is
			-- 
		external
			"C macro use <esdl.h>"
		alias
			"AUDIO_S16"
		end
		
	Esdl_audio_format_u16sys: INTEGER is
			-- 
		external
			"C macro use <esdl.h>"
		alias
			"AUDIO_U16SYS"
		end
		
	Esdl_audio_format_s16sys: INTEGER is
			-- 
		external
			"C macro use <esdl.h>"
		alias
			"AUDIO_S16SYS"
		end

	
end
\end{lstlisting}
\vspace*{1cm}

\subsection{sound/ESDL\_MIXER.e}
\begin{lstlisting}
indexing
	description: "audio mixer device - OO wrapper for SDL_mixer"
	author: "Yann Mueller muelleya@student.ethz.ch"
	date: "$Date: 2005/06/20 13:51:31 $"
	revision: "$Revision: 1.3 $"

class
	ESDL_MIXER

inherit

	ESDL_CONSTANTS
		export
			{NONE} all
		end

	ESDL_AUDIO_CONSTANTS
		export
			{NONE} all
		end

	SDL_MIXER_FUNCTIONS
		export
			{NONE} all
		end

	SDL_FUNCTIONS_EXTERNAL
		export
			{NONE} all
		end

create

	make


feature {NONE} -- Initialization

	make is
			-- Create a new mixer instance.


feature -- Basic operations

	open is
			-- Open the mixer device
		require
			not_open: not is_open

	close is
			-- Close the mixer device
		require
			is_open

	play_music is
			-- Play the music
		require
			device_open: is_open
			music_set: music /= Void

	stop_music is
			-- Stop the music
		require
			device_open: is_open
			music_set: music /= Void

	pause_music is
			-- pause the music
		require
			device_open: is_open
			music_set: music /= Void

	resume_music is
			-- resume paused music
		require
			device_open: is_open
			music_set: music /= Void

	halt_channel(a_channel :INTEGER) is
			-- halt channel


feature -- Access

	music_paused: BOOLEAN
			-- is the music currently paused?

	music: ESDL_MUSIC
			-- the current music object

	music_volume: INTEGER
			-- the volume of the music

	frequency: INTEGER
			-- The mixer frequency

	bits_per_sample: INTEGER
			-- bits per sample

	channels: INTEGER
			-- number of channels

	chunksize: INTEGER
			-- chunk size of the mixer


feature -- Element change

	set_music (a_music: ESDL_MUSIC) is
			-- Set the music object

	set_music_volume (a_volume: INTEGER) is
			-- Set the music volume
		local
			i: INTEGER

	set_frequency (a_frequency: INTEGER) is
			-- set mixer frequency
		require
			not_open: not is_open

	set_bits_per_sample (a_bits_per_sample: INTEGER) is
			-- set bits per sample
		require
			not_open: not is_open
			valid: a_bits_per_sample = 8 or a_bits_per_sample = 16

	set_channels (a_channels: INTEGER) is
			-- set number of channels
		require
			not_open: not is_open
			valid: a_channels = 1 or a_channels = 2

	set_chunksize (a_chunksize: INTEGER) is
			-- set the chunk size
		require
			not_open: not is_open


feature -- Status report

	is_open: BOOLEAN
			-- Is the device open

	is_music_playing: BOOLEAN is
			-- Is the music playing


end
\end{lstlisting}
\vspace*{1cm}

\subsection{sound/ESDL\_MUSIC.e}
\begin{lstlisting}
indexing
	description: "Music class to play in the mixer"
	author: "Yann Mueller muelleya@student.ethz.ch"
	date: "$Date: 2005/06/20 13:51:31 $"
	revision: "$Revision: 1.3 $"

class 
	ESDL_MUSIC
	
inherit
			
	SDL_MIXER_FUNCTIONS	

create 

	make_from_file (a_filename: STRING)
			-- Create a music object from a file


feature {NONE} -- Initialization

	make_from_file (a_filename: STRING) is
			-- Create a music object from a file
		

feature -- Access

	loops: INTEGER
			-- loop count. 0 means play only once. -1 means loop forever

	Sizeof: INTEGER is 0
			-- unknown size -> 0
	
	
feature -- Element change

	rewind
			-- rewind_music

	set_loops (a_loops: INTEGER)
			-- set loop count
		ensure
			set: loops = a_loops
	
	
feature -- Removal

	dispose
			-- Free external resources


feature {ESDL_MIXER}
	
	music_handle: POINTER	


feature -- Implementation

	filename: STRING
	

end -- class ESDL_MUSIC
\end{lstlisting}
\vspace*{1cm}

\subsection{sound/MUSIC\_PLAYER.e}
\begin{lstlisting}
indexing
	description: "Objects that manages all the sound events"
	author: "Florian Keusch, fkeusch@student.ethz.ch, Markus Neidhart, nemarkus@student.ethz.ch and UC Team"
	date: "$Date: 2005/06/20 13:51:31 $"
	revision: "$Revision: 1.3 $"

class
	MUSIC_PLAYER

create
	make


feature -- Initialization
	
	make is
			-- create `musictrack'
		ensure
			musictrack_exists: musictrack /= Void
			musictrack_is_open: musictrack.is_open
		

feature -- player functions

	open_sound (track: STRING) is
			-- opens the soundfile specified by `track'. Has to be a .ogg file.

	play () is
			-- plays loaded soundfile
		require
			sound_file_loaded: musictrack.music /= Void
		ensure
			music_is_playing: musictrack.is_music_playing
		
	stop () is
			-- stop loaded soundfile
		require
			sound_file_loaded: musictrack.music /= Void
		ensure
			sound_file_is_void: musictrack.music = Void
		
		
	pause () is
			-- pause loaded soundfile if playing
			-- unpause loaded soundfile if stopped
		require
			sound_file_loaded: musictrack.music /= Void
		
	next () is
			-- plays the next song
			
	previous () is
			-- plays the previous song

	set_volume (vol: INTEGER) is
			-- sets the volume
		require
			vol_not_void: vol /= Void
	
	turn_up is
			-- set the volume louder
		
	turn_down is
			-- turns the volume down
		

feature -- Implemenation

	read_sound_dir is
			-- go through sound_dir and check for playable files -> put into sound_container
	
	play_song (a_string: STRING) is
			-- plays the song with the string
			-- caution: string must exist
	
	set_sound_dir (a_string: STRING) is
			-- set a new sound_dir and read it
		require
			not_void_string: a_string /= Void
	
	next_song: STRING is
			-- gives back the string of the next song

	previous_song: STRING is
			-- gives back the string of the previous song

	set_event_loop(an_ev: ESDL_EVENT_LOOP) is
			-- set new event loop
		
	check_terminated:BOOLEAN is
			-- checks if song is finished

	check_next is
			-- checks if song is finished -> and then plays next
		
	mute is
			-- set volume to 1
			-- backup old volume
		
	
feature -- Status

	is_playing: BOOLEAN is
			-- checks if player is playing
		
	is_stopped: BOOLEAN is
			-- checks if player is stopped
	
	is_paused: BOOLEAN is
			-- checks whether player is paused
		
	song_nr: INTEGER is
			-- get the song number
	
	song_title: STRING is
			-- get the song title
			-- with path
		
	volume: INTEGER is
			-- gives back the music volume
		
	song_title_cut: STRING is
			-- get the song title cut
	
	is_empty: BOOLEAN is
			-- checks if player has items to play
	
		
feature -- Access

	musictrack: ESDL_MIXER 
		-- Mixer object
		
	sound_dir: STRING 
			-- string that indicates the sound directory

	sound_container: LINKED_LIST[STRING] is
				-- sound_container of strings
			once
				create Result.make
			ensure
				not_void: Result /= void
			end
			
	playing: INTEGER
			-- number of the song that is currently played or stopped
	
	ready: BOOLEAN
			-- indicates whether player is ready (sound_container has at least one element)
			
	event_loop_set: BOOLEAN
			-- check if event_loop is set
	
	ev: ESDL_EVENT_LOOP
			-- the event_loop that was given
	
	old_volume: INTEGER


invariant
	
	musictrack_exists: musictrack /= Void
	playing >= 0
	volume >= 0
	old_volume >= 0


end -- class MUSIC_PLAYER
\end{lstlisting}
\vspace*{1cm}

\subsection{workspace/UC\_FROM\_SPACE}
\begin{lstlisting}
indexing
	description: "This denotes a special kind of puzzle_view. Parts in this view only disappear, when they are locked.."
	author: "Stefan Hildenbrand and Team UC"
	date: "$Date: 2005/06/20 13:51:31 $"
	revision: "$Revision: 1.3 $"

class
	UC_FROM_SPACE

inherit

	UC_WORKSPACE
		redefine
			cond_delete
		end

	ESDL_SHARED_BITMAP_FACTORY
		export {NONE} all
		undefine copy, is_equal
		end

create
	make_from_puzzle


feature -- Element change
	cond_delete(v: ESDL_DRAWABLE) is
			-- redefine delete to handle the case where we want to delete
			-- the hidden element (which will most likely happen very often)
			-- IMPORTANT: this does not delete the part_view if it is not locked yet!
			--    instead it makes a copy of the part to delete and keeps the copy !
			

end -- class UC_FROM_SPACE
\end{lstlisting}
\vspace*{1cm}

\subsection{workspace/UC\_TO\_SPACE.e}
\begin{lstlisting}
indexing
	description: "This is a special view of a puzzle. This view does not allow deletion and draws the parts always correct."
	author: "Stefan Hildenbrand and Team UC"
	date: "$Date: 2005/06/20 13:51:31 $"
	revision: "$Revision: 1.3 $"

class
	UC_TO_SPACE

inherit
	UC_PUZZLE_VIEW
		redefine draw end

create
	make
	

feature
		
	draw (a_surface: ESDL_SURFACE) is
			-- Draw `Current' to `a_surface'
			-- this draws the parts in this workspace in a sorted way

		
feature -- Status report

	save: STRING is
			-- give a string back that holds all information for saving this workspace
		

end -- class UC_TO_SPACE
\end{lstlisting}
\vspace*{1cm}

\subsection{workspace/UC\_WORKSPACE.e}
\begin{lstlisting}
indexing
	description: "this is a special kind of puzzle_view, which supports sorted insertions, but does not impose restriction on extending or deleting"
	author: "Stefan Hildenbrand and Team UC"
	date: "$Date: 2005/06/20 13:51:31 $"
	revision: "$Revision: 1.3 $"

class
	UC_WORKSPACE

inherit
	UC_PUZZLE_VIEW
		redefine
			draw, delete, width, height
		end
	
	ESDL_SHARED_BITMAP_FACTORY
		export {NONE} all
		undefine copy, is_equal
		end

create
	make_from_puzzle, make_from_other, make
	

feature -- Drawing

	draw (a_surface: ESDL_SURFACE) is
			-- Draw `Current' to `a_surface'
			-- this draws the parts in this workspace in a sorted way
		
		
feature -- Status Report

	save: STRING is
			-- give a string back that holds all information for saving this workspace
		ensure
			Result_not_Void: Result /= Void
	
	width: INTEGER is
			-- width of this workspace

	height: INTEGER is
			-- height of this workspace
	

feature -- Element change
	
	hidden_part: UC_PUZZLE_PART_VIEW
		-- remember the part we hide

	hidden_index: INTEGER
		-- where is the part we had hidden
	
	hide (part_view : UC_PUZZLE_PART_VIEW) is
			-- hide given part, but do not reorder parts yet
			require
				item_is_there: has(part_view)
			
	unhide is
			-- show the part that was hidden before
			-- this function si tolerant, if there is no part we hide, just do nothing
			--require
			--	hidden_part_exists: hidden_part /= void

	cond_delete(v: ESDL_DRAWABLE) is
			-- sometimes we do want to make an conditional delete
			require
				v_not_void: v/= void
		
	delete(v: ESDL_DRAWABLE) is
			-- redefine delete to handle the case where we want to delete
			-- the hidden element (which will most likely happen very often)
			
	extend_sorted(v: UC_PUZZLE_PART_VIEW) is
			-- put given part v in the list, such that it appears there, where the user moved it
			-- ax,ay are coordinates, the source is the top right corner of this container!
			require
				v_not_void: v /= void
		
	sortable (v : UC_PUZZLE_PART_VIEW) : BOOLEAN is
			-- is a part with given coordinates sortable in this workspace
			require
				v_not_void: v /= void
			
	set_list(new_list : DS_BILINKED_LIST[ESDL_DRAWABLE]) is
			-- copy given part_list to this workspace
			require
				argument_not_void : new_list /= void
			

end -- class UC_WORKSPACE
\end{lstlisting}
\vspace*{1cm}

\subsection{FINISH\_SCREEN.e}
\begin{lstlisting}
indexing
	description: "Screen that shows the image that was solved and congratulates the user."
	author: "Stefan Hildenbrand and Team UC"
	date: "$Date: 2005/06/20 13:51:31 $"
	revision: "$Revision: 1.3 $"

class
	FINISH_SCREEN

inherit
	ESDL_SIMPLE_SCENE
	
	UC_SHARED_ITEMS
		rename 
			height as window_height,
			width as window_width
		undefine
			default_create, is_equal, copy
		end
		
	MEMORY
		undefine
			default_create, is_equal, copy
		end

create
	make_from_image


feature -- Access

	make_from_image(image: ESDL_BITMAP) is
			-- create this scene
			
	handle_continue is
			-- continue with menu


end -- class FINISH_SCREEN
\end{lstlisting}
\vspace*{1cm}


\subsection{PUZZLE\_START\_WINDOW.e}
\begin{lstlisting}
indexing

	description: "Main class of puzzle game UC"
	author: "Team UC"
	date: "$Date: 2005/06/20 13:51:31 $"
	revision: "$Revision: 1.3 $"

class

	PUZZLE_START_WINDOW

inherit
	ESDL_SCENE
		redefine
			initialize_scene, handle_key_down_event
		end	
		
	UC_SHARED_ITEMS
		export
			{NONE} all
		undefine
			default_create
		end	
		
	MEMORY -- need some additional memory management
		undefine
			default_create
		end

	SDLKEY_ENUM_EXTERNAL -- need the key codes
		
		export 
			{NONE} all
		undefine
			default_create
		end


feature {NONE} -- Initialization

	initialize_scene is
			-- Create the main application.
	
	initialize_events is
			-- initialize all events
			
	create_buttons is
			-- create all the buttons

	uninit_guis  is
				-- removes all the guis and checks many things
				

feature {UC_SAVE_PUZZLE, UC_LOAD_PUZZLE} -- Status

	image_file_name: STRING
			-- Name of image we want to display
	
	image: ESDL_BITMAP
			-- the image that was used to cut the puzzle
		
	number_of_parts: INTEGER
			-- The number of parts


feature {UC_SAVE_PUZZLE, UC_LOAD_PUZZLE} -- Workspaces, Puzzle usw	    

	puzzle : UC_FROM_SPACE
		-- this is the container for the puzzle parts at the left side of screen
		
	workspace1 : UC_WORKSPACE
	workspace2 : UC_WORKSPACE
		-- this are the container where the user can do what he wants to
	
	active_space : UC_WORKSPACE
		-- this is the container which is actually on top and active
	
	to_field: UC_TO_SPACE
		-- this is the container for the puzzle_parts which are placed correctly
	
	puzzle_part_view : UC_PUZZLE_PART_VIEW
		-- active item to move


feature {NONE} -- Buttons for workspace control

	button_fs : BUTTON
		-- this is the button representating the from_space
		
	button_w1 : BUTTON
	button_w2 : BUTTON
		-- this are the buttons representating the workspaces
		
	button_trash : BUTTON
		-- button for deleting a part from a workspace
	
	button_reset: BUTTON
		-- button for resetting a workspace
		
	button_image : BUTTON
		-- button for showing the solution
	
	button_cheat : BUTTON
		-- button for cheating
		
	y_coord: INTEGER is
		-- y_coord for the menu gui
		once
			Result := height - mute.height - song_title_to_show.height - 5
		end	

	load: BOOLEAN
		-- is to load?


feature -- load feature
	
	set_load is
		-- sets to load	


feature {NONE} -- Agents

	handle_mouse_button_down_on_item (an_item: ESDL_DRAWABLE; a_mouse_button_event: ESDL_MOUSEBUTTON_EVENT) is
			-- This activates the part the user clicked on

	handle_mouse_motion (a_motion_event: ESDL_MOUSEMOTION_EVENT) is
			-- this moves the part around on the screen
			-- if button is released:
			-- if it is at correct position, it gets locked
			-- if part is moved to other position in workspace, the workspace gets rearranged
			-- otherwise it jumps back to where it came from


feature {NONE} -- Agents for workspace control
		
		handle_ws_button (to : UC_WORKSPACE) is
				-- handle event when a workspace button is clicked
				require
					to_not_void: to /= void
					as_not_void: active_space /= void
		
		toggle_buttons is
				-- set buttons according to active_space
		
		handle_trash_button is
				-- handle deleting a part from active workspace
			
		handle_reset_button is
				-- handle resetting active workspace
		
		handle_image_button is
				-- handle showing solution
				
		handle_image_disappear(a_time : INTEGER) is
				-- hide image at given point in time
			
		handle_finish is
				-- handle the fact, that puzzle is solved
				
		handle_cheat is
				-- handle cheat request
			

feature {NONE} -- Agent for key handling

		handle_key_down_event (a_keyboard_event: ESDL_KEYBOARD_EVENT) is
			-- handle key down events
			-- ESC: go to menu
			-- q: quit application
			-- b: back to the previous song
			-- n: go to the next song
			-- m: mute / unmute
			-- c: cheat
			-- 0,1,2 switch workspaces
			-- d delete actual part if one clicked otherwise delete all parts from workspace
			-- r reset workspace
			-- i show image


feature {NONE} -- Agents for sound control

		toggle_stop is
				-- toggle `player' stop

		toggle_play_pause is
				-- toggle `player' play pause
	
		toggle_mute is
				-- toggle `player' mute
			
		toggle_previous is
				-- toggle `player' previous
			
		toggle_next is
				-- toggle `player' next


feature {NONE} -- Sound control

	play_icon, pause_icon, stop_icon, next_icon, prev_icon, sound_icon, nosound_icon: ESDL_BITMAP
	play_pause, stop, next, prev, mute : BUTTON

	check_next_song is
			-- checks if next song is played

	enable_song_title_showing is
			-- enable song title showing
		
	disable_song_title_showing is
			-- disable to show the song title
		
	song_title: STRING	
		
	song_title_to_show: ESDL_STRING
		-- song_title that is currently showed

	song_show: BOOLEAN
		-- intidates whether to show the song

	init_player_gui is
			-- create the gui (prev, play/pause, stop, next, mute)


feature -- access

	initialize_loaded is
				-- initialize this psw when things are already loaded

	set_from_space (fs: UC_FROM_SPACE) is
			-- set puzzle to fs
		require
			fs_not_Void: fs /= Void
	
	set_to_space (ts: UC_TO_SPACE) is
			-- set to_field to ts
		require
			ts_not_Void: ts /= Void
		
	set_workspaces (workspace_1: UC_WORKSPACE; workspace_2: UC_WORKSPACE) is
			-- set both workspaces
		require
			not_Void: workspace_1 /= Void and workspace_2 /= Void

	set_image_file_name (a_filename: STRING) is
			-- set image_file_name to a_filename
		require
			a_filename_not_Void: a_filename /= Void
		
	set_number_of_parts (nop: INTEGER) is
			-- set the number of parts
	

feature {MENU} -- menu features
		
	set_next_scene(ns: ESDL_SCENE) is
			-- set the next scene
		
	restart_event_loop is
			-- restart the event loop
		
	is_initialized: BOOLEAN -- is this puzzle_start_window already initialized?
	
	pause_force: BOOLEAN -- true if player.pause is manually set by the user
	
	set_initialized (b: BOOLEAN) is
			-- set is_initialized to b
		
		
end		
\end{lstlisting}
\vspace*{1cm}

\subsection{RANDOM\_NUMBER\_GENERATOR.e}
\begin{lstlisting}
indexing
	description: "Objects that Generates random numbers"
	author: "Florian Keusch, fkeusch@student.ethz.ch"
	date: "$Date: 2005/06/20 13:51:31 $"
	revision: "$Revision: 1.3 $"

class
	RANDOM_NUMBER_GENERATOR

create
	make


feature {NONE} -- Random Access

	rand: RANDOM
		-- random number gen
		
	timer: TIME	
		-- time at initialization
		
	init_seed: INTEGER
		-- the init seed of the random number generator
		
	next_nr: INTEGER
		-- the number of the next random number


feature -- init

	make is
			-- initializes the random number generator

	remake (seed: INTEGER) is
			-- reinitialize with new seed
		

feature -- functions

	next_int_mod  (n: INTEGER) : INTEGER is
			-- get the next random integer value mod n
			-- if n is 101 you get numbers from 0 to 100
			-- NOTE: n should be prime to get good results
			-- for example n := 101
		require
			n_not_void: n /= Void
	
	next_int_mod_minus_1 (n:INTEGER) : INTEGER is
			-- the same as next_int_mode but without zero
		require
			n_not_void: n /= Void

	next_int: INTEGER is
			-- get the next random integer value

		
	next_double: DOUBLE is
			-- get the next random double value
			-- normalized between 0 and 1
		
	next_real: REAL is
			-- get the next random real value
			-- normalized between 0 and 1
		
	next_bool: BOOLEAN is
			-- get random boolean value
		

end -- class RANDOM_NUMBER_GENERATOR
\end{lstlisting}
\vspace*{1cm}

\subsection{UC.e}
\begin{lstlisting}
indexing
	description: "System's root class"
	note: "Initial version automatically generated"

class 
	UC
	
inherit
	ESDL_APPLICATION
	
	UC_SHARED_ITEMS	

create 

	make
			-- Creation procedure.


feature -- Initialization

	make
			-- Creation procedure.


end -- class UC
\end{lstlisting}
\vspace*{1cm}

\subsection{UC\_LOAD\_PUZZLE.e}
\begin{lstlisting}
indexing
	description: "load the state of a puzzle saved before in a .puz file."
	author: "Markus Neidhart and UC Team"
	date: "$Date: 2005/06/20 13:51:31 $"
	revision: "$Revision: 1.3 $"

class
	UC_LOAD_PUZZLE

inherit
	SHARED_QUAD_CUTTER

create
	make


feature -- creation

	make (a_filename: STRING) is
			-- load a .puz file and return a puzzle_start_window
		require
			a_filename_not_Void: a_filename /= Void
	
		
feature  -- Implementation

	read_file: PUZZLE_START_WINDOW is
			-- read `file' in and create a puzzle_start_window
	
		
feature {NONE} -- Access

	file: PLAIN_TEXT_FILE


invariant
	file_not_Void: file /= Void
	

end -- class UC_SAVE_PUZZLE
\end{lstlisting}
\vspace*{1cm}

\subsection{UC\_SAVE\_PUZZLE.e}
\begin{lstlisting}
indexing
	description: "save the state of the current puzzle to an .puz file. later, you can load this file and resume the game"
	author: "Markus Neidhart and UC Team"
	date: "$Date: 2005/06/20 13:51:31 $"
	revision: "$Revision: 1.3 $"

class
	UC_SAVE_PUZZLE

inherit
	SHARED_QUAD_CUTTER

create
	make


feature -- creation

	make (a_filename: STRING; situation: PUZZLE_START_WINDOW) is
			-- make an .puz file from `a_filename'
		require
			a_filename_not_Void_and_not_empty: a_filename /= Void and then not a_filename.is_empty
			situation_not_Void: situation /= Void
		
		
feature {NONE} -- Implementation

	save_information (name: STRING; sit: PUZZLE_START_WINDOW) is
			-- store the information in the puz file
		require
			name_not_Void_and_not_empty: name /= Void and then not name.is_empty
			sit_not_Void: sit /= Void

		
feature {NONE} -- Access

	file: PLAIN_TEXT_FILE


end -- class UC_SAVE_PUZZLE
\end{lstlisting}
\vspace*{1cm}

\subsection{UC\_SHARED\_ITEMS.e}
\begin{lstlisting}
indexing
	description: " Shared access to functions used by UC, extends the class ESDL_SHARED_BITMAP_FACTORY"
	author: "Markus Neidhart, nemarkus@student.ethz.ch"
	date: "$Date: 2005/06/20 13:51:31 $"
	revision: "$Revision: 1.3 $"
	
class 
	UC_SHARED_ITEMS

inherit
	ESDL_SHARED_BITMAP_FACTORY	
		export
			{NONE} all
		undefine
			default_create
		end

	SHARED_QUAD_CUTTER
		export
			{NONE} all
		end


feature  -- Singleton Access

	player: MUSIC_PLAYER is
		-- Sound object which plays sound
	once
		create Result.make
	ensure
    		sound_not_void: Result /= Void
	end


feature -- Colors

		uc_background_color: ESDL_COLOR is
				-- background color
			once
				Result := create {ESDL_COLOR}.make_with_rgb (255,204,0)
			end

		uc_light_color: ESDL_COLOR is
				-- light color
			once
				Result := create {ESDL_COLOR}.make_with_rgb (255,239,186)
			end

		uc_default_button_active_color: ESDL_COLOR is
				-- default active button color
			once
				Result := create {ESDL_COLOR}.make_with_rgb (194,40,0)
			end

		uc_default_button_normal_color: ESDL_COLOR is
				-- default normal button color
			once
				Result := create {ESDL_COLOR}.make_with_rgb (255,204,0)
			end

		uc_default_button_prelight_color: ESDL_COLOR is
				-- default prelight button color
			once
				Result := create {ESDL_COLOR}.make_with_rgb (255,53,0)
			end

		uc_default_button_highlight_color: ESDL_COLOR is
				-- default highlight button color
			once
				Result := create {ESDL_COLOR}.make_with_rgb (255,239,186)
			end
			
		uc_default_button_border_color: ESDL_COLOR is
				-- default button-border color
			once
				Result := create {ESDL_COLOR}.make_black
			end


feature -- font
		uc_gui_elements_default_font : ESDL_FONT is
				-- default font for the gui_elements
			once
				bitmap_factory.create_bitmap_from_image ("./image/default_font.png")
				check
					todo_proper_error_handling: bitmap_factory.last_bitmap /= Void
				end
				Result := create {ESDL_BITMAPFONT}.make (bitmap_factory.last_bitmap)
			end


feature -- Constants
		
		width: INTEGER is 1024
			-- The width of the screen

		height: INTEGER is 768	
			-- The height of the screen

		resolution: INTEGER is 32
			-- The resolution of the scene			


end
\end{lstlisting}
