Changeset 4892


Ignore:
Timestamp:
2014-06-06 12:26:44 (9 years ago)
Author:
sieerinn
Message:
 
Location:
2014/23/LeoL/PerusPeli1/PerusPeli1
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • 2014/23/LeoL/PerusPeli1/PerusPeli1/PerusPeli1/PerusPeli1.cs

    r4882 r4892  
    99public class PerusPeli1 : Game 
    1010{ 
    11  
    1211    enum Talotyyppi 
    1312    { 
     
    3635    static readonly Image castleRakentaaImage = LoadImage("Buildings\\castleBuildingImage"); 
    3736 
     37    List<PushButton> painonapit = new List<PushButton>(); 
     38    Dictionary<Talotyyppi, IntMeter> talolaskurit = new Dictionary<Talotyyppi, IntMeter>(); 
     39    Dictionary<int, Dictionary<Talotyyppi, int>> kenttaTavoitteet = new Dictionary<int, Dictionary<Talotyyppi, int>>(); 
     40    Label menuHelperNaytto; 
     41 
    3842    public override void Begin() 
    3943    { 
     
    4246        // Kirjoita ohjelmakoodisi tähän 
    4347        SetWindowSize(800, 600); 
     48        MultiSelectWindow alkuValikko = new MultiSelectWindow("Pelin alkuvalikko","Aloita peli", "Lopeta"); 
     49        alkuValikko.AddItemHandler(0, AloitaPeli); 
     50        alkuValikko.AddItemHandler(1, Exit); 
     51        Add(alkuValikko); 
     52 
     53        Level.Background.Image = taustaKuva; 
     54        MediaPlayer.Play("menutaustamusiikki"); 
     55        MediaPlayer.IsRepeating = true; 
     56       
     57    } 
     58 
     59    public void AloitaPeli() 
     60    { 
    4461        LuoKentta(); 
     62        LuoTavoitteet(); 
    4563        LuoMenu(); 
    4664        LuoRahalaskuri(); 
     
    5270    } 
    5371 
     72    private void LuoTavoitteet() 
     73    { 
     74        kenttaTavoitteet.Add(0, new Dictionary<Talotyyppi, int>() 
     75        { 
     76            {Talotyyppi.Castle, 1}, 
     77            {Talotyyppi.Stronghold, 2}, 
     78            {Talotyyppi.Fortress, 4}, 
     79            {Talotyyppi.Keep, 8}, 
     80            {Talotyyppi.House, 16} 
     81        }); 
     82    } 
     83 
    5484    void LuoMenu() 
    5585    { 
     86        menuHelperNaytto = new Label(""); 
     87        menuHelperNaytto.XMargin = 7.0; 
     88        menuHelperNaytto.YMargin = 7.0; 
     89        menuHelperNaytto.Color = new Color(0, 0, 0, 100); 
     90        menuHelperNaytto.TextColor = Color.White; 
     91        menuHelperNaytto.IsVisible = false; 
     92        Add(menuHelperNaytto); 
     93 
    5694        for (int i = 0; i < Enum.GetNames(typeof(Talotyyppi)).Length; i++) 
    5795        { 
    58             Label l = new Label((Talotyyppi)i + "\n0"); 
    59             l.Left = Level.Left + i * 150+ 50; 
     96            IntMeter laskuri = new IntMeter(0, 0, int.MaxValue); 
     97            talolaskurit.Add((Talotyyppi)i, laskuri); 
     98            laskuri.Changed += delegate { 
     99                foreach (var kv in talolaskurit) 
     100                { 
     101                    if (kv.Value.Value < kenttaTavoitteet[0][kv.Key]) 
     102                    { 
     103                        return; 
     104                    } 
     105                } 
     106                Label l = new Label("TAVOITTEET SAAVUTETTU. LOL XD."); 
     107                Add(l); 
     108                l.Color = new Color(0, 0, 0, 100); 
     109                l.TextColor = Color.White; 
     110            }; 
     111        } 
     112 
     113        for (int i = 0; i < Enum.GetNames(typeof(Talotyyppi)).Length; i++) 
     114        { 
     115            Label l = new Label(); 
     116            l.XMargin = 7.0; 
     117            l.YMargin = 7.0; 
     118            l.IntFormatString = "" + (Talotyyppi)i + "\n{0:D1}" + " / " + kenttaTavoitteet[0][(Talotyyppi)i]; 
     119            l.Color = new Color(0, 0, 0, 100); 
     120            l.TextColor = Color.White; 
     121            l.Left = Level.Left + i * 150 + 50; 
    60122            l.Bottom = Level.Bottom + 20; 
     123            l.BindTo(talolaskurit[(Talotyyppi)i]); 
    61124            Add(l); 
    62125        } 
     126 
     127 
     128 
    63129    } 
    64130 
     
    68134        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 
    69135        Mouse.Listen(MouseButton.Left, ButtonState.Pressed, HiirtaPainettu, null); 
     136        Mouse.ListenMovement(1.0, delegate {  
     137            if (painonapit.TrueForAll((nappi) => !Mouse.IsCursorOn(nappi)))  
     138                    menuHelperNaytto.IsVisible = false;  
     139        }, null); 
    70140    } 
    71141 
     
    73143    { 
    74144        if (ollaanRakentamassa) ollaanRakentamassa = false; 
    75  
    76         #region vanha 
    77         /* 
    78         else if (Mouse.IsCursorOn(rakennusMenu)) 
    79         { 
    80             if (pisteLaskuri.Value >= 5) 
    81             { 
    82                 pisteLaskuri.Value -= 5; 
    83                 hiirellaSeuraaja = true; 
    84                 AnnaRakennus(60, 60, LoadImage("Buildings\\houseBuildingImage")); 
    85             } 
    86         } 
    87         else if (Mouse.IsCursorOn(keepMenu)) 
    88         { 
    89             if (pisteLaskuri.Value >= 10) 
    90             { 
    91                 pisteLaskuri.Value -= 10; 
    92                 hiirellaSeuraaja = true; 
    93                 AnnaRakennus(90, 90, LoadImage("Buildings\\keepBuildingImage")); 
    94             } 
    95         } 
    96         else if (Mouse.IsCursorOn(fortMenu)) 
    97         { 
    98             if (pisteLaskuri.Value >= 20) 
    99             { 
    100                 pisteLaskuri.Value -= 20; 
    101                 hiirellaSeuraaja = true; 
    102                 AnnaRakennus(90, 90, LoadImage("Buildings\\fortBuildingImage")); 
    103             } 
    104         } 
    105         else if (Mouse.IsCursorOn(strongholdMenu)) 
    106         { 
    107             if (pisteLaskuri.Value >= 40) 
    108             { 
    109                 pisteLaskuri.Value -= 40; 
    110                 hiirellaSeuraaja = true; 
    111                 AnnaRakennus(120, 120, LoadImage("Buildings\\strongholdBuildingImage")); 
    112             } 
    113         } 
    114         else if (Mouse.IsCursorOn(castleMenu)) 
    115         { 
    116             if (pisteLaskuri.Value >= 80) 
    117             { 
    118                 pisteLaskuri.Value -= 80; 
    119                 hiirellaSeuraaja = true; 
    120                 AnnaRakennus(160, 160, LoadImage("Buildings\\castleBuildingImage")); 
    121             } 
    122         } 
    123          * */ 
    124         #endregion 
    125145    } 
    126146 
     
    128148    { 
    129149        if (ollaanRakentamassa) return; 
    130         if (hinta > rahalaskuri.Value) { MessageDisplay.Add("Ei tarpeeksi rahaa!"); return; } 
     150        if (hinta > rahalaskuri.Value) { MessageDisplay.Add("Ei tarpeeksi kultaa!"); return; } 
    131151        rahalaskuri.Value -= hinta; 
    132152 
     
    138158        seurattava = talo; 
    139159        Add(talo, 3); 
    140         rakennetutTalot.Add(talotyyppi); 
    141  
    142  
    143  
     160        //rakennetutTalot.Add(talotyyppi); 
     161        talolaskurit[talotyyppi].Value++; 
    144162    } 
    145163 
     
    152170        MediaPlayer.Play("taustamusiikki"); 
    153171        MediaPlayer.IsRepeating = true; 
    154         ruudut.SetTileMethod<String, Action>(Color.Black, LuoPainike, "Images\\houseImage", () => AnnaRakennus(leveys: 60, korkeus: 60, hinta: 5, kuva: houseRakentaaKuva, talotyyppi: Talotyyppi.House)); 
    155         ruudut.SetTileMethod<String, Action>(Color.Red, LuoPainike, "Images\\keepImage", () => AnnaRakennus(leveys: 90, korkeus: 90, hinta: 10, kuva: keepRakentaaKuva, talotyyppi: Talotyyppi.Keep)); 
    156         ruudut.SetTileMethod<String, Action>(new Color(255, 216, 0), LuoPainike, "Images\\fortImage", () => AnnaRakennus(leveys: 90, korkeus: 90, hinta: 20, kuva: fortRakentaaKuva, talotyyppi: Talotyyppi.Fortress)); 
    157         ruudut.SetTileMethod<String, Action>(new Color(0, 38, 255), LuoPainike, "Images\\strongholdImage", () => AnnaRakennus(leveys: 120, korkeus: 120, hinta: 40, kuva: strongholdRakentaaKuva, talotyyppi: Talotyyppi.Stronghold)); 
    158         ruudut.SetTileMethod<String, Action>(new Color(0, 255, 33), LuoPainike, "Images\\castleImage", () => AnnaRakennus(leveys: 160, korkeus: 160, hinta: 80, kuva: castleRakentaaImage, talotyyppi: Talotyyppi.Castle)); 
     172        ruudut.SetTileMethod(Color.Black, delegate(Vector paikka, double leveys, double korkeus) { LuoPainike(paikka, leveys, korkeus, "Images\\houseImage", houseRakentaaKuva, Talotyyppi.House, 5, 60); }); 
     173        ruudut.SetTileMethod(Color.Red, delegate(Vector paikka, double leveys, double korkeus) { LuoPainike(paikka, leveys, korkeus, "Images\\keepImage", keepRakentaaKuva, Talotyyppi.Keep, 10, 90); }); 
     174        ruudut.SetTileMethod(new Color(255, 216, 0), delegate(Vector paikka, double leveys, double korkeus) { LuoPainike(paikka, leveys, korkeus, "Images\\fortImage", fortRakentaaKuva, Talotyyppi.Fortress, 20, 90); }); 
     175        ruudut.SetTileMethod(new Color(0, 38, 255), delegate(Vector paikka, double leveys, double korkeus) { LuoPainike(paikka, leveys, korkeus, "Images\\strongholdImage", strongholdRakentaaKuva, Talotyyppi.Stronghold, 40, 90); }); 
     176        ruudut.SetTileMethod(new Color(0, 255, 33), delegate(Vector paikka, double leveys, double korkeus) { LuoPainike(paikka, leveys, korkeus, "Images\\castleImage", castleRakentaaImage, Talotyyppi.Castle, 80, 160); }); 
    159177        ruudut.Execute(25, 25); 
    160178        Level.CreateBorders(); 
     
    162180    } 
    163181 
    164     void LuoPainike(Vector paikka, double leveys, double korkeus, String kuva, Action toiminto) 
    165     { 
    166         PushButton menuNappi = new PushButton(leveys, korkeus, LoadImage(kuva)); 
     182    void LuoPainike(Vector paikka, double leveys, double korkeus, String nappikuva, Image rakennusKuva, Talotyyppi talotyyppi, int hinta, int rakennusKoko) 
     183    { 
     184        PushButton menuNappi = new PushButton(leveys, korkeus, LoadImage(nappikuva)); 
    167185        menuNappi.Position = paikka; 
    168         menuNappi.Clicked += toiminto; 
     186        menuNappi.Clicked += new Action(() => AnnaRakennus(rakennusKoko, rakennusKoko, hinta, rakennusKuva, talotyyppi)); 
    169187        Add(menuNappi); 
     188        painonapit.Add(menuNappi); 
     189        Mouse.ListenMovement(1.0, delegate 
     190        { 
     191            if (Mouse.IsCursorOn(menuNappi)) 
     192            { 
     193                menuHelperNaytto.IsVisible = true; 
     194                menuHelperNaytto.Text = talotyyppi + ", " + hinta + " kultaa"; 
     195                menuHelperNaytto.Position = Mouse.PositionOnWorld + new Vector(menuHelperNaytto.Width / 2 + 10, 0); 
     196            } 
     197        }, null 
     198            ); 
    170199    } 
    171200 
     
    241270    void LuoRahalaskuri() 
    242271    { 
    243         rahalaskuri = new IntMeter(0); 
     272        rahalaskuri = new IntMeter(0, 0, int.MaxValue); 
    244273 
    245274        Label rahanaytto = new Label(); 
    246275        rahanaytto.X = Screen.Right - 70; 
    247276        rahanaytto.Y = Screen.Top - 20; 
    248         rahanaytto.TextColor = Color.Black; 
    249         rahanaytto.Color = Color.Gray; 
     277        rahanaytto.TextColor = Color.White; 
     278        rahanaytto.Color = new Color(0, 0, 0, 100); 
     279        rahanaytto.XMargin = 7.0; 
     280        rahanaytto.YMargin = 7.0; 
    250281        rahanaytto.BindTo(rahalaskuri); 
     282        rahanaytto.IntFormatString = "Kultaa: {0:D1}"; 
    251283        Add(rahanaytto); 
    252284 
  • 2014/23/LeoL/PerusPeli1/PerusPeli1/PerusPeli1Content/PerusPeli1Content.contentproj

    r4882 r4892  
    134134    </Compile> 
    135135  </ItemGroup> 
     136  <ItemGroup> 
     137    <Compile Include="menutaustamusiikki.mp3"> 
     138      <Name>menutaustamusiikki</Name> 
     139      <Importer>Mp3Importer</Importer> 
     140      <Processor>SongProcessor</Processor> 
     141    </Compile> 
     142  </ItemGroup> 
    136143  <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 
    137144  <!--  To modify your build process, add your task inside one of the targets below and uncomment it.  
Note: See TracChangeset for help on using the changeset viewer.