Skip to content

Commit

Permalink
添加自由模式
Browse files Browse the repository at this point in the history
  • Loading branch information
HPLZH committed Oct 8, 2022
1 parent 6289ad7 commit e42e2a2
Show file tree
Hide file tree
Showing 21 changed files with 433 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto" package="cn.hplzh.blackwhite.app" android:versionCode="22" android:versionName="3.1.22">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto" package="cn.hplzh.blackwhite.app" android:versionCode="23" android:versionName="3.2.23">
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="31" />
<application android:label="BlackWhite.App.Android" android:theme="@style/MainTheme" android:icon="@mipmap/icon"></application>
</manifest>
6 changes: 3 additions & 3 deletions BlackWhite.App/BlackWhite.App/AppVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ namespace BlackWhite.App
{
public static class AppVersion
{
public static Version Version => new Version(3, 1, 22);
public static Version Version => new Version(3, 2, 23);

public static DateTime ReleaseDate => new DateTime(2022, 9, 3);
public static DateTime ReleaseDate => new DateTime(2022, 10, 8);

public static bool Preview => false;
public static bool Preview => true;
}
}
6 changes: 6 additions & 0 deletions BlackWhite.App/BlackWhite.App/BlackWhite.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
</ItemGroup>

<ItemGroup>
<Compile Update="Game\Select\NumberSizePage.xaml.cs">
<DependentUpon>NumberSizePage.xaml</DependentUpon>
</Compile>
<Compile Update="Properties\App.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
Expand Down Expand Up @@ -59,6 +62,9 @@
<EmbeddedResource Update="Game\Base\GamePage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Game\Select\NumberSizePage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Properties\App.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>App.Designer.cs</LastGenOutput>
Expand Down
2 changes: 1 addition & 1 deletion BlackWhite.App/BlackWhite.App/Game/Base/GamePage.xaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:c="clr-namespace:BlackWhite.App"
xmlns:c="clr-namespace:BlackWhite.App.Game.Base"
x:Class="BlackWhite.App.Game.Base.GamePage">
<ContentPage.Content>
<StackLayout x:Name="pageStack">
Expand Down
85 changes: 85 additions & 0 deletions BlackWhite.App/BlackWhite.App/Game/Main/FreeGamePage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using BlackWhite.App.Game.Base;
using BlackWhite.Core;
using System;
using System.Collections.Generic;
using System.Text;
using Xamarin.Forms;

namespace BlackWhite.App.Game.Main
{
internal class FreeGamePage : GamePage
{
private FreeCore<GameButton> core;
private Random random = new Random();

private StackLayout toolStack = new StackLayout();
private StackLayout generateStack = new StackLayout() { HorizontalOptions = LayoutOptions.CenterAndExpand, Orientation = StackOrientation.Vertical };
private StackLayout clickStack = new StackLayout() { HorizontalOptions = LayoutOptions.CenterAndExpand, Orientation = StackOrientation.Vertical };

private Label generateLabel = new Label() { Text = Properties.GamePage.Generate, TextColor = Color.White, FontSize = 20, HorizontalTextAlignment = TextAlignment.Center };
private Label clickLabel = new Label() { Text = Properties.GamePage.Click, TextColor = Color.White, FontSize = 20, HorizontalTextAlignment = TextAlignment.Center };
private Button generateButton = new Button() { Text = "..." };
private Switch clickSwitch = new Switch() { HorizontalOptions = LayoutOptions.Center };

public FreeGamePage(int size)
: base()
{
Initialize(size);
InitializeToolBar();
core = new FreeCore<GameButton>(blocks);
Show();
}

private void InitializeToolBar()
{
this.InfoContent = toolStack;
toolStack.Children.Add(generateStack);
toolStack.Children.Add(clickStack);
generateStack.Children.Add(generateLabel);
generateStack.Children.Add(generateButton);
clickStack.Children.Add(clickLabel);
clickStack.Children.Add(clickSwitch);
generateButton.Clicked += GenerateButton_Clicked;
clickSwitch.Toggled += ClickSwitch_Toggled;
}

private void ClickSwitch_Toggled(object sender, ToggledEventArgs e)
{
if (clickSwitch.IsToggled)
{
clickLabel.Text = Properties.GamePage.Single;
core.ClickMode = FreeCore<GameButton>.ClickModes.Change;
}
else
{
clickLabel.Text = Properties.GamePage.Click;
core.ClickMode = FreeCore<GameButton>.ClickModes.Normal;
}
}

private async void GenerateButton_Clicked(object sender, EventArgs e)
{
string result = await DisplayActionSheet(Properties.GamePage.Generate,
Properties.GamePage.Msg_Button_Cancel,
null,
Properties.GamePage.Generate_White,
Properties.GamePage.Generate_Black,
Properties.GamePage.Generate_GameRandomize,
Properties.GamePage.Generate_FullRandomize,
Properties.GamePage.Generate_MixRandomize,
Properties.GamePage.Generate_Invert);
if (result == Properties.GamePage.Generate_White) core.Clear(true);
else if (result == Properties.GamePage.Generate_Black) core.Clear(false);
else if (result == Properties.GamePage.Generate_GameRandomize) core.GameRandomize(random);
else if (result == Properties.GamePage.Generate_FullRandomize) core.FullRandomize(random);
else if (result == Properties.GamePage.Generate_MixRandomize) core.MixRandomize(random);
else if (result == Properties.GamePage.Generate_Invert) core.Invert();
}

protected override void OnSizeAllocated(double width, double height)
{
toolStack.Orientation = width < height ? StackOrientation.Horizontal : StackOrientation.Vertical;
base.OnSizeAllocated(width, height);
}
}
}
22 changes: 22 additions & 0 deletions BlackWhite.App/BlackWhite.App/Game/Select/NumberButton.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Text;

using Xamarin.Forms;

namespace BlackWhite.App.Game.Select
{
internal class NumberButton : Button
{
private int _value;
public int Value
{
get { return _value; }
set
{
_value = value;
this.Text = _value.ToString();
}
}
}
}
48 changes: 48 additions & 0 deletions BlackWhite.App/BlackWhite.App/Game/Select/NumberSizePage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:p="clr-namespace:BlackWhite.App.Properties"
xmlns:c="clr-namespace:BlackWhite.App.Game.Select"
x:Class="BlackWhite.App.Game.Select.NumberSizePage">
<ContentPage.Content>
<StackLayout>
<Frame BackgroundColor="#2196F3" Padding="24" CornerRadius="0">
<StackLayout>
<Label x:Name="titleLabel" HorizontalTextAlignment="Center" TextColor="White" FontSize="36"/>
<Label x:Name="textLabel" HorizontalTextAlignment="Center" TextColor="White"></Label>
</StackLayout>
</Frame>
<ScrollView>
<StackLayout Padding="20">
<Label Text="{x:Static p:StartPage.Size_Label}" HorizontalOptions="Center"></Label>
<Label Text="0" x:Name="sizeText" FontSize="Large" HorizontalOptions="Center"></Label>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<Button x:Name="ac" Text="AC" Grid.Row="3" Grid.Column="2" FontSize="Large" Clicked="ac_Clicked"></Button>
<c:NumberButton Value="0" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="3" FontSize="Large" Clicked="NumberButton_Clicked"></c:NumberButton>
<c:NumberButton Value="1" Grid.Column="0" Grid.Row="2" FontSize="Large" Clicked="NumberButton_Clicked"></c:NumberButton>
<c:NumberButton Value="2" Grid.Column="1" Grid.Row="2" FontSize="Large" Clicked="NumberButton_Clicked"></c:NumberButton>
<c:NumberButton Value="3" Grid.Column="2" Grid.Row="2" FontSize="Large" Clicked="NumberButton_Clicked"></c:NumberButton>
<c:NumberButton Value="4" Grid.Column="0" Grid.Row="1" FontSize="Large" Clicked="NumberButton_Clicked"></c:NumberButton>
<c:NumberButton Value="5" Grid.Column="1" Grid.Row="1" FontSize="Large" Clicked="NumberButton_Clicked"></c:NumberButton>
<c:NumberButton Value="6" Grid.Column="2" Grid.Row="1" FontSize="Large" Clicked="NumberButton_Clicked"></c:NumberButton>
<c:NumberButton Value="7" Grid.Column="0" Grid.Row="0" FontSize="Large" Clicked="NumberButton_Clicked"></c:NumberButton>
<c:NumberButton Value="8" Grid.Column="1" Grid.Row="0" FontSize="Large" Clicked="NumberButton_Clicked"></c:NumberButton>
<c:NumberButton Value="9" Grid.Column="2" Grid.Row="0" FontSize="Large" Clicked="NumberButton_Clicked"></c:NumberButton>
</Grid>
<Button x:Name="start" Text="{x:Static p:StartPage.Start_Button}" Clicked="start_Clicked" IsEnabled="False"></Button>
</StackLayout>
</ScrollView>
</StackLayout>
</ContentPage.Content>
</ContentPage>
70 changes: 70 additions & 0 deletions BlackWhite.App/BlackWhite.App/Game/Select/NumberSizePage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using BlackWhite.App.Game.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace BlackWhite.App.Game.Select
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class NumberSizePage : ContentPage
{
private int _size = 0;

protected virtual void StartGame(int size) { }

public NumberSizePage(string title, string text)
{
InitializeComponent();
titleLabel.Text = title;
textLabel.Text = text;
ChangeValue(0);
}

private void ac_Clicked(object sender, EventArgs e)
{
ChangeValue(0);
}

private void NumberButton_Clicked(object sender, EventArgs e)
{
ChangeValue(_size * 10 + ((NumberButton)sender).Value);
}

private void start_Clicked(object sender, EventArgs e)
{
StartGame(_size);
}

protected override void OnSizeAllocated(double width, double height)
{
ChangeValue(_size);
base.OnSizeAllocated(width, height);
}

private void ChangeValue(int value)
{
_size = value;
sizeText.Text = value.ToString();
if (value < 3)
{
sizeText.TextColor = Color.Red;
start.IsEnabled = false;
}
else if (value > SizeCalculator.GetMax())
{
sizeText.TextColor = Color.Orange;
start.IsEnabled = true;
}
else
{
sizeText.TextColor = Color.Green;
start.IsEnabled = true;
}
}
}
}
12 changes: 12 additions & 0 deletions BlackWhite.App/BlackWhite.App/Game/Select/SizePages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,16 @@ protected override void StartGame(int size)
base.StartGame(size);
}
}

internal class FreeSizePage : NumberSizePage
{
public FreeSizePage()
: base(Properties.StartPage.Free, Properties.StartPage.Free_Text) { }

protected override void StartGame(int size)
{
Navigation.PushAsync(new FreeGamePage(size));
base.StartGame(size);
}
}
}
2 changes: 1 addition & 1 deletion BlackWhite.App/BlackWhite.App/Game/Select/StartPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<c:ButtonCardView ButtonText="{x:Static p:StartPage.Next}" Title="{x:Static p:StartPage.Normal}" Text="{x:Static p:StartPage.Normal_Text}" ButtonClicked="Normal_ButtonClicked"></c:ButtonCardView>
<c:ButtonCardView ButtonText="{x:Static p:StartPage.Next}" Title="{x:Static p:StartPage.Perfect}" Text="{x:Static p:StartPage.Perfect_Text}" ButtonClicked="Perfect_ButtonClicked"></c:ButtonCardView>
<c:ButtonCardView ButtonText="{x:Static p:StartPage.Next}" Title="{x:Static p:StartPage.Timed}" Text="{x:Static p:StartPage.Timed_Text}" ButtonClicked="Timed_ButtonClicked"></c:ButtonCardView>
<c:ButtonCardView IsVisible="False" ButtonText="{x:Static p:StartPage.Next}" Title="{x:Static p:StartPage.Free}" Text="{x:Static p:StartPage.Free_Text}" ButtonClicked="Free_ButtonClicked"></c:ButtonCardView>
<c:ButtonCardView ButtonText="{x:Static p:StartPage.Next}" Title="{x:Static p:StartPage.Free}" Text="{x:Static p:StartPage.Free_Text}" ButtonClicked="Free_ButtonClicked"></c:ButtonCardView>
</StackLayout>
</ScrollView>
</ContentPage.Content>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private void Timed_ButtonClicked(object sender, EventArgs e)

private void Free_ButtonClicked(object sender, EventArgs e)
{

Navigation.PushAsync(new FreeSizePage());
}

}
Expand Down
1 change: 1 addition & 0 deletions BlackWhite.App/BlackWhite.App/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Threading.Tasks;
using System.Threading;
using Xamarin.Forms;
using BlackWhite.App.Game.Select;

namespace BlackWhite.App
{
Expand Down
Loading

0 comments on commit e42e2a2

Please sign in to comment.