1 | using System; |
---|
2 | using System.Collections.Generic; |
---|
3 | using System.Linq; |
---|
4 | using Jypeli; |
---|
5 | using Microsoft.Xna.Framework; |
---|
6 | using Microsoft.Xna.Framework.Graphics; |
---|
7 | |
---|
8 | namespace Muistipeli |
---|
9 | { |
---|
10 | public class Kortti : GameObject |
---|
11 | { |
---|
12 | bool onkoKaantynyt; |
---|
13 | protected Vector alkuperainenKoko; |
---|
14 | protected enum Kortintila { Kuvapuoli, KaantymassaKuvapuoli, KaantymassaTakapuoli, Takapuoli } |
---|
15 | Kortintila tila; |
---|
16 | bool kaantyminenAlkanut = false; |
---|
17 | |
---|
18 | public Kortti(double width, double height) |
---|
19 | : base(width, height, Shapes.Rectangle) |
---|
20 | { |
---|
21 | // TODO: Construct any child components here |
---|
22 | onkoKaantynyt = false; |
---|
23 | tila = Kortintila.Kuvapuoli; |
---|
24 | IsUpdated = true; |
---|
25 | this.alkuperainenKoko = new Vector(width, height); |
---|
26 | } |
---|
27 | |
---|
28 | public void Kaanna() |
---|
29 | { |
---|
30 | kaantyminenAlkanut = true; |
---|
31 | Pienenna(); |
---|
32 | } |
---|
33 | |
---|
34 | protected void Pienenna() |
---|
35 | { |
---|
36 | if (tila == Kortintila.Kuvapuoli) |
---|
37 | { |
---|
38 | tila = Kortintila.KaantymassaKuvapuoli; |
---|
39 | } |
---|
40 | if (tila == Kortintila.Takapuoli) |
---|
41 | { |
---|
42 | tila = Kortintila.KaantymassaTakapuoli; |
---|
43 | } |
---|
44 | } |
---|
45 | |
---|
46 | /// <summary> |
---|
47 | /// Allows the game component to update itself. |
---|
48 | /// </summary> |
---|
49 | /// <param name="gameTime">Provides a snapshot of timing values.</param> |
---|
50 | public override void Update(Time time) |
---|
51 | { |
---|
52 | if (tila == Kortintila.KaantymassaKuvapuoli) |
---|
53 | { |
---|
54 | if(this.Width > 3) |
---|
55 | { |
---|
56 | this.Size = new Vector(this.Width - 3, this.Height); |
---|
57 | } |
---|
58 | if(this.Width <= 3) |
---|
59 | { |
---|
60 | tila = Kortintila.KaantymassaTakapuoli; |
---|
61 | kaantyminenAlkanut = true; |
---|
62 | } |
---|
63 | } |
---|
64 | |
---|
65 | if (tila == Kortintila.KaantymassaTakapuoli) |
---|
66 | { |
---|
67 | if (this.Width < this.alkuperainenKoko.X) |
---|
68 | { |
---|
69 | this.Size = new Vector(this.Width + 3, this.Height); |
---|
70 | } |
---|
71 | if (this.Width >= this.alkuperainenKoko.X) |
---|
72 | { |
---|
73 | tila = Kortintila.Takapuoli; |
---|
74 | kaantyminenAlkanut = false; |
---|
75 | } |
---|
76 | |
---|
77 | } |
---|
78 | |
---|
79 | |
---|
80 | // TODO: Add your update code here |
---|
81 | base.Update(time); |
---|
82 | } |
---|
83 | } |
---|
84 | } |
---|