1 | using System; |
---|
2 | using System.Collections.Generic; |
---|
3 | using Jypeli; |
---|
4 | using Jypeli.ScreenObjects; |
---|
5 | using Jypeli.Assets; |
---|
6 | |
---|
7 | public class Peli : Game |
---|
8 | { |
---|
9 | List<GameObject> kortit = new List<GameObject>(); |
---|
10 | double kortinLeveys = 80; |
---|
11 | double kortinKorkeus = 100; |
---|
12 | int korostettuKortti; |
---|
13 | |
---|
14 | public enum Suunta { Vasen, Oikea, Ylos, Alas } |
---|
15 | |
---|
16 | protected override void Begin() |
---|
17 | { |
---|
18 | TeeKortit(); |
---|
19 | AsetaNappaimet(); |
---|
20 | KortitRuudulle(kortit); |
---|
21 | ValitseEnsimmainen(); |
---|
22 | } |
---|
23 | |
---|
24 | void ValitseEnsimmainen() |
---|
25 | { |
---|
26 | KorostaKortti(kortit.Count / 2); |
---|
27 | korostettuKortti = kortit.Count / 2; |
---|
28 | } |
---|
29 | |
---|
30 | int KortinNumeronTarkistus(int kortinNro) |
---|
31 | { |
---|
32 | if (kortinNro < 0) |
---|
33 | { |
---|
34 | kortinNro = kortit.Count - 1; |
---|
35 | } |
---|
36 | |
---|
37 | if (kortinNro > kortit.Count - 1) |
---|
38 | { |
---|
39 | kortinNro = 0; |
---|
40 | } |
---|
41 | |
---|
42 | return kortinNro; |
---|
43 | } |
---|
44 | |
---|
45 | void KorostaKortti(int kortinNro) |
---|
46 | { |
---|
47 | kortinNro = KortinNumeronTarkistus(kortinNro); |
---|
48 | kortit[kortinNro].Color = Color.Gray; |
---|
49 | korostettuKortti = kortinNro; |
---|
50 | } |
---|
51 | |
---|
52 | void PoistaKorostus(int kortinNro) |
---|
53 | { |
---|
54 | kortinNro = KortinNumeronTarkistus(kortinNro); |
---|
55 | kortit[kortinNro].Color = Color.White; |
---|
56 | } |
---|
57 | |
---|
58 | void AsetaNappaimet() |
---|
59 | { |
---|
60 | Keyboard.Listen(Key.Left, ButtonState.Pressed, KortinValinta, null, Suunta.Vasen); |
---|
61 | Keyboard.Listen(Key.Right, ButtonState.Pressed, KortinValinta, null, Suunta.Oikea); |
---|
62 | } |
---|
63 | |
---|
64 | void KortinValinta(Suunta suunta) |
---|
65 | { |
---|
66 | if (suunta == Suunta.Vasen) |
---|
67 | { |
---|
68 | PoistaKorostus(korostettuKortti); |
---|
69 | KorostaKortti(--korostettuKortti); |
---|
70 | } |
---|
71 | |
---|
72 | if (suunta == Suunta.Oikea) |
---|
73 | { |
---|
74 | PoistaKorostus(korostettuKortti); |
---|
75 | KorostaKortti(++korostettuKortti); |
---|
76 | } |
---|
77 | |
---|
78 | |
---|
79 | } |
---|
80 | |
---|
81 | void TeeKortit() |
---|
82 | { |
---|
83 | for (int i = 0; i < 12; i++) |
---|
84 | { |
---|
85 | TeeKortti(); |
---|
86 | } |
---|
87 | } |
---|
88 | |
---|
89 | private void KortitRuudulle(List<GameObject> kortit) |
---|
90 | { |
---|
91 | int montakoKorttia = kortit.Count; |
---|
92 | int montakoKorttiaRiviin = 8; |
---|
93 | int montakoRivia = kortit.Count / 8; |
---|
94 | |
---|
95 | int i = 0; |
---|
96 | int rivi = 1; |
---|
97 | int rivilla = 0; |
---|
98 | foreach (GameObject kortti in kortit) |
---|
99 | { |
---|
100 | Add(kortti); |
---|
101 | kortti.X = (-(montakoKorttia * (kortinLeveys + 20)) / 2) + (i * (kortinLeveys + 20)); |
---|
102 | kortti.Y = |
---|
103 | i++; |
---|
104 | rivilla++; |
---|
105 | if (rivilla > 8) |
---|
106 | { |
---|
107 | rivi++; |
---|
108 | rivilla = 0; |
---|
109 | } |
---|
110 | } |
---|
111 | } |
---|
112 | |
---|
113 | void TeeKortti() |
---|
114 | { |
---|
115 | GameObject kortti = new GameObject(kortinLeveys, kortinKorkeus, Shapes.Rectangle); |
---|
116 | kortti.Color = Color.White; |
---|
117 | kortit.Add(kortti); |
---|
118 | } |
---|
119 | } |
---|