LabyrinthViewModel.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Media;
  5. using Avalonia;
  6. using Avalonia.Controls;
  7. using Avalonia.Controls.Shapes;
  8. using Avalonia.Media;
  9. using ExCSS;
  10. using HelloItQuantum.Function;
  11. using HelloItQuantum.Views;
  12. namespace HelloItQuantum.ViewModels
  13. {
  14. public class LabyrinthViewModel : MainWindowViewModel
  15. {
  16. List<string> listContent = new List<string>();
  17. bool isVisibleContextWindow = true;
  18. string textInSP = "Æèë-áûë ðîáîò Ðàêåòà. Îí õîòåë ïîìî÷ü ïðîôåññîðó íà ñòàíöèè, íî ìåæäó íèìè áûë ëàáèðèíò èç îðàíæåâûõ è êðàñíûõ êëåòîê. Ðàêåòà ìîã èäòè òîëüêî ïî îðàíæåâûì, èçáåãàÿ êðàñíûõ. Ïîìîãè Ðàêåòå äîáðàòüñÿ äî ñòàíöèè ïðîôåññîðà.";
  19. string textInBTN = "Äàëåå";
  20. string pathAudio = $"LabyrinthAudio\\voice_start.wav";
  21. StackPanel listCommandForRobots = new StackPanel();
  22. public StackPanel ListCommandForRobots { get => listCommandForRobots; set => SetProperty(ref listCommandForRobots, value); }
  23. public bool IsVisibleContextWindow { get => isVisibleContextWindow; set => SetProperty(ref isVisibleContextWindow, value); }
  24. public string TextInSP { get => textInSP; set => SetProperty(ref textInSP, value); }
  25. public string TextInBTN { get => textInBTN; set => SetProperty(ref textInBTN, value); }
  26. /// <summary>
  27. /// Ôóíêöèÿ çàïóñêà àóäèî
  28. /// </summary>
  29. public void PlayTask()
  30. {
  31. SoundPlayer snd = new SoundPlayer(pathAudio);
  32. snd.Play();
  33. }
  34. public void GoNext()
  35. {
  36. IsVisibleContextWindow = false;
  37. }
  38. /// <summary>
  39. /// Âåðíóòüñÿ â ãëàâíîå ìåíþ
  40. /// </summary>
  41. public void GoBack()
  42. {
  43. PageSwitch.View = new PlaySectionView();
  44. }
  45. /// <summary>
  46. /// Äîáàâëåíèå ñïèñêà êîìàíä ïðè íàæàòèè íà êíîïêó
  47. /// </summary>
  48. /// <param name="comand">ïåðåäàâàåìàÿ êîìàíäà (âëåâî, âïðàâî, âíèç, ââåðõ)</param>
  49. public void AddButton(string comand)
  50. {
  51. ListCommandForRobots.HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center;
  52. TextBlock tb = new TextBlock();
  53. tb.Text = "go " + comand;
  54. tb.TextAlignment = TextAlignment.Center;
  55. tb.FontSize = 24;
  56. tb.Width = 150;
  57. tb.Margin = new Thickness(10);
  58. Border border = new Border();
  59. border.CornerRadius = new CornerRadius(20);
  60. border.Background = new SolidColorBrush(Avalonia.Media.Color.FromArgb(242, 101, 39, 0));
  61. border.Child = tb;
  62. border.Margin = new Thickness(5);
  63. ListCommandForRobots.Children.Add(border);
  64. listContent.Add(tb.Text);
  65. }
  66. /// <summary>
  67. /// Î÷èùåíèå ñïèñêà êîìàíä äëÿ ðîáîòà
  68. /// </summary>
  69. public void DeleteCommand() {
  70. ListCommandForRobots.Children.Clear();
  71. listContent.Clear();
  72. }
  73. /// <summary>
  74. /// Ïðîâåðêà ïðàâèëüíîñòè ñïèñêà êîìàíä
  75. /// </summary>
  76. public void CheckCommand()
  77. {
  78. //ListCommandForRobots.Children.Clear();
  79. var c = ListCommandForRobots.Children;
  80. bool googCommands = true;
  81. if (listContent.Count < 9)
  82. {
  83. googCommands = false;
  84. }
  85. else {
  86. for (int i = 0; i < listContent.Count; i++) {
  87. if (listContent[0] != "go right") {
  88. googCommands = false; break;
  89. }
  90. if (listContent[1] != "go right")
  91. {
  92. googCommands = false; break;
  93. }
  94. if (listContent[2] != "go up")
  95. {
  96. googCommands = false; break;
  97. }
  98. if (listContent[3] != "go up")
  99. {
  100. googCommands = false; break;
  101. }
  102. if (listContent[4] != "go left")
  103. {
  104. googCommands = false; break;
  105. }
  106. if (listContent[5] != "go up")
  107. {
  108. googCommands = false; break;
  109. }
  110. if (listContent[6] != "go up")
  111. {
  112. googCommands = false; break;
  113. }
  114. if (listContent[7] != "go right")
  115. {
  116. googCommands = false; break;
  117. }
  118. if (listContent[8] != "go right")
  119. {
  120. googCommands = false; break;
  121. }
  122. }
  123. }
  124. if (googCommands)
  125. {
  126. WorkWithFile.UpdateValueGameProgress(2, 100, CurrentUser);
  127. pathAudio = $"LabyrinthAudio\\voice_win.wav";
  128. TextInSP = "Çäîðîâî! Ðàêåòà îêàçàëñÿ íà èññëåäîâàòåëüñêîé ñòàíöèè è ïîìîã ïðîôåññîðó ïî÷èíèòü ëàáîðàòîðèþ. Ìèññèÿ âûïîëíåíà!";
  129. IsVisibleContextWindow = true;
  130. TextInBTN = "Çàêðûòü";
  131. }
  132. else {
  133. TextInSP = "Ê ñîæàëåíèþ, Ðàêåòà çàáëóäèëñÿ è íå äîáðàëñÿ äî èññëåäîâàòåëüñêîé ñòàíöèè. Íå îò÷àèâàéñÿ! Ïîïðîáóé çàíîâî!";
  134. pathAudio = $"LabyrinthAudio\\voice_loss.wav";
  135. IsVisibleContextWindow = true;
  136. TextInBTN = "Çàêðûòü";
  137. }
  138. }
  139. }
  140. }