Hello, I am developing a small role-playing game that works very well with a single Class: Personnage but if I integrate a RadioButton to choose between 3 characters, I cannot retrieve the correct information.
I have a Class : Voleur, Guerrier and Archer which inherits from the Class: Personnage, itself inheriting from the Class: Entite.
Otherwise, if I give all the attributes to a generic Class: Personnage, there is no problem but you cannot choose your character.
My xaml :
<StackLayout x:Name="ChoixPerso">
<Label Text="Choisissez votre avatar."
Margin="20"
HorizontalTextAlignment="Center"
HorizontalOptions="CenterAndExpand"
FontSize="Large"/>
<RadioButton x:Name="ChoixPerso01"
Value="Guerrier"
Content="Guerrier"
CheckedChanged="ChoisirGuerrier"/>
<RadioButton x:Name="ChoixPerso02"
Value="Archer"
Content="Archer"
CheckedChanged="ChoisirArcher"/>
<RadioButton x:Name="ChoixPerso03"
Value="Voleur"
Content="Voleur"
CheckedChanged="ChoisirVoleur"/>
<Label x:Name="personnageLabel"
Text="Vous avez choisi:"/>
</StackLayout>
<!--Row 01-->
<Label HorizontalTextAlignment="Start"
Grid.Row="1"
Grid.ColumnSpan="2"
x:Name="Text01"
TextColor="Black"/>
My xaml.cs :
namespace JdrApp.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class Donjon01 : ContentPage
{
int tentative = 0;
Personnage monPerso = new Personnage("Renshaw");
public Donjon01()
{
InitializeComponent();
}
public void ChoisirGuerrier(object sender, CheckedChangedEventArgs e)
{
RadioButton button = sender as RadioButton;
personnageLabel.Text = $"Vous avez choisi: {button.Content}";
monPerso = { button.Content}( new Guerrier("OlafMegabaff"));
Text01.Text = $"Vous êtes un puissant {button.Content} nommé \n" + monPerso.Caracteristiques() + "\nVous arrivez devant le Donjon et face à vous, une porte sombre et imposante se dresse. Cela semble être la seule entrée.\nQu'allez vous décider ?";
}
public void ChoisirArcher(object sender, CheckedChangedEventArgs e)
{
RadioButton button = sender as RadioButton;
personnageLabel.Text = $"Vous avez choisi: {button.Content}";
monPerso = { button.Content} (new Guerrier("OlafMegabaff"));
Text01.Text = $"Vous êtes un habile {button.Content} nommé \n" + monPerso.Caracteristiques() + "\nVous arrivez devant le Donjon et face à vous, une porte sombre et imposante se dresse. Cela semble être la seule entrée.\nQu'allez vous décider ?";
}
public void ChoisirVoleur(object sender, CheckedChangedEventArgs e)
{
RadioButton button = sender as RadioButton;
personnageLabel.Text = $"Vous avez choisi: {button.Content}";
monPerso = { button.Content} (new Guerrier("OlafMegabaff"));
Text01.Text = $"Vous êtes un rapide {button.Content} nommé \n" + monPerso.Caracteristiques() + "\nVous arrivez devant le Donjon et face à vous, une porte sombre et imposante se dresse. Cela semble être la seule entrée.\nQu'allez vous décider ?";
}
My Entite.cs
public abstract class Entite
{
protected string nom;
protected bool estMort = false;
protected int pointsDeVie;
protected int degatsMin;
protected int degatsMax;
protected int potionsSoins;
protected int piecesOr;
protected Random random = new Random();
public Entite(string nom)
{
this.nom = nom;
}
My Class : Personnage
public class Personnage : Entite
{
private int niveau;
private int experience;
public Personnage(string nom) : base(nom)
{
this.nom = nom;
//pointsDeVie = 150;
//degatsMin = 15;
//degatsMax = 20;
niveau = 1;
experience = 0;
potionsSoins = 0;
}
My Class : Voleur (same as for Guerrier.cs or Archer.cs)
public class Voleur: Personnage
{
public Voleur(string nom) : base(nom)
{
pointsDeVie = 200;
degatsMin = 30;
degatsMax = 35;
}
}
