Changeset 2284


Ignore:
Timestamp:
2011-06-29 13:32:00 (12 years ago)
Author:
jumakall
Message:

Safehousen auton tuunaus ja myymisominaisuudet (myös auton vaihtaminen) valmiit.

Location:
2011/26/JuhoK/SFN
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • 2011/26/JuhoK/SFN/SFN/SFN/Peli.cs

    r2262 r2284  
    1212    { 
    1313        List<Auto> autot = new List<Auto>(); 
    14         int ID = 0; 
     14        int ID = 0, max_taso = 20; 
     15        double raha = 5000; 
    1516 
    1617        Image MenuBackround = LoadImage("MenuBackround"); 
    17         Label number, malli, moottori, renkaat, moottorin_hinta, renkaiden_hinta; 
     18        Label number, malli, moottori, renkaat, moottorin_hinta, renkaiden_hinta, sell_price, rahat; 
    1819 
    1920        public override void Begin() 
     
    7071        { 
    7172            ClearAll(); 
     73            Keyboard.Listen(Key.Escape, ButtonState.Released, Exit, null); 
     74            Camera.ZoomToLevel(); 
     75            Level.BackgroundColor = Color.LightGray; 
    7276 
    7377            Label ylapalkki = new Label(Screen.Width, Screen.Height / 15); 
     
    8791            Add(oikeareuna); 
    8892 
    89             Keyboard.Listen(Key.Escape, ButtonState.Released, Exit, null); 
    90             Camera.ZoomToLevel(); 
    91             Level.BackgroundColor = Color.LightGray; 
    92  
    93             /*GameObject alapalkki = new GameObject(Level.Width, Level.Height / 4); 
    94             alapalkki.X = 0; 
    95             alapalkki.Y = Level.Bottom + alapalkki.Height / 2; 
    96             Add(alapalkki);*/ 
    97             /* 
    98             GameObject ylapalkki = new GameObject(Level.Width, Level.Height / 10); 
    99             ylapalkki.X = 0; 
    100             ylapalkki.Y = Level.Top - ylapalkki.Height / 2; 
    101             Add(ylapalkki); 
    102             */ 
    103             /*GameObject oikeareuna = new GameObject(Level.Width / 6, Level.Height); 
    104             oikeareuna.Position = new Vector(Level.Right - oikeareuna.Width / 2, 0); 
    105             Add(oikeareuna);*/ 
    10693 
    10794            //Next 
     
    118105 
    119106            PushButton update_engine = new PushButton("Update engine"); 
    120             update_engine.Position = new Vector(Level.Right + 65, Level.Top - 20); 
     107            update_engine.Position = new Vector(oikeareuna.X, Screen.Top * 0.75); 
    121108            update_engine.Clicked += new Action(update_engine_Clicked); 
    122109            Add(update_engine); 
    123110 
    124111            PushButton update_tiers = new PushButton("Update tiers"); 
    125             update_tiers.Position = new Vector(Level.Right + 65, Level.Top - 140); 
     112            update_tiers.Position = new Vector(oikeareuna.X, Screen.Top * 0.52); 
    126113            update_tiers.Clicked += new Action(update_tiers_Clicked); 
    127114            Add(update_tiers); 
     115 
     116            PushButton drive = new PushButton("Leave safehouse"); 
     117            drive.Position = new Vector(oikeareuna.X, Screen.Bottom * 0.4);  
     118            Add(drive); 
     119 
     120            PushButton sell = new PushButton("Sell car"); 
     121            sell.Position = new Vector(oikeareuna.X, Screen.Bottom * 0.2); 
     122            sell.Clicked += new Action(sell_Clicked); 
     123            Add(sell); 
    128124 
    129125            //Number 
     
    133129 
    134130            malli = new Label(autot[ID].korinnimi.ToString()); 
    135             malli.Position = new Vector(Level.Left, ylapalkki.Y); //Level.Left, Level.Top + 60 
     131            malli.Position = new Vector(Screen.Left * 0.9, ylapalkki.Y); //Level.Left, Level.Top + 60 
    136132            Add(malli); 
    137133 
    138             moottori = new Label("Moottori: " + autot[ID].moottori.ToString()); 
    139             moottori.Position = new Vector(Level.Left + 250, ylapalkki.Y); //Level.Left + 250, Level.Top * 1.2 
     134            moottori = new Label("Engine: " + autot[ID].moottori.ToString()); 
     135            moottori.Position = new Vector(Screen.Left * 0.5, ylapalkki.Y); //Level.Left + 250, Level.Top * 1.2 
    140136            Add(moottori); 
    141137 
    142  
    143             renkaat = new Label("Renkaat: "+autot[ID].renkaat.ToString()); 
    144             renkaat.Position = new Vector(0, ylapalkki.Y); 
     138            rahat = new Label("Money: "+raha.ToString()); 
     139            rahat.Position = new Vector(oikeareuna.X, 0); 
     140            Add(rahat); 
     141 
     142            double hinta =(10000 + (autot[ID].kori * 100) * 0.75) + ((autot[ID].moottori * 100) / 2) + ((autot[ID].renkaat * 100) / 2); 
     143            sell_price = new Label("Sell price: " + hinta); 
     144            sell_price.Position = new Vector(oikeareuna.X, Screen.Bottom * 0.28); 
     145            Add(sell_price); 
     146             
     147 
     148            renkaat = new Label("Tiers: "+autot[ID].renkaat.ToString()); 
     149            renkaat.Position = new Vector(Screen.Left * 0.05, ylapalkki.Y); 
    145150            //renkaat.Y = ylapalkki.Y; 
    146151            //ylapalkki.Y = 200 - ylapalkki.Height/2; 
     
    148153            Add(renkaat); 
    149154 
    150             moottorin_hinta = new Label("Hinta: " + (autot[ID].moottori * 100).ToString()); 
    151             moottorin_hinta.Position = new Vector(Level.Right + 65, Level.Top - 60); 
     155            moottorin_hinta = new Label("Price: " + (autot[ID].moottori * 100).ToString()); 
     156            moottorin_hinta.Position = new Vector(oikeareuna.X, Screen.Top * 0.65); 
    152157            Add(moottorin_hinta); 
    153158 
    154             renkaiden_hinta = new Label("Hinta: " + (autot[ID].renkaat * 100).ToString()); 
    155             renkaiden_hinta.Position = new Vector(Level.Right + 65, Level.Top - 180); 
     159            renkaiden_hinta = new Label("Price: " + (autot[ID].renkaat * 100).ToString()); 
     160            renkaiden_hinta.Position = new Vector(oikeareuna.X, Screen.Top * 0.4); 
    156161            Add(renkaiden_hinta); 
    157162             
    158163        } 
    159164 
     165        void sell_Clicked() 
     166        { 
     167            if (autot.Count > 1) 
     168            { 
     169                double hinta = (10000 + (autot[ID].kori * 100) * 0.75) + ((autot[ID].moottori * 100) / 2) + ((autot[ID].renkaat * 100) / 2); 
     170                autot.RemoveAt(ID); 
     171                raha = raha + hinta; 
     172                ID = ++ID % autot.Count; 
     173                UpdateHUD(); 
     174            } 
     175            else 
     176            { 
     177                MessageDisplay.Add("Can't sell last car."); 
     178            } 
     179        } 
     180 
    160181        void update_tiers_Clicked() 
    161182        { 
    162             MessageDisplay.Add("Tiers updated."); 
    163             autot[ID].renkaat += 1; 
     183            int hinta = autot[ID].renkaat * 100; 
     184            if (raha >= hinta) 
     185            { 
     186                if (autot[ID].renkaat < max_taso) 
     187                { 
     188                    raha = raha - hinta; 
     189                    autot[ID].renkaat += 1; 
     190                } 
     191                else 
     192                { 
     193                    MessageDisplay.Add("Can't update engine."); 
     194                } 
     195            } 
     196            else 
     197            { 
     198                MessageDisplay.Add("No enought money."); 
     199            } 
    164200            UpdateHUD(); 
    165201        } 
     
    167203        void update_engine_Clicked() 
    168204        { 
    169             MessageDisplay.Add("Engine updated."); 
    170             autot[ID].moottori += 1; 
     205            int hinta = autot[ID].moottori * 100; 
     206            if (raha >= hinta) 
     207            { 
     208                if (autot[ID].moottori < max_taso) 
     209                { 
     210                    raha = raha - hinta; 
     211                    autot[ID].moottori += 1; 
     212                } 
     213                else 
     214                { 
     215                    MessageDisplay.Add("Can't update engine."); 
     216                } 
     217            } 
     218            else 
     219            { 
     220                MessageDisplay.Add("No enought money."); 
     221            } 
    171222            UpdateHUD(); 
    172223        } 
     
    186237        void UpdateHUD() 
    187238        { 
     239            double hinta = (10000 + (autot[ID].kori * 100) * 0.75) + ((autot[ID].moottori * 100) / 2) + ((autot[ID].renkaat * 100) / 2); 
     240            sell_price.Text = "Sell price: " + hinta.ToString(); 
    188241            malli.Text = autot[ID].korinnimi.ToString(); 
    189             moottori.Text = "Moottori: " + autot[ID].moottori.ToString(); 
    190             renkaat.Text = "Renkaat: " + autot[ID].renkaat.ToString(); 
     242            moottori.Text = "Engine: " + autot[ID].moottori.ToString(); 
     243            renkaat.Text = "Tiers: " + autot[ID].renkaat.ToString(); 
    191244            number.Text = (ID + 1).ToString() + "/" + autot.Count.ToString(); 
    192             moottorin_hinta.Text = "Hinta: " + (autot[ID].moottori * 100).ToString(); 
    193             renkaiden_hinta.Text = "Hinta: " + (autot[ID].renkaat * 100).ToString(); 
     245            moottorin_hinta.Text = "Price: " + (autot[ID].moottori * 100).ToString(); 
     246            renkaiden_hinta.Text = "Price: " + (autot[ID].renkaat * 100).ToString(); 
    194247        } 
    195248    } 
Note: See TracChangeset for help on using the changeset viewer.