Browse Source

feat: add progress and restart play CreateFrend

Otter 4 months ago
parent
commit
80737512d3

+ 4 - 8
HelloItQuantum/Function/WorkWithFile.cs

@@ -61,20 +61,16 @@ namespace HelloItQuantum.Function
 			return true;
 		}
 
-
 		static public void UpdateValueGameProgress(int game, int value, User currentUser)
 		{
             List<User>? users = GetAllUsers();
             users.Remove(users.FirstOrDefault(it => it.Nickname == currentUser.Nickname));
-			if (game == 1)
+			switch (game)
 			{
-                if (currentUser.GameHotkeys < value)
-                {
-                    currentUser.GameHotkeys = value;
-                }
+				case 1: currentUser.GameHotkeys = currentUser.GameHotkeys < value ? value : currentUser.GameHotkeys; break;
+				case 2: currentUser.GameLabyrinth = value; break;
+				case 3: currentUser.GameCreateFriend = value; break;
 			}
-			if (game == 2) currentUser.GameLabyrinth = value;
-			if (game == 3) currentUser.GameCreateFriend = value;
             users.Add(currentUser);
             using (StreamWriter writer = new StreamWriter(filePath, false))
             {

+ 10 - 6
HelloItQuantum/ViewModels/GameCreateFriendViewModel.cs

@@ -1,7 +1,5 @@
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
-using System.Drawing.Printing;
-using System.Xml.Linq;
 using Avalonia;
 using Avalonia.Controls;
 using Avalonia.Controls.Shapes;
@@ -22,6 +20,7 @@ namespace HelloItQuantum.ViewModels
 			{ 2, Color.Parse("#B21E22") },
 			{ 3, Color.Parse("#006838") }
 		};
+		public void GoBack() => PageSwitch.View = new PlaySectionView();
 
 		#region Object and Property for Xaml
 		ObservableCollection<FriendElement> listElements = new ObservableCollection<FriendElement>();
@@ -72,15 +71,20 @@ namespace HelloItQuantum.ViewModels
 
 		public void ClickCreateFriend()
 		{
-			if (btnContent == "ÑÎÇÄÀÒÜ")
+			if (btnContent == "ÑÎÇÄÀÒÜ" && PChildrens.Children.Count > 1)
 			{
+				WorkWithFile.UpdateValueGameProgress(3, 100, CurrentUser);
 				IsVisibleHello = true;
-				BtnContent = "ÂÛÉÒÈ";
+				BtnContent = "ÇÀÍÎÂÎ";
 				BtnColor = new SolidColorBrush(Color.Parse("#F26527"));
 			}
-			else
+			else if (btnContent == "ÇÀÍÎÂÎ")
 			{
-				PageSwitch.View = new PlaySectionView();
+				IsVisibleHello = false;
+				BtnContent = "ÑÎÇÄÀÒÜ";
+				BtnColor = new SolidColorBrush(Color.Parse("#7CBE41"));
+				PChildrens.Children.Clear();
+				ListElements.Clear();
 			}
 		}
 

+ 0 - 2
HelloItQuantum/ViewModels/HomeViewModel.cs

@@ -1,6 +1,4 @@
-using Avalonia.Controls.ApplicationLifetimes;
 using HelloItQuantum.Views;
-using Avalonia.Controls;
 
 namespace HelloItQuantum.ViewModels
 {

+ 1 - 1
HelloItQuantum/ViewModels/MainWindowViewModel.cs

@@ -20,7 +20,7 @@ namespace HelloItQuantum.ViewModels
         static PlaySectionViewModel? playSectionVM;
 		public static PlaySectionViewModel PlaySectionVM { get => playSectionVM; set => playSectionVM = value; }
 
-		static GameCreateFriendViewModel? gameCreateFriendVM;
+		static GameCreateFriendViewModel gameCreateFriendVM = new GameCreateFriendViewModel();
 		public static GameCreateFriendViewModel GameCreateFriendVM { get => gameCreateFriendVM; set => gameCreateFriendVM = value; }
 
 		static HotkeysViewModel hotkeysVM;

+ 3 - 11
HelloItQuantum/ViewModels/PlaySectionViewModel.cs

@@ -13,19 +13,11 @@ namespace HelloItQuantum.ViewModels
 
         public void GoLabyrinth()
         {
-
             PageSwitch.View = new LabyrinthView();
         }
 
-        public void GoCreateFriend()
-        {
-			GameCreateFriendVM = new GameCreateFriendViewModel();
-			PageSwitch.View = new GameCreateFriendView();
-        }
-
-        public void GoBack()
-        {
-            PageSwitch.View = new HomeView();
-        }
+        public void GoCreateFriend() => PageSwitch.View = new GameCreateFriendView();
+   
+        public void GoBack() => PageSwitch.View = new HomeView();
     }
 }

+ 4 - 1
HelloItQuantum/Views/GameCreateFriendView.axaml

@@ -28,7 +28,7 @@
 	</UserControl.Styles>
 
 		<Panel Background="#006838">
-			<Grid ColumnDefinitions="auto, auto" RowDefinitions="*, auto" Margin="5 20" HorizontalAlignment="Center">
+			<Grid ColumnDefinitions="auto, auto" RowDefinitions="*, auto" Margin="10 20" HorizontalAlignment="Center">
 
 				<Grid Grid.Column="0" Grid.Row="0" ColumnDefinitions="60, 200, 20, 140, 20, 300, 40" RowDefinitions="auto, 10, *">
 
@@ -96,6 +96,9 @@
 						Margin="0 30"
 						Background="{Binding GameCreateFriendVM.BtnColor}"/>
 			</Grid>
+			<Button Command="{Binding GameCreateFriendVM.GoBack}" Width="50" Height="50" VerticalAlignment="Top" CornerRadius="10000" Padding="1" Margin="10 20">
+				<Image Source="/Assets/КнопкаНазад.png"/>
+			</Button>
 		</Panel>