Selaa lähdekoodia

feat: add system save Progress

klmnvan 2 kuukautta sitten
vanhempi
commit
e63cffd3fe

+ 18 - 0
HelloItQuantum/Function/WorkWithFile.cs

@@ -59,5 +59,23 @@ namespace HelloItQuantum.Function
 			}
 			return true;
 		}
+
+
+		static public void UpdateValueGameProgress(int game, int value, User currentUser)
+		{
+            List<User>? users = GetAllUsers();
+			users.Remove(currentUser);
+			if (game == 1) currentUser.GameHotkeys = value;
+			if (game == 2) currentUser.GameLabyrinth = value;
+			if (game == 3) currentUser.GameCreateFriend = value;
+            users.Add(currentUser);
+            using (StreamWriter writer = new StreamWriter(filePath, false))
+            {
+				foreach (User newUser in users)
+				{
+                    writer.WriteLine($"{newUser.Nickname};{newUser.Name};{newUser.Surname};{newUser.GameHotkeys};{newUser.GameCreateFriend};{newUser.GameLabyrinth}");
+                }
+            }
+        }
 	}
 }

+ 1 - 0
HelloItQuantum/ViewModels/AuthViewModel.cs

@@ -28,6 +28,7 @@ namespace HelloItQuantum.ViewModels
                 userNicknames = users.Select(it => it.Nickname).ToList();
                 if (userNicknames.Contains(Nickname))
                 {
+                    CurrentUser = users.FirstOrDefault(it => it.Nickname == Nickname);
                     HomeVM = new HomeViewModel();
                     PageSwitch.View = new HomeView();
                 }

+ 7 - 1
HelloItQuantum/ViewModels/HotkeysViewModel.cs

@@ -1,4 +1,5 @@
-using HelloItQuantum.Views;
+using HelloItQuantum.Function;
+using HelloItQuantum.Views;
 using System;
 using System.IO;
 using System.Media;
@@ -141,6 +142,7 @@ namespace HelloItQuantum.ViewModels
                         {
                             if (TextAnswer.ToLower().Trim() == "backspace" || TextAnswer.ToLower().Trim() == "←" || TextAnswer.ToLower().Trim() == "<-")
                             {
+                                WorkWithFile.UpdateValueGameProgress(1, 20, CurrentUser);
                                 act = (6, "Ты молодец. Знаешь ли ты, как с помощью клавиатуры скопировать текст?", 2);
                                 path = $"{directory}\\Assets\\HotkeysAudio\\voice6.wav";
                                 TextShowAct = "2/5";
@@ -192,6 +194,7 @@ namespace HelloItQuantum.ViewModels
                         {
                             if (TextAnswer.ToLower().Trim() == "ctrl + c" || TextAnswer.ToLower().Trim() == "ctrl c")
                             {
+                                WorkWithFile.UpdateValueGameProgress(1, 40, CurrentUser);
                                 act = (9, "Отлично справляешься. Знаешь ли ты, как с помощью клавиатуры вставить скопированный текст?", 2);
                                 path = $"{directory}\\Assets\\HotkeysAudio\\voice11.wav";
                                 TextShowAct = "3/5";
@@ -237,6 +240,7 @@ namespace HelloItQuantum.ViewModels
                         {
                             if (TextAnswer.ToLower().Trim() == "ctrl + v")
                             {
+                                WorkWithFile.UpdateValueGameProgress(1, 60, CurrentUser);
                                 act = (12, "Почти конец! Знаешь ли ты, как стереть символ спереди курсора?", 2);
                                 path = $"{directory}\\Assets\\HotkeysAudio\\voice15.wav";
                                 TextShowAct = "4/5";
@@ -282,6 +286,7 @@ namespace HelloItQuantum.ViewModels
                         {
                             if (TextAnswer.ToLower().Trim() == "delete" || TextAnswer.ToLower().Trim() == "del")
                             {
+                                WorkWithFile.UpdateValueGameProgress(1, 80, CurrentUser);
                                 act = (15, "И мой последний вопрос. Знаешь ли ты, как закрыть приложение, в котором ты сейчас находишься, с помощью клавиш?", 2);
                                 path = $"{directory}\\Assets\\HotkeysAudio\\voice19.wav";
                                 TextShowAct = "5/5";
@@ -327,6 +332,7 @@ namespace HelloItQuantum.ViewModels
                         {
                             if (TextAnswer.ToLower().Trim() == "alt + f4")
                             {
+                                WorkWithFile.UpdateValueGameProgress(1, 100, CurrentUser);
                                 act = (18, "Ты молодец и знаешь все базовые горячие клавиши для того, чтобы изучать программирование. Надеюсь это поможет тебе выбрать направление. Пока-пока!", 1);
                                 path = $"{directory}\\Assets\\HotkeysAudio\\voice23.wav";
                                 TextInBtnNext = "Выйти";

+ 9 - 4
HelloItQuantum/ViewModels/MainWindowViewModel.cs

@@ -1,4 +1,6 @@
-namespace HelloItQuantum.ViewModels
+using HelloItQuantum.Models;
+
+namespace HelloItQuantum.ViewModels
 {
 	public class MainWindowViewModel : ViewModelBase
 	{
@@ -9,7 +11,7 @@
         static AuthViewModel authVM = new AuthViewModel();
         public static AuthViewModel AuthVM { get => authVM; set => authVM = value; }
 
-        static ProgressViewModel progressVM = new ProgressViewModel();
+        static ProgressViewModel progressVM;
         public static ProgressViewModel ProgressVM { get => progressVM; set => progressVM = value; }
 
         static CreateProfileViewModel createProfileVM = new CreateProfileViewModel();
@@ -26,6 +28,9 @@
         
         static LabyrinthViewModel labyrinthVM = new LabyrinthViewModel();
 		public static LabyrinthViewModel LabyrinthVM { get => labyrinthVM; set => labyrinthVM = value; }
-		#endregion
-	}
+
+        static User currentUser;
+        public static User CurrentUser { get => currentUser; set => currentUser = value; }
+        #endregion
+    }
 }

+ 4 - 0
HelloItQuantum/ViewModels/PlaySectionViewModel.cs

@@ -23,5 +23,9 @@ namespace HelloItQuantum.ViewModels
 			PageSwitch.View = new GameCreateFriendView();
         }
 
+        public void GoBack()
+        {
+            PageSwitch.View = new HomeView();
+        }
     }
 }

+ 23 - 2
HelloItQuantum/ViewModels/ProgressViewModel.cs

@@ -1,11 +1,32 @@
 using System;
 using System.Collections.Generic;
+using HelloItQuantum.Views;
 using ReactiveUI;
 
 namespace HelloItQuantum.ViewModels
 {
-	public class ProgressViewModel : ReactiveObject
+	public class ProgressViewModel : MainWindowViewModel
 	{
+        #region
+        int pbGameHotkeys = 0;
+        int pbGameCreateFriend = 0;
+        int pbGameLabyrinth = 0;
 
-	}
+        public int PbGameHotkeys { get => pbGameHotkeys; set => SetProperty(ref pbGameHotkeys, value); }
+        public int PbGameCreateFriend { get => pbGameCreateFriend; set => SetProperty(ref pbGameCreateFriend, value); }
+        public int PbGameLabyrinth { get => pbGameLabyrinth; set => SetProperty(ref pbGameLabyrinth, value); }
+        #endregion
+
+        public ProgressViewModel()
+        {
+            PbGameHotkeys = CurrentUser.GameHotkeys;
+            PbGameCreateFriend = CurrentUser.GameCreateFriend;
+            PbGameLabyrinth = CurrentUser.GameLabyrinth;
+        }
+
+        public void GoBack()
+        {
+            PageSwitch.View = new HomeView();
+        }
+    }
 }

+ 9 - 45
HelloItQuantum/Views/PlaySectionView.axaml

@@ -13,11 +13,8 @@
 		</Style>
 	</UserControl.Styles>
 
-	<Panel>
-		<!--<Image Source="/Assets/фон.png" Stretch="Fill"
-       StretchDirection="Both" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>-->
-		
-		<StackPanel HorizontalAlignment="Stretch" Orientation="Vertical" VerticalAlignment="Stretch" Background="#C8FFF5">
+	<Panel Background="#C8FFF5">
+		<StackPanel HorizontalAlignment="Stretch" Orientation="Vertical" VerticalAlignment="Stretch">
 
 			<Grid ColumnDefinitions="Auto, *" RowDefinitions="*">
 				<Image Grid.Column="0" Grid.Row="0" Source="/Assets/kvanlogo.png" Width="100" Height="100" Margin="30 0 0 0"></Image>
@@ -69,47 +66,14 @@
 				<Rectangle Grid.Column="4" Grid.Row="1" Height="{Binding $parent[Grid].Bounds.Height}" Width="40" Fill="#54230E"/>
 
 			</Grid>
-
-			<!--<Grid ColumnDefinitions="*,*,*" RowDefinitions="*" VerticalAlignment="Stretch" Margin="50 40 50 0" HorizontalAlignment="Center">
-				<Border Grid.Column="0" Grid.Row="0" CornerRadius="10" Background="#0BA5CF" BoxShadow="0 5 #0534B5" VerticalAlignment="Stretch">
-					<Button HorizontalAlignment="Stretch" VerticalAlignment="Stretch" VerticalContentAlignment="Center" 
-							Command="{Binding PlaySectionVM.GoCommands}" CornerRadius="10">
-						<StackPanel>
-							<ProgressBar Margin="30 20" Height="20" Minimum="0" Maximum="100" Value="14" Foreground="#0534B5" Background="#FFFFFF" ShowProgressText="True"/>
-							<Svg Path="/Assets/icon_comands.svg" Margin="80 20"/>
-							<Border Background="White" BorderThickness="1" HorizontalAlignment="Stretch" Margin="30 0 30 10"/>
-							<TextBlock Text="Комманды" FontSize="24" TextAlignment="Center" Foreground="#FFFFFF" Margin="0 0 0 30"/>
-						</StackPanel>
-					</Button>
-				</Border>
-
-				<Border Grid.Column="1" Grid.Row="0" CornerRadius="10" Background="#F26527" BoxShadow="0 5 #973F19" VerticalAlignment="Stretch" >
-					<Button HorizontalAlignment="Stretch" VerticalAlignment="Stretch" VerticalContentAlignment="Center" 
-							Command="{Binding PlaySectionVM.GoLabyrinth}" CornerRadius="10">
-						<StackPanel>
-							<ProgressBar Margin="30 20" Height="20" Minimum="0" Maximum="100" Value="14" Foreground="#973F19" Background="#FFFFFF" ShowProgressText="True"/>
-							<Svg Path="/Assets/icon_labyrinth.svg" Margin="80 20"/>
-							<Border Background="White" BorderThickness="1" HorizontalAlignment="Stretch" Margin="30 0 30 10"/>
-							<TextBlock Text="Лабиринт" FontSize="24" TextAlignment="Center" Foreground="#FFFFFF" Margin="0 0 0 30"/>
-						</StackPanel>
-					</Button>
-				</Border>
-
-				<Border Grid.Column="2" Grid.Row="0" CornerRadius="10" Background="#00A659" BoxShadow="0 5 #006838" VerticalAlignment="Stretch">
-					<Button HorizontalAlignment="Stretch" VerticalAlignment="Stretch" VerticalContentAlignment="Center" 
-							Command="{Binding PlaySectionVM.GoCreateFriend}" CornerRadius="10">
-						<StackPanel>
-							<ProgressBar Margin="30 20" Height="20" Minimum="0" Maximum="100" Value="14" Foreground="#006838" Background="#FFFFFF" ShowProgressText="True"/>
-							<Svg Path="/Assets/icon_create_friend.svg" Margin="80 20"/>
-							<Border Background="White" BorderThickness="1" HorizontalAlignment="Stretch" Margin="30 0 30 10"/>
-							<TextBlock Text="Создай друга" FontSize="24" TextAlignment="Center" Foreground="#FFFFFF" Margin="0 0 0 30"/>
-						</StackPanel>
-					</Button>
-				</Border>
-			</Grid>-->
-
 		</StackPanel>
-
+		<!--Кнопка Далее-->
+		<Border CornerRadius="20" Background="#B21E22" BoxShadow="0 5 #470C0D"
+				Margin="0 20 30 20" HorizontalAlignment="Right" VerticalAlignment="Top">
+			<Button Command="{Binding PlaySectionVM.GoBack}" CornerRadius="20">
+				<TextBlock Text="Выйти" FontSize="28" Foreground="#FFFFFF" Margin="25 15"/>
+			</Button>
+		</Border>
 	</Panel>
 
 </UserControl>

+ 4 - 4
HelloItQuantum/Views/ProgressView.axaml

@@ -15,7 +15,7 @@
 	</UserControl.Styles>
 
 	<Panel HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
-		<Button Command="{Binding HotkeysVM.GoBack}" Width="50" Height="50" VerticalAlignment="Top" CornerRadius="10000" Padding="1" Margin="20 20 0 0">
+		<Button Command="{Binding ProgressVM.GoBack}" Width="50" Height="50" VerticalAlignment="Top" CornerRadius="10000" Padding="1" Margin="20 20 0 0">
 			<Image Source="/Assets/КнопкаНазад.png"/>
 		</Button>
 		<Grid ColumnDefinitions="2*, 13*, 2*" RowDefinitions="*,15,*,15,*" Width="{Binding $parent[Panel].Bounds.Width}" Margin="0 30">
@@ -29,7 +29,7 @@
 							<TextBlock Text="Игра Комманды" FontSize="24" TextAlignment="Center" Foreground="#FFFFFF" Margin="0 0 0 0"/>
 							<!--Прогрессбар игры Горячие клавиши-->
 							<ProgressBar Margin="0 20 0 0" Height="20" Width="{Binding $parent[StackPanel].Bounds.Width}"
-										 Minimum="0" Maximum="100" Value="14" Foreground="#0534B5" Background="#FFFFFF"
+										 Minimum="0" Maximum="100" Value="{Binding ProgressVM.PbGameHotkeys}" Foreground="#0534B5" Background="#FFFFFF"
 										 ShowProgressText="True"
 										 />
 						</StackPanel>
@@ -46,7 +46,7 @@
 							<TextBlock Text="Игра Лабиринт" FontSize="24" TextAlignment="Center" Foreground="#FFFFFF" Margin="0 0 0 0"/>
 							<!--Прогрессбар игры Лабиринт-->
 							<ProgressBar Margin="0 20 0 0" Height="20" Width="{Binding $parent[StackPanel].Bounds.Width}"
-										 Minimum="0" Maximum="100" Value="14" Foreground="#973F19" Background="#FFFFFF"
+										 Minimum="0" Maximum="100" Value="{Binding ProgressVM.PbGameLabyrinth}" Foreground="#973F19" Background="#FFFFFF"
 										 ShowProgressText="True"
 									 />
 						</StackPanel>
@@ -63,7 +63,7 @@
 							<TextBlock Text="Игра Создай друга" FontSize="24" TextAlignment="Center" Foreground="#FFFFFF" Margin="0 0 0 0"/>
 							<!--Прогрессбар игры Лабиринт-->
 							<ProgressBar Margin="0 20 0 0" Height="20" Width="{Binding $parent[StackPanel].Bounds.Width}"
-										 Minimum="0" Maximum="100" Value="14" Foreground="#006838" Background="#FFFFFF"
+										 Minimum="0" Maximum="100" Value="{Binding ProgressVM.PbGameCreateFriend}" Foreground="#006838" Background="#FFFFFF"
 										 ShowProgressText="True"
 									 />
 						</StackPanel>