source: 2011/26/JuhoK/SFN/SFN/SFN/Peli.cs @ 2249

Revision 2249, 6.4 KB checked in by jumakall, 12 years ago (diff)
Line 
1using System;
2using System.Collections.Generic;
3using Jypeli;
4using Jypeli.Assets;
5using Jypeli.Controls;
6using Jypeli.Effects;
7using Jypeli.Widgets;
8
9namespace SFN
10{
11    public class Peli : PhysicsGame
12    {
13        List<Auto> autot = new List<Auto>();
14        int ID = 0;
15
16        Image MenuBackround = LoadImage("MenuBackround");
17        Label number, malli, moottori, renkaat, moottorin_hinta, renkaiden_hinta;
18
19        public override void Begin()
20        {
21            autot.Add(new Auto("Model1", 1, 4, 5));
22            autot.Add(new Auto("Model3", 3, 9, 1));
23            autot.Add(new Auto("Model2", 2, 9, 3));
24            Keyboard.Listen(Key.Escape, ButtonState.Released, Exit, null);
25            Mouse.IsCursorVisible = true;
26            CreateMenu();
27        }
28
29        void CreateMenu()
30        {
31            //Set menu backround
32            Level.Background.Image = MenuBackround;
33
34            //Quit game button
35            PushButton quit_game = new PushButton("Quit game");
36            quit_game.Clicked += new Action(quit_game_Clicked);
37            quit_game.Position = new Vector(380.0, -50.0);
38            Add(quit_game);
39
40            //Load game button
41            PushButton load_game = new PushButton("Load game");
42            //load_game.Clicked += new Action(load_game_Clicked);
43            load_game.Clicked += new Action(GoToShop);
44            load_game.Position = new Vector(200.0, -50.0);
45            Add(load_game);
46
47            //New game button
48            PushButton new_game = new PushButton("New game");
49            new_game.Clicked += new Action(new_game_Clicked);
50            new_game.Position = new Vector(20.0, -50.0);
51            Add(new_game);
52        }
53
54        void new_game_Clicked()
55        {
56            MessageDisplay.Add("Can't start new game. Game engine not availible.");
57        }
58
59        void load_game_Clicked()
60        {
61            MessageDisplay.Add("Can't load game. Game save system not availible.");
62        }
63
64        void quit_game_Clicked()
65        {
66            Exit();
67        }
68
69        void GoToShop()
70        {
71            ClearAll();
72            Keyboard.Listen(Key.Escape, ButtonState.Released, Exit, null);
73            Camera.ZoomToLevel();
74            Level.BackgroundColor = Color.LightGray;
75
76            GameObject alapalkki = new GameObject(Level.Width, Level.Height / 4);
77            alapalkki.X = 0;
78            alapalkki.Y = Level.Bottom + alapalkki.Height / 2;
79            Add(alapalkki);
80
81            GameObject ylapalkki = new GameObject(Level.Width, Level.Height / 10);
82            ylapalkki.X = 0;
83            ylapalkki.Y = Level.Top - ylapalkki.Height / 2;
84            Add(ylapalkki);
85
86            GameObject oikeareuna = new GameObject(Level.Width / 6, Level.Height);
87            oikeareuna.Position = new Vector(Level.Right - oikeareuna.Width / 2, 0);
88            Add(oikeareuna);
89
90            //Next
91            PushButton nextid = new PushButton("-->");
92            nextid.Position = new Vector(Level.Right * 1.15, Level.Top * 1.2); //Level.Right + 80, Level.Top + 60
93            nextid.Clicked += new Action(nextid_Clicked);
94            Add(nextid);
95
96            //Previous
97            PushButton previousid = new PushButton("<--");
98            previousid.Position = new Vector(Level.Right * 0.85, Level.Top * 1.2); //Level.Right - 80, Level.Top + 60
99            previousid.Clicked += new Action(previousid_Clicked);
100            Add(previousid);
101
102            PushButton update_engine = new PushButton("Update engine");
103            update_engine.Position = new Vector(Level.Right + 65, Level.Top - 20);
104            update_engine.Clicked += new Action(update_engine_Clicked);
105            Add(update_engine);
106
107            PushButton update_tiers = new PushButton("Update tiers");
108            update_tiers.Position = new Vector(Level.Right + 65, Level.Top - 140);
109            update_tiers.Clicked += new Action(update_tiers_Clicked);
110            Add(update_tiers);
111
112            //Number
113            number = new Label((ID+1).ToString()+"/"+autot.Count.ToString());
114            number.Position = new Vector(Level.Right, Level.Top * 1.2); //Level.Right, Level.Top + 60
115            Add(number);
116
117            malli = new Label(autot[ID].korinnimi.ToString());
118            malli.Position = new Vector(Level.Left, Level.Top * 1.2); //Level.Left, Level.Top + 60
119            Add(malli);
120
121            moottori = new Label("Moottori: " + autot[ID].moottori.ToString());
122            moottori.Position = new Vector(Level.Left + 250, Level.Top * 1.2); //Level.Left + 250, Level.Top * 1.2
123            Add(moottori);
124
125            renkaat = new Label("Renkaat: "+autot[ID].renkaat.ToString());
126            renkaat.Position = new Vector(Level.Left + 500, Level.Top * 1.2); //Level.Left + 500, Level.Top + 60
127            Add(renkaat);
128
129            moottorin_hinta = new Label("Hinta: " + (autot[ID].moottori * 100).ToString());
130            moottorin_hinta.Position = new Vector(Level.Right + 65, Level.Top - 60);
131            Add(moottorin_hinta);
132
133            renkaiden_hinta = new Label("Hinta: " + (autot[ID].renkaat * 100).ToString());
134            renkaiden_hinta.Position = new Vector(Level.Right + 65, Level.Top - 180);
135            Add(renkaiden_hinta);
136        }
137
138        void update_tiers_Clicked()
139        {
140            MessageDisplay.Add("Tiers updated.");
141            autot[ID].renkaat += 1;
142            UpdateHUD();
143        }
144
145        void update_engine_Clicked()
146        {
147            MessageDisplay.Add("Engine updated.");
148            autot[ID].moottori += 1;
149            UpdateHUD();
150        }
151
152        void previousid_Clicked()
153        {
154            //ID = --ID % autot.Count;
155            MessageDisplay.Add("You can't use this button, because it's are broken.");
156            UpdateHUD();
157        }
158
159        void nextid_Clicked()
160        {
161            ID = ++ID % autot.Count;
162            UpdateHUD();
163        }
164
165        void UpdateHUD()
166        {
167            malli.Text = autot[ID].korinnimi.ToString();
168            moottori.Text = "Moottori: " + autot[ID].moottori.ToString();
169            renkaat.Text = "Renkaat: " + autot[ID].renkaat.ToString();
170            number.Text = (ID + 1).ToString() + "/" + autot.Count.ToString();
171            moottorin_hinta.Text = "Hinta: " + (autot[ID].moottori * 100).ToString();
172            renkaiden_hinta.Text = "Hinta: " + (autot[ID].renkaat * 100).ToString();
173        }
174    }
175}
Note: See TracBrowser for help on using the repository browser.