~eda-qa/dhlib/main

« back to all changes in this revision

Viewing changes to app-sudoku/sudoku/Main.mhx

  • Committer: edA-qa mort-ora-y
  • Date: 2010-02-16 05:36:32 UTC
  • Revision ID: eda-qa@disemia.com-20100216053632-60lt7fndfi3fgblw
first

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* <license>
 
2
 * This file is part of the dis-Emi-A HaXe Library. Copyright © edA-qa mort-ora-y
 
3
 * For full copyright and license information please refer to doc/license.txt.
 
4
 * </license> 
 
5
 */
 
6
package sudoku;
 
7
 
 
8
import ui.Button;
 
9
import ui.Action;
 
10
 
 
11
/**
 
12
 * In such a Main class is where you put the title screen and
 
13
 * main menu for a game.
 
14
 *
 
15
 * In this game however we don't have much of a main panel
 
16
 * so we just add it alongside the in game menu.  This panel
 
17
 * is nonetheless setup and controlled here, the GameLayout
 
18
 * simply needs to stick it somewhere.
 
19
 */
 
20
class Main extends ui.StageLayout
 
21
{
 
22
        var gameLayout : GameLayout;
 
23
        
 
24
        var mainPanel : ui.LinearLayout;
 
25
        var tfDifficulty : ui.StaticText;
 
26
                
 
27
        public function new()
 
28
        {       
 
29
                super();
 
30
                MixinLayout();
 
31
                
 
32
                mainPanel = ui.LinearLayout.vertical();
 
33
                mainPanel.add( ui.StaticText.singleLine( "Game Options", 1.3 ) );
 
34
                mainPanel.add( Button.plain( Action.bind( newGame ), "New Game" ) );
 
35
                
 
36
                tfDifficulty = ui.StaticText.singleLine( "" );
 
37
                mainPanel.add( tfDifficulty );
 
38
                mainPanel.add( Button.plain( Action.bind1( alterDiff, 5 ), "Harder" ) );
 
39
                mainPanel.add( Button.plain( Action.bind1( alterDiff, -5 ), "Easier" ) );
 
40
                
 
41
                gameLayout = new GameLayout( mainPanel );
 
42
                layout.add( gameLayout, ui.SizeType.Fill( 0 ) );
 
43
                
 
44
                alterDiff( 0 );
 
45
        }
 
46
        
 
47
        function newGame()
 
48
        {
 
49
                gameLayout.startNew( Options.difficulty );
 
50
        }
 
51
        
 
52
        function alterDiff( step : Int )
 
53
        {
 
54
                Options.difficulty += step;
 
55
                if( Options.difficulty < 1 )
 
56
                        Options.difficulty = 1;
 
57
                if( Options.difficulty > (GConst.numCells-GConst.boardSize) )
 
58
                        Options.difficulty = GConst.numCells - GConst.boardSize;
 
59
                        
 
60
                tfDifficulty.text = "Difficulty: " + Options.difficulty;
 
61
                newGame();
 
62
        }
 
63
        
 
64
        public static function main()
 
65
        {
 
66
                ui.StageLayout.setup( Main );
 
67
        }
 
68
        
 
69
        define(`IsVerticalLayout',true)
 
70
        include(`ui/MixinLayout.ihx')
 
71
}
 
 
b'\\ No newline at end of file'