mirror of
https://github.com/Nioux/AideDeJeu.git
synced 2025-10-30 15:06:06 +00:00
Dice vm
This commit is contained in:
parent
d3b81c32c5
commit
4c63fce22f
3 changed files with 86 additions and 9 deletions
|
|
@ -14,6 +14,26 @@ namespace AideDeJeu.ViewModels
|
||||||
_Random = new Random(Environment.TickCount);
|
_Random = new Random(Environment.TickCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private int _Quantity = 3;
|
||||||
|
public int Quantity
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _Quantity;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
SetProperty(ref _Quantity, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public int _Type = 6;
|
||||||
|
public int Type { get { return _Type; } set { SetProperty(ref _Type, value); } }
|
||||||
|
public int _Mod = 0;
|
||||||
|
public int Mod { get { return _Mod; } set { SetProperty(ref _Mod, value); } }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public List<int> RollMRick()
|
public List<int> RollMRick()
|
||||||
{
|
{
|
||||||
var dices = new List<int>();
|
var dices = new List<int>();
|
||||||
|
|
|
||||||
|
|
@ -6,16 +6,64 @@
|
||||||
x:Class="AideDeJeu.Views.DicesPage">
|
x:Class="AideDeJeu.Views.DicesPage">
|
||||||
<ContentPage.Content>
|
<ContentPage.Content>
|
||||||
<StackLayout>
|
<StackLayout>
|
||||||
<!--<Label Text="Welcome to Xamarin.Forms!"
|
|
||||||
VerticalOptions="CenterAndExpand"
|
|
||||||
HorizontalOptions="CenterAndExpand" />-->
|
|
||||||
<StackLayout Orientation="Horizontal">
|
<StackLayout Orientation="Horizontal">
|
||||||
|
<Picker SelectedItem="{Binding BindingContext.Quantity, Mode=TwoWay}">
|
||||||
|
<Picker.ItemsSource>
|
||||||
|
<x:Array Type="{x:Type x:Int32}">
|
||||||
|
<x:Int32>6</x:Int32>
|
||||||
|
<x:Int32>5</x:Int32>
|
||||||
|
<x:Int32>4</x:Int32>
|
||||||
|
<x:Int32>3</x:Int32>
|
||||||
|
<x:Int32>2</x:Int32>
|
||||||
|
<x:Int32>1</x:Int32>
|
||||||
|
</x:Array>
|
||||||
|
</Picker.ItemsSource>
|
||||||
|
</Picker>
|
||||||
|
<Picker ItemDisplayBinding="{Binding StringFormat='d{0}'}" SelectedItem="{Binding BindingContext.Type, Mode=TwoWay}">
|
||||||
|
<Picker.ItemsSource>
|
||||||
|
<x:Array Type="{x:Type x:Int32}">
|
||||||
|
<x:Int32>20</x:Int32>
|
||||||
|
<x:Int32>12</x:Int32>
|
||||||
|
<x:Int32>10</x:Int32>
|
||||||
|
<x:Int32>8</x:Int32>
|
||||||
|
<x:Int32>6</x:Int32>
|
||||||
|
<x:Int32>4</x:Int32>
|
||||||
|
</x:Array>
|
||||||
|
</Picker.ItemsSource>
|
||||||
|
</Picker>
|
||||||
|
<Picker ItemDisplayBinding="{Binding StringFormat='{}{0:+0;-#}'}" SelectedItem="{Binding BindingContext.Mod, Mode=TwoWay}">
|
||||||
|
<Picker.ItemsSource>
|
||||||
|
<x:Array Type="{x:Type x:Int32}">
|
||||||
|
<x:Int32>10</x:Int32>
|
||||||
|
<x:Int32>9</x:Int32>
|
||||||
|
<x:Int32>8</x:Int32>
|
||||||
|
<x:Int32>7</x:Int32>
|
||||||
|
<x:Int32>6</x:Int32>
|
||||||
|
<x:Int32>5</x:Int32>
|
||||||
|
<x:Int32>4</x:Int32>
|
||||||
|
<x:Int32>3</x:Int32>
|
||||||
|
<x:Int32>2</x:Int32>
|
||||||
|
<x:Int32>1</x:Int32>
|
||||||
|
<x:Int32>0</x:Int32>
|
||||||
|
<x:Int32>-1</x:Int32>
|
||||||
|
<x:Int32>-2</x:Int32>
|
||||||
|
<x:Int32>-3</x:Int32>
|
||||||
|
<x:Int32>-4</x:Int32>
|
||||||
|
<x:Int32>-5</x:Int32>
|
||||||
|
<x:Int32>-6</x:Int32>
|
||||||
|
<x:Int32>-7</x:Int32>
|
||||||
|
<x:Int32>-8</x:Int32>
|
||||||
|
<x:Int32>-9</x:Int32>
|
||||||
|
<x:Int32>-10</x:Int32>
|
||||||
|
</x:Array>
|
||||||
|
</Picker.ItemsSource>
|
||||||
|
</Picker>
|
||||||
|
<!--<pickers:StringPickerView BindingContext="{Binding}" Title="{Binding PreferedBackgroundSpecialties.Name}" Description="{Binding PreferedBackgroundSpecialties.Description}" ItemsSource="{Binding PreferedBackgroundSpecialties.BindableTable}" SelectedItem="{Binding BackgroundSpecialty, Mode=TwoWay}" />
|
||||||
<pickers:StringPickerView BindingContext="{Binding}" Title="{Binding PreferedBackgroundSpecialties.Name}" Description="{Binding PreferedBackgroundSpecialties.Description}" ItemsSource="{Binding PreferedBackgroundSpecialties.BindableTable}" SelectedItem="{Binding BackgroundSpecialty, Mode=TwoWay}" />
|
<pickers:StringPickerView BindingContext="{Binding}" Title="{Binding PreferedBackgroundSpecialties.Name}" Description="{Binding PreferedBackgroundSpecialties.Description}" ItemsSource="{Binding PreferedBackgroundSpecialties.BindableTable}" SelectedItem="{Binding BackgroundSpecialty, Mode=TwoWay}" />
|
||||||
<pickers:StringPickerView BindingContext="{Binding}" Title="{Binding PreferedBackgroundSpecialties.Name}" Description="{Binding PreferedBackgroundSpecialties.Description}" ItemsSource="{Binding PreferedBackgroundSpecialties.BindableTable}" SelectedItem="{Binding BackgroundSpecialty, Mode=TwoWay}" />
|
<pickers:StringPickerView BindingContext="{Binding}" Title="{Binding PreferedBackgroundSpecialties.Name}" Description="{Binding PreferedBackgroundSpecialties.Description}" ItemsSource="{Binding PreferedBackgroundSpecialties.BindableTable}" SelectedItem="{Binding BackgroundSpecialty, Mode=TwoWay}" />-->
|
||||||
<pickers:StringPickerView BindingContext="{Binding}" Title="{Binding PreferedBackgroundSpecialties.Name}" Description="{Binding PreferedBackgroundSpecialties.Description}" ItemsSource="{Binding PreferedBackgroundSpecialties.BindableTable}" SelectedItem="{Binding BackgroundSpecialty, Mode=TwoWay}" />
|
|
||||||
|
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
<skviews:SKCanvasView Margin="15" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" PaintSurface="SKCanvasView_PaintSurface">
|
<skviews:SKCanvasView x:Name="CanvasDices" Margin="15" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" PaintSurface="SKCanvasView_PaintSurface">
|
||||||
|
|
||||||
</skviews:SKCanvasView>
|
</skviews:SKCanvasView>
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
|
|
|
||||||
|
|
@ -18,15 +18,24 @@ namespace AideDeJeu.Views
|
||||||
public DicesPage()
|
public DicesPage()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
var vm = new DiceRollerViewModel();
|
||||||
|
vm.PropertyChanged += Vm_PropertyChanged;
|
||||||
|
BindingContext = vm;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Vm_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||||
|
{
|
||||||
|
CanvasDices.InvalidateSurface();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SKCanvasView_PaintSurface(object sender, SkiaSharp.Views.Forms.SKPaintSurfaceEventArgs args)
|
private void SKCanvasView_PaintSurface(object sender, SkiaSharp.Views.Forms.SKPaintSurfaceEventArgs args)
|
||||||
{
|
{
|
||||||
|
var vm = BindingContext as DiceRollerViewModel;
|
||||||
var diceRoller = new DiceRollerViewModel();
|
var diceRoller = new DiceRollerViewModel();
|
||||||
var diceRolls = diceRoller.DicesValues(6, 3);
|
var diceRolls = diceRoller.DicesValues(vm.Type, vm.Quantity);
|
||||||
foreach (var diceRoll in diceRolls)
|
foreach (var diceRoll in diceRolls)
|
||||||
{
|
{
|
||||||
Debug.WriteLine($"{diceRoll.Key} => {diceRoll.Value / 3}");
|
Debug.WriteLine($"{diceRoll.Key} => {diceRoll.Value / vm.Quantity}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue