编写一个WPF应用程序,设计一个有时间限制(25s)的数学测验小游戏。要求玩家必须在规定的时间内回答4道随机出现的加,减,乘,除计算题。如果玩家在规定的时间内全部回答正确,弹出对话框显示“恭喜,过关成功。”,否则弹出对话框显示“过关失败,请继续努力!”。文章来源地址https://www.toymoban.com/news/detail-560275.html
cv我作业能点个赞不能?made by guosenkun
<Window x:Class="WpfApp3MathGame.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp3MathGame"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<GroupBox Header="试题" HorizontalAlignment="Center" VerticalAlignment="Center" Width="500" Height="246"/>
<Label Content="" x:Name="a1" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="200,154,0,0" Height="25" Width="30" />
<Label Content="" x:Name="a2" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="200,184,0,0" Height="25" Width="30" />
<Label Content=" " x:Name="a3" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="200,214,0,0" Height="25" Width="30" />
<Label Content=" " x:Name="a4" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="200,244,0,0" Height="25" Width="30" />
<Label Content="1." HorizontalAlignment="Left" VerticalAlignment="Top" Margin="179,154,0,0" Height="25" Width="40" />
<Label Content=" 2." HorizontalAlignment="Left" VerticalAlignment="Top" Margin="165,184,0,0" Height="25" Width="50" />
<Label Content=" 3." HorizontalAlignment="Left" VerticalAlignment="Top" Margin="158,214,0,0" Height="25" Width="50" />
<Label Content=" 4. " HorizontalAlignment="Left" VerticalAlignment="Top" Margin="162,244,0,0" Height="25" Width="50" />
<Label Content="" x:Name="b1" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="250,154,0,0" Height="25" Width="30" />
<Label Content="" x:Name="b2" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="250,184,0,0" Height="25" Width="30" />
<Label Content=" " x:Name="b3" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="250,214,0,0" Height="25" Width="30" />
<Label Content=" " x:Name="b4" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="250,244,0,0" Height="25" Width="30" />
<Label Content="+" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="225,154,0,0" Height="25" Width="30" />
<Label Content="-" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="225,184,0,0" Height="25" Width="30" />
<Label Content="* " HorizontalAlignment="Left" VerticalAlignment="Top" Margin="225,214,0,0" Height="25" Width="30" />
<Label Content="/ " HorizontalAlignment="Left" VerticalAlignment="Top" Margin="225,244,0,0" Height="25" Width="30" />
<Label Content="=" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="270,154,0,0" Height="25" Width="30" />
<Label Content="=" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="270,184,0,0" Height="25" Width="30" />
<Label Content="=" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="270,214,0,0" Height="25" Width="30" />
<Label Content="=" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="270,244,0,0" Height="25" Width="30" />
<Label Content="剩余时间:" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="400,50,0,0" Height="25" Width="75" />
<Button x:Name="start" Click="start_Click" Content="生成试题并开始计时" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="250,50,0,0" Height="25" Width="120" />
<Button x:Name="sumbit" Click="sumbit_Click" Content="确认提交" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="350,370,0,0" Width="100" Height="25" />
<TextBox x:Name="text1" Text="" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="300,154,0,0" Width="130" Height="25"/>
<TextBox x:Name="text2" Text="" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="300,184,0,0" Width="130" Height="25"/>
<TextBox x:Name="text3" Text="" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="300,214,0,0" Width="130" Height="25"/>
<TextBox x:Name="text4" Text="" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="300,244,0,0" Width="130" Height="25"/>
<TextBox x:Name="texttime" Text="" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="499,51,0,0" Width="54" Height="35"/>
</Grid>
</Window>
using System;
using System.Timers;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
namespace WpfApp3MathGame
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
DispatcherTimer dt = new DispatcherTimer {
Interval=TimeSpan.FromSeconds(1)
};
int a = 25;
public MainWindow()
{
InitializeComponent();
dt.Tick += (s, e) =>
{
texttime.Text = a.ToString();
a--;
if (a == -1)
{
dt.Stop();
MessageBox.Show("时间到,考试结束");
}
};
}
private void sumbit_Click(object sender, RoutedEventArgs e)
{
dt.Start();
int aa1=Convert.ToInt32(a1.Content);
int aa2 = Convert.ToInt32(a2.Content);
int aa3 = Convert.ToInt32(a3.Content);
int aa4 = Convert.ToInt32(a4.Content);
int bb1 = Convert.ToInt32(b1.Content);
int bb2 = Convert.ToInt32(b2.Content);
int bb3 = Convert.ToInt32(b3.Content);
int bb4 = Convert.ToInt32(b4.Content);
if (aa1 + bb1 ==int.Parse(text1.Text)&& aa2 - bb2 == int.Parse(text2.Text)
&& aa3 * bb3 == int.Parse(text3.Text)&& aa4 /bb4 == int.Parse(text4.Text))
{
MessageBox.Show("恭喜你,全部答对");
}
else
{
MessageBox.Show("抱歉,你有题答错了");
}
}
private void start_Click(object sender, RoutedEventArgs e)
{
dt.Start();
Random r = new Random();
a1.Content = r.Next(1, 10);
a2.Content = r.Next(1, 10);
a3.Content = r.Next(1, 10);
a4.Content = r.Next(1, 10);
b1.Content = r.Next(1, 10);
b2.Content = r.Next(1, 10);
b3.Content = r.Next(1, 10);
b4.Content = r.Next(1, 10);
}
}
}
文章来源:https://www.toymoban.com/news/detail-560275.html
到了这里,关于25s数学测试小游戏的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!