Changeset 4892
- Timestamp:
- 2014-06-06 12:26:44 (9 years ago)
- 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 9 9 public class PerusPeli1 : Game 10 10 { 11 12 11 enum Talotyyppi 13 12 { … … 36 35 static readonly Image castleRakentaaImage = LoadImage("Buildings\\castleBuildingImage"); 37 36 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 38 42 public override void Begin() 39 43 { … … 42 46 // Kirjoita ohjelmakoodisi tähän 43 47 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 { 44 61 LuoKentta(); 62 LuoTavoitteet(); 45 63 LuoMenu(); 46 64 LuoRahalaskuri(); … … 52 70 } 53 71 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 54 84 void LuoMenu() 55 85 { 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 56 94 for (int i = 0; i < Enum.GetNames(typeof(Talotyyppi)).Length; i++) 57 95 { 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; 60 122 l.Bottom = Level.Bottom + 20; 123 l.BindTo(talolaskurit[(Talotyyppi)i]); 61 124 Add(l); 62 125 } 126 127 128 63 129 } 64 130 … … 68 134 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 69 135 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); 70 140 } 71 141 … … 73 143 { 74 144 if (ollaanRakentamassa) ollaanRakentamassa = false; 75 76 #region vanha77 /*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 #endregion125 145 } 126 146 … … 128 148 { 129 149 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; } 131 151 rahalaskuri.Value -= hinta; 132 152 … … 138 158 seurattava = talo; 139 159 Add(talo, 3); 140 rakennetutTalot.Add(talotyyppi); 141 142 143 160 //rakennetutTalot.Add(talotyyppi); 161 talolaskurit[talotyyppi].Value++; 144 162 } 145 163 … … 152 170 MediaPlayer.Play("taustamusiikki"); 153 171 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); }); 159 177 ruudut.Execute(25, 25); 160 178 Level.CreateBorders(); … … 162 180 } 163 181 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)); 167 185 menuNappi.Position = paikka; 168 menuNappi.Clicked += toiminto;186 menuNappi.Clicked += new Action(() => AnnaRakennus(rakennusKoko, rakennusKoko, hinta, rakennusKuva, talotyyppi)); 169 187 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 ); 170 199 } 171 200 … … 241 270 void LuoRahalaskuri() 242 271 { 243 rahalaskuri = new IntMeter(0 );272 rahalaskuri = new IntMeter(0, 0, int.MaxValue); 244 273 245 274 Label rahanaytto = new Label(); 246 275 rahanaytto.X = Screen.Right - 70; 247 276 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; 250 281 rahanaytto.BindTo(rahalaskuri); 282 rahanaytto.IntFormatString = "Kultaa: {0:D1}"; 251 283 Add(rahanaytto); 252 284 -
2014/23/LeoL/PerusPeli1/PerusPeli1/PerusPeli1Content/PerusPeli1Content.contentproj
r4882 r4892 134 134 </Compile> 135 135 </ItemGroup> 136 <ItemGroup> 137 <Compile Include="menutaustamusiikki.mp3"> 138 <Name>menutaustamusiikki</Name> 139 <Importer>Mp3Importer</Importer> 140 <Processor>SongProcessor</Processor> 141 </Compile> 142 </ItemGroup> 136 143 <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 137 144 <!-- 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.