Changeset 2362 for 2011/26


Ignore:
Timestamp:
2011-06-30 14:20:12 (12 years ago)
Author:
jumakall
Message:
 
Location:
2011/26/JuhoK/SFN
Files:
3 edited

Legend:

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

    r2353 r2362  
    1212        public int moottori = 0; 
    1313        public int renkaat = 0; 
    14         public int korinhinta = 0; 
    1514 
    16         public Auto(string korinnimi, int korinhinta, int kori, int moottori, int renkaat) 
     15        public Auto(string korinnimi, int kori, int moottori, int renkaat) 
    1716        { 
    1817            this.korinnimi = korinnimi; 
     
    2019            this.moottori = moottori; 
    2120            this.renkaat = renkaat; 
    22             this.korinhinta = korinhinta; 
    2321        } 
    2422    } 
  • 2011/26/JuhoK/SFN/SFN/SFN/Peli.cs

    r2353 r2362  
    1111{ 
    1212    public class Peli : PhysicsGame 
    13     {        List<Auto> autot = new List<Auto>(); 
     13    {         
     14        List<Auto> autot = new List<Auto>(); 
    1415        List<Image> kuvat = new List<Image>(); 
     16        List<int> hinnat = new List<int>(); 
     17        String[] mallit = new String[4]; 
     18        Label[] autokuvat = new Label[4]; 
    1519        int ID = 0, max_taso = 20; 
    1620        double raha = 5000; 
     
    1923        Image kuva = LoadImage("Blues\\Perus1"); 
    2024        Label number, malli, moottori, renkaat, moottorin_hinta, renkaiden_hinta, sell_price, rahat; 
    21         Label auto1, auto2, auto3, auto4; 
    22         PushButton osta_auto1, osta_auto2, osta_auto3, osta_auto4; 
     25         
    2326        int ChangeColor; 
    2427 
    2528        public override void Begin() 
    2629        { 
     30            hinnat.Add(5000); 
     31            hinnat.Add(10000); 
     32            hinnat.Add(15000); 
     33            hinnat.Add(20000); 
     34 
     35            mallit[0] = "Model0"; 
     36            mallit[1] = "Model1"; 
     37            mallit[2] = "Model2"; 
     38            mallit[3] = "Model3"; 
     39 
    2740            for (int i = 0; i < 4; i += 1) 
    2841            { 
     
    3447            } 
    3548 
    36             autot.Add(new Auto("Model1", 15000, 1, 4, 5)); 
    37             autot.Add(new Auto("Model3", 17500, 3, 9, 1)); 
    38             autot.Add(new Auto("Model2", 20000, 2, 9, 3)); 
     49            autot.Add(new Auto("Model1", 1, 4, 5)); 
     50            autot.Add(new Auto("Model3", 3, 9, 1)); 
     51            autot.Add(new Auto("Model2", 2, 9, 3)); 
    3952            Keyboard.Listen(Key.Escape, ButtonState.Released, Exit, null); 
    4053            Mouse.IsCursorVisible = true; 
     
    154167            Add(rahat); 
    155168 
    156             double hinta =(10000 + (autot[ID].kori * 100) * 0.75) + ((autot[ID].moottori * 100) / 2) + ((autot[ID].renkaat * 100) / 2); 
     169            double hinta = (hinnat[autot[ID].kori] * 0.75) + ((autot[ID].moottori * 100) / 2) + ((autot[ID].renkaat * 100) / 2); 
    157170            sell_price = new Label("Sell price: " + hinta); 
    158171            sell_price.Position = new Vector(oikeareuna.X, Screen.Bottom * 0.28); 
     
    212225            Add(valkoinen); 
    213226 
     227             
    214228 
    215229            double kerroin = 0.85; 
     
    217231            for (int i = 0; i < 4; i++) 
    218232            { 
    219                 Label autokuva = new Label(40, 20); 
    220                 autokuva.Image = kuvat[i + kuvaindeksilaskuri]; 
    221                 autokuva.Position = new Vector(Screen.Left * kerroin, alapalkki.Y + alapalkki.Height * 0.2); 
    222                 Add(autokuva); 
     233                autokuvat[i] = new Label(40, 20); 
     234                autokuvat[i].Image = kuvat[0 + kuvaindeksilaskuri]; 
     235                autokuvat[i].Position = new Vector(Screen.Left * kerroin, alapalkki.Y + alapalkki.Height * 0.2); 
     236                Add(autokuvat[i]); 
     237                 
     238                PushButton nappi = new PushButton("Buy " + i); 
     239                nappi.Position = new Vector(Screen.Left * kerroin, alapalkki.Y - alapalkki.Height * 0.2); 
     240                int temp = i; 
     241                nappi.Clicked += new Action(delegate { Osta(temp);});     
     242                Add(nappi); 
     243 
     244                Label teksti = new Label("Price: "+hinnat[i].ToString()); 
     245                teksti.Position = new Vector(Screen.Left * kerroin, alapalkki.Y - alapalkki.Height * 0.05); 
     246                Add(teksti); 
     247 
    223248                kuvaindeksilaskuri += 5; 
    224             } 
    225  
    226             auto1 = new Label(40, 20); 
    227             auto1.Position = new Vector(Screen.Left * 0.85, alapalkki.Y + alapalkki.Height * 0.20); 
    228             auto1.Image = kuvat[0]; 
    229             Add(auto1); 
    230  
    231             auto2 = new Label(40, 20); 
    232             auto2.Position = new Vector(Screen.Left * 0.55, alapalkki.Y + alapalkki.Height * 0.20); 
    233             auto2.Image = kuvat[5]; 
    234             Add(auto2); 
    235  
    236             auto3 = new Label(40, 20); 
    237             auto3.Position = new Vector(Screen.Left * 0.25, alapalkki.Y + alapalkki.Height * 0.20); 
    238             auto3.Image = kuvat[10]; 
    239             Add(auto3); 
    240  
    241             auto4 = new Label(40, 20); 
    242             auto4.Position = new Vector(Screen.Left * -0.05, alapalkki.Y + alapalkki.Height * 0.20); 
    243             auto4.Image = kuvat[15]; 
    244             Add(auto4); 
    245  
    246             Label[] osta_auto_buttons = new Label[4]; 
    247             kerroin = 0.85; 
    248  
    249             for (int i = 0; i < osta_auto_buttons.Length; i++) 
    250                         { 
    251                 osta_auto_buttons[i] = new PushButton("Buy"); 
    252                 osta_auto_buttons[i].Position = new Vector(Screen.Left * kerroin, alapalkki.Y - alapalkki.Height * 0.2); 
    253                 Add(osta_auto_buttons[i]); 
    254249                kerroin -= 0.3; 
    255                         } 
    256  
    257             /*osta_auto1 = new PushButton("Osta"); 
    258             osta_auto1.Position = new Vector(Screen.Left * 0.85, alapalkki.Y - alapalkki.Height * 0.20); 
    259             Add(osta_auto1); 
    260  
    261             osta_auto2 = new PushButton("Osta"); 
    262             osta_auto2.Position = new Vector(Screen.Left * 0.55, alapalkki.Y - alapalkki.Height * 0.20); 
    263             Add(osta_auto2); 
    264  
    265             osta_auto3 = new PushButton("Osta"); 
    266             osta_auto3.Position = new Vector(Screen.Left * 0.25, alapalkki.Y - alapalkki.Height * 0.20); 
    267             Add(osta_auto3); 
    268  
    269             osta_auto4 = new PushButton("Osta"); 
    270             osta_auto4.Position = new Vector(Screen.Left * -0.05, alapalkki.Y - alapalkki.Height * 0.20); 
    271             Add(osta_auto4);*/ 
    272  
    273             /*Label[] laabelit = new Label[4]; 
    274             double kerroin = 0.85; 
    275             for (int i = 0; i < laabelit.Length; i++) 
    276             { 
    277                 String hintaTuhatErottimella = autot[i].korinhinta.ToString("0,0", CultureInfo.InvariantCulture); 
    278                 laabelit[i] = new Label("Price: " + hintaTuhatErottimella); 
    279                 laabelit[i].Position = new Vector(Screen.Left * kerroin, alapalkki.Y - alapalkki.Height * 0.05); 
    280                 Add(laabelit[i]); 
    281                 kerroin -= 0.3; 
    282             } */ 
    283  
    284             // Lisätään hintaan tuhaterotin 
    285             //int _hinta = (10000 + (0 * 100)); 
    286              
    287  
    288             /*Label hinta_auto1 = new Label("Price: "+hintaTuhatErottimella); 
    289             hinta_auto1.Position = new Vector(Screen.Left * 0.85, alapalkki.Y - alapalkki.Height * 0.05); 
    290             Add(hinta_auto1); 
    291  
    292             _hinta = int.Parse((10000 + (1 * 100)).ToString()); 
    293             hintaTuhatErottimella = _hinta.ToString("0,0", CultureInfo.InvariantCulture); 
    294             Label hinta_auto2 = new Label("Price: "+hintaTuhatErottimella); 
    295             hinta_auto2.Position = new Vector(Screen.Left * 0.55, alapalkki.Y - alapalkki.Height * 0.05); 
    296             Add(hinta_auto2); 
    297  
    298             _hinta = int.Parse((20000 + (2 * 100)).ToString()); 
    299             hintaTuhatErottimella = _hinta.ToString("0,0", CultureInfo.InvariantCulture); 
    300             Label hinta_auto3 = new Label("Price: "+hintaTuhatErottimella); 
    301             hinta_auto3.Position = new Vector(Screen.Left * 0.25, alapalkki.Y - alapalkki.Height * 0.05); 
    302             Add(hinta_auto3); 
    303  
    304             _hinta = int.Parse((20000 + (3 * 100)).ToString()); 
    305             hintaTuhatErottimella = _hinta.ToString("0,0", CultureInfo.InvariantCulture); 
    306             Label hinta_auto4 = new Label("Price: "+hintaTuhatErottimella); 
    307             hinta_auto4.Position = new Vector(Screen.Left * -0.05, alapalkki.Y - alapalkki.Height * 0.05); 
    308             Add(hinta_auto4);*/ 
     250            } 
     251 
     252        } 
     253 
     254        void Osta(int indeksi) 
     255        { 
     256            if (raha >= hinnat[indeksi]) 
     257            { 
     258                raha -= hinnat[indeksi]; 
     259                autot.Add(new Auto(mallit[indeksi], indeksi, 1, 1)); 
     260                ID = autot.Count - 1; 
     261                UpdateHUD(); 
     262            } 
     263            else 
     264            { 
     265                MessageDisplay.Add("No enought money."); 
     266            } 
    309267        } 
    310268 
     
    346304        void ChangeCarColor() 
    347305        { 
    348             auto1.Image = kuvat[ChangeColor]; 
    349             auto2.Image = kuvat[ChangeColor + 5]; 
    350             auto3.Image = kuvat[ChangeColor + 10]; 
    351             auto4.Image = kuvat[ChangeColor + 15]; 
     306            autokuvat[0].Image = kuvat[ChangeColor]; 
     307            autokuvat[1].Image = kuvat[ChangeColor + 5]; 
     308            autokuvat[2].Image = kuvat[ChangeColor + 10]; 
     309            autokuvat[3].Image = kuvat[ChangeColor + 15]; 
    352310        } 
    353311 
     
    356314            if (autot.Count > 1) 
    357315            { 
    358                 double hinta = (10000 + (autot[ID].kori * 100) * 0.75) + ((autot[ID].moottori * 100) / 2) + ((autot[ID].renkaat * 100) / 2); 
     316                double hinta = (hinnat[autot[ID].kori] * 0.75) + ((autot[ID].moottori * 100) / 2) + ((autot[ID].renkaat * 100) / 2); 
    359317                autot.RemoveAt(ID); 
    360318                raha = raha + hinta; 
     
    426384        void UpdateHUD() 
    427385        { 
    428             double hinta = (10000 + (autot[ID].kori * 100) * 0.75) + ((autot[ID].moottori * 100) / 2) + ((autot[ID].renkaat * 100) / 2); 
     386            double hinta = (hinnat[autot[ID].kori] * 0.75) + ((autot[ID].moottori * 100) / 2) + ((autot[ID].renkaat * 100) / 2); 
    429387            sell_price.Text = "Sell price: " + hinta.ToString(); 
    430388            malli.Text = autot[ID].korinnimi.ToString(); 
     
    434392            moottorin_hinta.Text = "Price: " + (autot[ID].moottori * 100).ToString(); 
    435393            renkaiden_hinta.Text = "Price: " + (autot[ID].renkaat * 100).ToString(); 
     394            rahat.Text = "Money: " + raha.ToString(); 
    436395        } 
    437396    } 
Note: See TracChangeset for help on using the changeset viewer.