Click here to Skip to main content
15,887,585 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey everybody I'm currently doing an assignment for school and I'm really stuck on this part. I've staring at it and googling things for hours and I'm having any luck. I have included below what I have so far.

The directions aren't that good.

"Create a public enum CharacterState for the 4 image states: Attacking, Defending, Idle, and Dead.
Now create a member variable state to hold the character state and a public property State with a get
and set. For now, fill in the default behavior of get and set to return/set the value of state."


Any help would be greatly appeciated! Thank you



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;

namespace WPFBattle
{
class CharacterImage: System.Windows.Controls.Image
{


public enum Attacking{



}

public enum Defending{



}

public enum Idle{



}

public enum Dead{

}


public ImageSource IdleImageSource { get; set; }
public ImageSource AttackingImageSource { get; set; }
public ImageSource TakeDamageImageSource { get; set; }
public ImageSource DeadImageSource { get; set; }

protected void UpdateImageSource()
{
switch (State)
{
case CharacterState.Attacking:
this.Source = AttackingImageSource;
break;
case CharacterState.TakeDamage:
this.Source = TakeDamageImageSource;
break;
case CharacterState.Dead:
this.Source = DeadImageSource;
break;
case CharacterState.Idle:
default:
this.Source = IdleImageSource;
break;
}
}

protected override void OnRender(DrawingContext dc)
{
UpdateImageSource();
base.OnRender(dc);
}


public CharacterState State
{
get { return state; }
set
{
state = value;
this.Dispatcher.Invoke((Action)(() =>
{
UpdateImageSource();
}));
}
}


}
}

What I have tried:

Googling various things, and I tried to follow the directions but nothing seems to be working
Posted
Updated 24-Nov-16 16:33pm
Comments
Philippe Mori 25-Nov-16 10:36am    
Use a code block to format your code. No one like to read unformatted color without syntax coloring. By taking an extra minute when asking your question, you would improve by a huge factor the chance that someone help you. I rarely help people that do at least some effort.

1 solution

you define enums like this:

C#
public enum CharacterState{Attacking,Defending,Idle,Dead}


the class variable should be like this:
Edit: improved second part of answer
class CharacterImage{
//member variable
private CharacterState characterState;

//property
public CharacterState State
{
get{return characterState;}
set(characterState=value;}
}
}
 
Share this answer
 
v2
Comments
Member 12869562 24-Nov-16 22:44pm    
Thank you very much for your response! I fixed the enum part but I'm still a little confused on the "Now create a member variable state to hold the character state and a public property State with a get and set. " part. I'm not sure exactly how to fix that issue.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900