Jypeli  9
The simple game programming library
Brain.cs
Siirry tämän tiedoston dokumentaatioon.
1 #region MIT License
2 /*
3  * Copyright (c) 2009 University of Jyväskylä, Department of Mathematical
4  * Information Technology.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 #endregion
25 
26 /*
27  * Authors: Tero Jäntti, Tomi Karppinen, Janne Nikkanen.
28  */
29 
30 using System.ComponentModel;
31 using System;
32 
33 namespace Jypeli
34 {
40  public class Brain
41  {
45  internal static readonly Brain None = new Brain();
46 
47  private bool active = true;
48 
52  public bool Active
53  {
54  get { return active; }
55  set { active = value; }
56  }
57 
61  public event Action<Brain> Updated;
62 
64 
69  {
70  get { return _owner; }
71  set
72  {
73  if ( _owner == value ) return;
74  IGameObject prevOwner = _owner;
75  _owner = value;
76  if ( prevOwner != null ) OnRemove( prevOwner );
77  if ( value != null ) OnAdd( value );
78  }
79  }
80 
81  internal void AddToGameEvent()
82  {
83  OnAddToGame();
84  }
85 
86  internal void DoUpdate( Time time )
87  {
88  if ( Active )
89  {
90  Update( time );
91  if ( Updated != null ) Updated( this );
92  }
93  }
94 
99  [EditorBrowsable( EditorBrowsableState.Never )]
100  protected virtual void OnAdd( IGameObject newOwner )
101  {
102  }
103 
108  [EditorBrowsable( EditorBrowsableState.Never )]
109  protected virtual void OnRemove( IGameObject prevOwner )
110  {
111  }
112 
117  [EditorBrowsable( EditorBrowsableState.Never )]
118  protected virtual void OnAddToGame() { }
119 
127  [EditorBrowsable( EditorBrowsableState.Never )]
128  protected virtual void Update( Time time ) { }
129 
136  [EditorBrowsable( EditorBrowsableState.Never )]
137  public virtual void OnCollision( IGameObject target )
138  {
139  }
140  }
141 }
Jypeli.Brain.OnAddToGame
virtual void OnAddToGame()
Kutsutaan, kun aivojen omistaja lisätään peliin tai omistajaksi asetetaan olio, joka on jo lisätty pe...
Definition: Brain.cs:118
Jypeli.Brain.OnRemove
virtual void OnRemove(IGameObject prevOwner)
Kutsutaan, kun aivot poistetaan oliolta.
Definition: Brain.cs:109
Jypeli.Brain.Updated
Action< Brain > Updated
Tapahtuu kun aivoja päivitetään.
Definition: Brain.cs:61
Jypeli.Brain.Owner
IGameObject Owner
Aivojen haltija.
Definition: Brain.cs:69
Jypeli
Definition: Automobile.cs:5
Jypeli.IGameObject
Yhteinen rajapinta kaikille peliolioille.
Definition: IGameObject.cs:11
Jypeli.Brain
Aivoluokka peliolioille. Voidaan käyttää tekoälyn ja tilannekohtaisten toimintamallien luomiseen peli...
Definition: Brain.cs:41
Jypeli.Brain.OnAdd
virtual void OnAdd(IGameObject newOwner)
Kutsutaan, kun aivot lisätään oliolle.
Definition: Brain.cs:100
Jypeli.Time
Sisältää tiedon ajasta, joka on kulunut pelin alusta ja viime päivityksestä.
Definition: Time.cs:14
Jypeli.Brain.DoUpdate
void DoUpdate(Time time)
Definition: Brain.cs:86
Jypeli.Brain.OnCollision
virtual void OnCollision(IGameObject target)
Kutsutaan, kun tapahtuu törmäys. Perivässä luokassa methodin kuuluu kutsua vastaavaa kantaluokan meth...
Definition: Brain.cs:137
Jypeli.Brain.None
static readonly Brain None
Tyhjät aivot, eivät sisällä mitään toiminnallisuutta.
Definition: Brain.cs:45
System
Definition: CFFauxAttributes.cs:29
Jypeli.Brain.active
bool active
Definition: Brain.cs:47
Jypeli.Brain.Active
bool Active
Aivot käytössä tai pois käytöstä.
Definition: Brain.cs:53
Jypeli.Brain.Update
virtual void Update(Time time)
Kutsutaan, kun tilaa päivitetään. Suurin osa päätöksenteosta tapahtuu täällä. Perivässä luokassa meth...
Definition: Brain.cs:128
Jypeli.Brain._owner
IGameObject _owner
Definition: Brain.cs:63
Jypeli.Brain.AddToGameEvent
void AddToGameEvent()
Definition: Brain.cs:81