Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions katas/LangtonAnt/solutions/petar.peev/LangtonAnt/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version = "1.0" encoding = "UTF-8" ?>
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:LangtonAnt"
x:Class="LangtonAnt.App">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
11 changes: 11 additions & 0 deletions katas/LangtonAnt/solutions/petar.peev/LangtonAnt/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace LangtonAnt;

public partial class App : Application
{
public App()
{
InitializeComponent();

MainPage = new AppShell();
}
}
13 changes: 13 additions & 0 deletions katas/LangtonAnt/solutions/petar.peev/LangtonAnt/AppShell.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Shell
x:Class="LangtonAnt.AppShell"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:LangtonAnt"
Shell.FlyoutBehavior="Disabled">

<ShellContent Title="LangtonAnt"
ContentTemplate="{DataTemplate local:MainPage}"
Route="MainPage" />

</Shell>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace LangtonAnt;

public partial class AppShell : Shell
{
public AppShell()
{
InitializeComponent();
}
}
59 changes: 59 additions & 0 deletions katas/LangtonAnt/solutions/petar.peev/LangtonAnt/LangtonAnt.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net7.0-android;net7.0-ios;net7.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net7.0-windows10.0.19041.0</TargetFrameworks>
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
<!-- <TargetFrameworks>$(TargetFrameworks);net7.0-tizen</TargetFrameworks> -->
<OutputType>Exe</OutputType>
<RootNamespace>LangtonAnt</RootNamespace>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>

<!-- Display name -->
<ApplicationTitle>LangtonAnt</ApplicationTitle>

<!-- App Identifier -->
<ApplicationId>com.companyname.langtonant</ApplicationId>
<ApplicationIdGuid>f4625517-8028-4c23-ba09-295e8cd520db</ApplicationIdGuid>

<!-- Versions -->
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
<ApplicationVersion>1</ApplicationVersion>

<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">11.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">13.1</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
</PropertyGroup>

<ItemGroup>
<!-- App Icon -->
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />

<!-- Splash Screen -->
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" />

<!-- Images -->
<MauiImage Include="Resources\Images\*" />
<MauiImage Update="Resources\Images\dotnet_bot.svg" BaseSize="168,208" />

<!-- Custom Fonts -->
<MauiFont Include="Resources\Fonts\*" />

<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>

<ItemGroup>
<None Remove="Resources\Images\ant.svg" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
</ItemGroup>

</Project>
27 changes: 27 additions & 0 deletions katas/LangtonAnt/solutions/petar.peev/LangtonAnt/LangtonAnt.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31611.283
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LangtonAnt", "LangtonAnt.csproj", "{538C5CEB-16DD-40C4-A823-27964FCA2E4F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{538C5CEB-16DD-40C4-A823-27964FCA2E4F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{538C5CEB-16DD-40C4-A823-27964FCA2E4F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{538C5CEB-16DD-40C4-A823-27964FCA2E4F}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{538C5CEB-16DD-40C4-A823-27964FCA2E4F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{538C5CEB-16DD-40C4-A823-27964FCA2E4F}.Release|Any CPU.Build.0 = Release|Any CPU
{538C5CEB-16DD-40C4-A823-27964FCA2E4F}.Release|Any CPU.Deploy.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {61F7FB11-1E47-470C-91E2-47F8143E1572}
EndGlobalSection
EndGlobal
89 changes: 89 additions & 0 deletions katas/LangtonAnt/solutions/petar.peev/LangtonAnt/MainPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:graphics="clr-namespace:LangtonAnt.Utils"
x:Class="LangtonAnt.MainPage">
<ContentPage.Resources>
<graphics:AntDrawable x:Key="AntDrawable" />
</ContentPage.Resources>
<Grid RowDefinitions="Auto, *">
<Grid.Resources>
<Style x:Key="LabelStyle"
TargetType="Label">
<Setter Property="Margin"
Value="50,15,0,10" />
<Setter Property="WidthRequest"
Value="200" />
</Style>
</Grid.Resources>
<VerticalStackLayout Spacing="10"
Padding="0,10,0,0"
VerticalOptions="Center">
<HorizontalStackLayout>
<Label Text="Kantenlänge:"
Style="{StaticResource LabelStyle}" />
<Entry WidthRequest="120"
MaximumHeightRequest="20"
Text="{Binding Data.EdgeLenght, Mode=TwoWay}" />
<Label Text="Maximal Anzahl der Züge:"
Style="{StaticResource LabelStyle}" />
<Entry WidthRequest="120"
MaximumHeightRequest="20"
Text="{Binding Data.MaxMovesCount, Mode=TwoWay}" />
<Label Text="Zuggeschwindigkeit [ms]:"
Style="{StaticResource LabelStyle}" />
<Entry WidthRequest="120"
MaximumHeightRequest="20"
Text="{Binding Data.DelayTime, Mode=TwoWay}" />
<Button Text="Save result"
Margin="30,0"
Command="{Binding SaveAsFileCommand}" />
</HorizontalStackLayout>
<HorizontalStackLayout>
<Label Text="Startposition der Ameise:"
Style="{StaticResource LabelStyle}" />
<Entry WidthRequest="55"
Margin="0,-5,0,5"
IsEnabled="False"
MaximumHeightRequest="20"
Text="{Binding Data.AnpStartPosition.Row, Mode=TwoWay}" />
<Entry WidthRequest="55"
Margin="10,-5,0,5"
IsEnabled="False"
MaximumHeightRequest="20"
Text="{Binding Data.AnpStartPosition.Column, Mode=TwoWay}" />
<Label Text="Blickrichtung der Ameise:"
Style="{StaticResource LabelStyle}" />
<Picker WidthRequest="120"
ItemsSource="{Binding Data.OutlookItems}"
MaximumHeightRequest="20"
SelectedItem="{Binding Data.AntSelectedStartOutlook, Mode=TwoWay}" />
<Label Text="Anzal Züge:"
Style="{StaticResource LabelStyle}" />
<Entry WidthRequest="120"
IsEnabled="False"
MaximumHeightRequest="20"
Text="{Binding Data.CurrentMovesCount, Mode=TwoWay}" />
<Button Text="Load result"
Margin="30,0"
Command="{Binding LoadFromFileCommand}" />
</HorizontalStackLayout>

<!--<Label Text="{Binding Data.CurrentResult, Mode=OneWay}"
SemanticProperties.HeadingLevel="Level1"
FontSize="16"
HorizontalOptions="Center" />-->
<GraphicsView Drawable="{StaticResource AntDrawable}"
Margin="20"
VerticalOptions="StartAndExpand"
Grid.Column="1"
WidthRequest="500"
HeightRequest="500"
HorizontalOptions="StartAndExpand"
x:Name="antGraphicsView">
</GraphicsView>

</VerticalStackLayout>
</Grid>

</ContentPage>
18 changes: 18 additions & 0 deletions katas/LangtonAnt/solutions/petar.peev/LangtonAnt/MainPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace LangtonAnt;
public partial class MainPage : ContentPage
{
DashboardViewModel viewModel = new DashboardViewModel();
public MainPage()
{
viewModel.Initialize();
BindingContext = viewModel;
AntDrawable.Matchfield = viewModel.Data;
InitializeComponent();

Loaded += (sender, args) => {
viewModel.Data.PropertyChanged += (sender, args) => { if (args.PropertyName == "CurrentResult") antGraphicsView.Invalidate(); };
viewModel.LoadDataCommand.Execute(null);
};
}
}

27 changes: 27 additions & 0 deletions katas/LangtonAnt/solutions/petar.peev/LangtonAnt/MauiProgram.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
global using LangtonAnt.Mvvm.Lite;
global using LangtonAnt.Utils;
global using LangtonAnt.ViewModels;
using Microsoft.Extensions.Logging;

namespace LangtonAnt;

public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});

#if DEBUG
builder.Logging.AddDebug();
#endif

return builder.Build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System.Windows.Input;
namespace LangtonAnt.Mvvm.Lite;
/// <summary>
/// Abstarct base-klasse für MVVM-ViewModels
/// </summary>
public abstract class BaseViewModel : NotificationBase
{
private bool _isRefreshing = false;
private bool _isBusy = false;
private string _title;

public bool IsRefreshing
{
get => _isRefreshing;
protected set
{
if (_isRefreshing == value)
return;

_isRefreshing = value;
RaisePropertyChanged(nameof(IsRefreshing));
}
}
public bool IsBusy
{
get => _isBusy;
protected set
{
if (_isBusy == value)
return;

_isBusy = value;

RaisePropertyChanged(nameof(IsBusy));
}
}
public string Title
{
get => _title;
set {
if(_title != value)
{
_title = value;
RaisePropertyChanged(nameof(Title));
}
}
}
public ICommand LoadDataCommand { get; protected set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace LangtonAnt.Mvvm.Lite;

public abstract class NotificationBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;

// SetField (Name, value); // where there is a data member
protected virtual bool SetProperty<T>(ref T field, T value, [CallerMemberName] string property = null)
{
if (EqualityComparer<T>.Default.Equals(field, value)) return false;
field = value;
RaisePropertyChanged(property);
return true;
}

// SetField(()=> somewhere.Name = value; somewhere.Name, value) // Advanced case where you rely on another property
protected virtual void SetProperty<T>(T currentValue, T newValue, Action doSet, [CallerMemberName] string property = null)
{
if (EqualityComparer<T>.Default.Equals(currentValue, newValue)) return;
doSet.Invoke();
RaisePropertyChanged(property);
}

protected void RaisePropertyChanged(string property)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
}
}

public abstract class NotificationBase<T> : NotificationBase where T : class, new()
{
protected readonly T This;

public static implicit operator T(NotificationBase<T> thing) { return thing.This; }

protected NotificationBase(T thing = null)
{
This = thing ?? new T();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Android.App;
using Android.Content.PM;
using Android.OS;

namespace LangtonAnt;

[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
public class MainActivity : MauiAppCompatActivity
{
}
Loading