Jypeli  9
The simple game programming library
IntMeter.cs
Siirry tämän tiedoston dokumentaatioon.
1 using System;
2 using System.Collections.Generic;
3 
4 namespace Jypeli
5 {
10  public class IntMeter : Meter<int>
11  {
12  private List<Operation> operations = new List<Operation>();
13 
14  public override double RelativeValue
15  {
16  get { return ( Value - MinValue ) / (double)( MaxValue - MinValue ); }
17  set { Value = (int)( MinValue + value * ( MaxValue - MinValue ) ); }
18  }
19 
20  public IntMeter( int defaultValue )
21  : base( defaultValue, 0, int.MaxValue )
22  {
23  }
24 
25  public IntMeter(int defaultValue,int minValue, int MaxValue)
26  : base(defaultValue, minValue,MaxValue)
27  {
28  }
29 
35  public static implicit operator int( IntMeter m )
36  {
37  return m.Value;
38  }
39 
45  public static implicit operator double( IntMeter m )
46  {
47  return (double)m.Value;
48  }
49 
55  public void AddValue( int change )
56  {
57  Value += change;
58  }
59 
65  public void MultiplyValue( int multiplier )
66  {
67  Value *= multiplier;
68  }
69 
75  public void MultiplyValue( double multiplier )
76  {
77  Value = (int)Math.Round( Value * multiplier );
78  }
79 
87  public Operation AddOverTime( int change, double seconds, Action onComplete )
88  {
89  Operation op = AddOverTime( change, seconds );
90  op.Finished += onComplete;
91  return op;
92  }
93 
100  public Operation AddOverTime( int change, double seconds )
101  {
102  Operation op = new IntMeterAddOperation( this, change, seconds );
103  op.Finished += delegate { operations.Remove( op ); };
104  op.Stopped += delegate { operations.Remove( op ); };
105  operations.Add( op );
106  return op;
107  }
108 
112  public void Stop()
113  {
114  while ( operations.Count > 0 )
115  operations[0].Stop();
116  }
117 
118  internal override double GetValue()
119  {
120  return Value;
121  }
122 
123  internal override double GetMinValue()
124  {
125  return MinValue;
126  }
127 
128  internal override double GetMaxValue()
129  {
130  return MaxValue;
131  }
132  }
133 }
134 
Jypeli.Meter
Mittari, joka mittaa erityyppisiä arvoja. Sidottavissa näyttöihin, kuten ValueDisplay ja BarGauge.
Definition: Meter.cs:61
Jypeli.IntMeter.AddOverTime
Operation AddOverTime(int change, double seconds, Action onComplete)
Lisää tietyn summan mittariin tasaisesti tietyn ajan sisällä.
Definition: IntMeter.cs:87
Jypeli.Operation.Stopped
Action Stopped
Tapahtuu kun tehtävä pysäytetään Stop-metodilla.
Definition: Operation.cs:29
Jypeli.IntMeter.IntMeter
IntMeter(int defaultValue)
Definition: IntMeter.cs:20
Jypeli
Definition: Automobile.cs:5
Jypeli.IntMeter.GetValue
override double GetValue()
Definition: IntMeter.cs:118
Jypeli.IntMeter.AddValue
void AddValue(int change)
Lisää jotain mittarin arvoon. Sama kuin Value-ominaisuuteen lisääminen, mutta helpompi käyttää...
Definition: IntMeter.cs:55
Jypeli.IntMeter.Stop
void Stop()
Pysäyttää AddOverTime-metodilla tehtävät lisäykset mittariin.
Definition: IntMeter.cs:112
Jypeli.IntMeter.AddOverTime
Operation AddOverTime(int change, double seconds)
Lisää tietyn summan mittariin tasaisesti tietyn ajan sisällä.
Definition: IntMeter.cs:100
Jypeli.IntMeter.IntMeter
IntMeter(int defaultValue, int minValue, int MaxValue)
Definition: IntMeter.cs:25
Jypeli.Operation
Käynnissä oleva tehtävä
Definition: Operation.cs:9
Jypeli.Operation.Finished
Action Finished
Tapahtuu kun tehtävä valmistuu. Ei tapahdu, jos tehtävä keskeytetään Stop-aliohjelmalla.
Definition: Operation.cs:24
Jypeli.IntMeter.RelativeValue
override double RelativeValue
Definition: IntMeter.cs:15
Jypeli.IntMeter.MultiplyValue
void MultiplyValue(double multiplier)
Kertoo mittarin arvon jollakin. Sama kuin Value-ominaisuuden kertominen, mutta helpompi käyttää ta...
Definition: IntMeter.cs:75
Jypeli.IntMeterAddOperation
Tehtävä mittarin arvon kasvattamiselle.
Definition: MeterAddOperation.cs:9
Jypeli.IntMeter.operations
List< Operation > operations
Definition: IntMeter.cs:12
System
Definition: CFFauxAttributes.cs:29
Jypeli.IntMeter
Mittari, joka mittaa int-tyyppisiä arvoja. Sidottavissa näyttöihin, kuten ValueDisplay ja BarGauge...
Definition: IntMeter.cs:11
Jypeli.IntMeter.GetMaxValue
override double GetMaxValue()
Definition: IntMeter.cs:128
Jypeli.IntMeter.MultiplyValue
void MultiplyValue(int multiplier)
Kertoo mittarin arvon jollakin. Sama kuin Value-ominaisuuden kertominen, mutta helpompi käyttää ta...
Definition: IntMeter.cs:65
Jypeli.IntMeter.GetMinValue
override double GetMinValue()
Definition: IntMeter.cs:123