Thank you Sherif for kind reply,
I wanted to mean, here my Bonus class.
public class Bonus
{
Timer bonusTimer;
const int BONUS_TIME_MAX = 5;
Player tempPlayer
public Bonus(Player myPlayer)
{
bonusTimer = new Timer();
bonusTimer.Enabled = true;
bonusTimer.Interval = 1000;
seconds = 0;
isBonusFinished = false;
this.bonusTimer.Tick += new
System.EventHandler(this.bonusTimer_Tick);
}
public void setProperties(ref Player myPlayer)
{
tempPlayer = myPlayer
tempPlayer.ChangeColor(Color.White);
}
public void setPropertiesBack(Player tempPlayer)
{
tempPlayer.ChangeColor(Color.Black);
bonusTimer.Enabled = false;
}
private void bonusTimer_Tick(object sender, System.EventArgs e)
{
if(++seconds == BONUS_TIME_MAX)
{
setPropertiesBack(tempPlayer);
}
}
}
In Game class;
I'm creating a bonus,
Player playerOne = new Player(Color.Red);
Bonus myBonus = new Bonus(playerOne);
When user gets bonus, I want just invoke setProperties(playerOne method and
myBonus object will change color of playerOne to white first and after 5
seconds to black.
How can I do this?
Thanks.
"Sherif ElMetainy" <el*************@wayout.net.NOSPAM> wrote in message
news:ua**************@TK2MSFTNGP10.phx.gbl...
Hello
Make the myTimer event handler an instance member of the Player class.
myTimer.Tick += new EventHandler(myPlayer.ChangeColor);
class Player
{
// other Player class members
public void ChangeColor(object sender, EventArgs args) {
this.Color = Colors.White;
}
}
Best regards,
Sherif
"Arda Coskun" <a@a.com> wrote in message
news:#U**************@TK2MSFTNGP12.phx.gbl... Hi,
I have a problem with references in C#.
I have three classes; Game class, Player class and Bonus class.
In Game class,
I have created a Player object and named it myPlayer and set myPlayer's
color to White.
I have created a Bonus object and named it myBonus and send myPlayer to
myBonus as a parameter.
In Bonus class,
I have created a Timer object and named it myTimer.
The thing I want to do is change myPlayer's color from myTimer's Tick
event.
I do not want to declare myPlayer's color as static. I want to solve
this with references but how?
Any help would be appriciated.