当前位置:   article > 正文

25s数学测试小游戏_编写一个wpf应用程序,设计一个有时间限制(25s)的数学测验小游戏。要求玩家必须在

编写一个wpf应用程序,设计一个有时间限制(25s)的数学测验小游戏。要求玩家必须在

编写一个WPF应用程序,设计一个有时间限制(25s)的数学测验小游戏。要求玩家必须在规定的时间内回答4道随机出现的加,减,乘,除计算题。如果玩家在规定的时间内全部回答正确,弹出对话框显示“恭喜,过关成功。”,否则弹出对话框显示“过关失败,请继续努力!”

cv我作业能点个赞不能?made by guosenkun

  1. <Window x:Class="WpfApp3MathGame.MainWindow"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  5. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  6. xmlns:local="clr-namespace:WpfApp3MathGame"
  7. mc:Ignorable="d"
  8. Title="MainWindow" Height="450" Width="800">
  9. <Grid>
  10. <GroupBox Header="试题" HorizontalAlignment="Center" VerticalAlignment="Center" Width="500" Height="246"/>
  11. <Label Content="" x:Name="a1" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="200,154,0,0" Height="25" Width="30" />
  12. <Label Content="" x:Name="a2" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="200,184,0,0" Height="25" Width="30" />
  13. <Label Content=" " x:Name="a3" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="200,214,0,0" Height="25" Width="30" />
  14. <Label Content=" " x:Name="a4" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="200,244,0,0" Height="25" Width="30" />
  15. <Label Content="1." HorizontalAlignment="Left" VerticalAlignment="Top" Margin="179,154,0,0" Height="25" Width="40" />
  16. <Label Content=" 2." HorizontalAlignment="Left" VerticalAlignment="Top" Margin="165,184,0,0" Height="25" Width="50" />
  17. <Label Content=" 3." HorizontalAlignment="Left" VerticalAlignment="Top" Margin="158,214,0,0" Height="25" Width="50" />
  18. <Label Content=" 4. " HorizontalAlignment="Left" VerticalAlignment="Top" Margin="162,244,0,0" Height="25" Width="50" />
  19. <Label Content="" x:Name="b1" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="250,154,0,0" Height="25" Width="30" />
  20. <Label Content="" x:Name="b2" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="250,184,0,0" Height="25" Width="30" />
  21. <Label Content=" " x:Name="b3" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="250,214,0,0" Height="25" Width="30" />
  22. <Label Content=" " x:Name="b4" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="250,244,0,0" Height="25" Width="30" />
  23. <Label Content="+" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="225,154,0,0" Height="25" Width="30" />
  24. <Label Content="-" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="225,184,0,0" Height="25" Width="30" />
  25. <Label Content="* " HorizontalAlignment="Left" VerticalAlignment="Top" Margin="225,214,0,0" Height="25" Width="30" />
  26. <Label Content="/ " HorizontalAlignment="Left" VerticalAlignment="Top" Margin="225,244,0,0" Height="25" Width="30" />
  27. <Label Content="=" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="270,154,0,0" Height="25" Width="30" />
  28. <Label Content="=" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="270,184,0,0" Height="25" Width="30" />
  29. <Label Content="=" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="270,214,0,0" Height="25" Width="30" />
  30. <Label Content="=" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="270,244,0,0" Height="25" Width="30" />
  31. <Label Content="剩余时间:" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="400,50,0,0" Height="25" Width="75" />
  32. <Button x:Name="start" Click="start_Click" Content="生成试题并开始计时" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="250,50,0,0" Height="25" Width="120" />
  33. <Button x:Name="sumbit" Click="sumbit_Click" Content="确认提交" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="350,370,0,0" Width="100" Height="25" />
  34. <TextBox x:Name="text1" Text="" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="300,154,0,0" Width="130" Height="25"/>
  35. <TextBox x:Name="text2" Text="" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="300,184,0,0" Width="130" Height="25"/>
  36. <TextBox x:Name="text3" Text="" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="300,214,0,0" Width="130" Height="25"/>
  37. <TextBox x:Name="text4" Text="" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="300,244,0,0" Width="130" Height="25"/>
  38. <TextBox x:Name="texttime" Text="" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="499,51,0,0" Width="54" Height="35"/>
  39. </Grid>
  40. </Window>
  1. using System;
  2. using System.Timers;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Navigation;
  15. using System.Windows.Shapes;
  16. using System.Windows.Threading;
  17. namespace WpfApp3MathGame
  18. {
  19. /// <summary>
  20. /// Interaction logic for MainWindow.xaml
  21. /// </summary>
  22. public partial class MainWindow : Window
  23. {
  24. DispatcherTimer dt = new DispatcherTimer {
  25. Interval=TimeSpan.FromSeconds(1)
  26. };
  27. int a = 25;
  28. public MainWindow()
  29. {
  30. InitializeComponent();
  31. dt.Tick += (s, e) =>
  32. {
  33. texttime.Text = a.ToString();
  34. a--;
  35. if (a == -1)
  36. {
  37. dt.Stop();
  38. MessageBox.Show("时间到,考试结束");
  39. }
  40. };
  41. }
  42. private void sumbit_Click(object sender, RoutedEventArgs e)
  43. {
  44. dt.Start();
  45. int aa1=Convert.ToInt32(a1.Content);
  46. int aa2 = Convert.ToInt32(a2.Content);
  47. int aa3 = Convert.ToInt32(a3.Content);
  48. int aa4 = Convert.ToInt32(a4.Content);
  49. int bb1 = Convert.ToInt32(b1.Content);
  50. int bb2 = Convert.ToInt32(b2.Content);
  51. int bb3 = Convert.ToInt32(b3.Content);
  52. int bb4 = Convert.ToInt32(b4.Content);
  53. if (aa1 + bb1 ==int.Parse(text1.Text)&& aa2 - bb2 == int.Parse(text2.Text)
  54. && aa3 * bb3 == int.Parse(text3.Text)&& aa4 /bb4 == int.Parse(text4.Text))
  55. {
  56. MessageBox.Show("恭喜你,全部答对");
  57. }
  58. else
  59. {
  60. MessageBox.Show("抱歉,你有题答错了");
  61. }
  62. }
  63. private void start_Click(object sender, RoutedEventArgs e)
  64. {
  65. dt.Start();
  66. Random r = new Random();
  67. a1.Content = r.Next(1, 10);
  68. a2.Content = r.Next(1, 10);
  69. a3.Content = r.Next(1, 10);
  70. a4.Content = r.Next(1, 10);
  71. b1.Content = r.Next(1, 10);
  72. b2.Content = r.Next(1, 10);
  73. b3.Content = r.Next(1, 10);
  74. b4.Content = r.Next(1, 10);
  75. }
  76. }
  77. }

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号