Hello,
Welcome to our Microsoft Q&A platform!
I do not know about this monPerso = { button.Content}( new Guerrier("OlafMegabaff"));, I copy this line to my demo, it will have grammatical errors. So I change it to monPerso = new Archer(button.Content + ": test 2"); format.
Do you want to achieve the function like following screenshot? I do not know what is Archer and Voleur s name? So I give change name to test1, test 2, test 3. and you donot share Caracteristiques method, I make him to return the value of nom.
Click the Guerrier
click the Archer
click the Voleur
Here is xaml.cs code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace RecordAudioDemo
{
[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"));
monPerso= new Guerrier(button.Content+": test 1");
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 Archer("OlafMegabaff"));
monPerso = new Archer(button.Content + ": test 2");
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 Voleur("OlafMegabaff"));
monPerso = new Voleur(button.Content + ": test 3");
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 ?";
}
}
}
Here is edited Personnage.cs
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;
}
internal string Caracteristiques()
{
// throw new NotImplementedException();
return "nom: " + this.nom;
}
}
Best Regards,
Leon Lu
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.