116 lines
3.3 KiB
C#
116 lines
3.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Runtime.Remoting.Channels;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace gameeee
|
|
{
|
|
public partial class Form1 : Form
|
|
{
|
|
private Random random = new Random();
|
|
private int score = 0;// bpvtytbyt
|
|
private int timeLeft = 60;
|
|
private int interval = 1000;
|
|
private Timer gameTimer = new Timer();
|
|
private Timer buttonTimer = new Timer();
|
|
|
|
public Form1()
|
|
{
|
|
InitializeComponent();
|
|
InitializeGame();
|
|
}
|
|
|
|
private void InitializeGame()
|
|
{
|
|
gameTimer.Interval = 1000;
|
|
gameTimer.Tick += GameTimer_Tick;
|
|
|
|
buttonTimer.Interval = interval;
|
|
buttonTimer.Tick += ButtonTimer_Tick;
|
|
|
|
startButton.Click += (sender, e) =>
|
|
{
|
|
StartGame();
|
|
};
|
|
|
|
foreach (Control control in this.Controls)
|
|
{
|
|
if (control is Button button && button.Name.StartsWith("button") && button != startButton)
|
|
{
|
|
button.Visible = false;
|
|
button.Click += CubeButton_Click;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void StartGame()
|
|
{
|
|
score = 0;
|
|
timeLeft = 60;
|
|
interval = 1000;
|
|
|
|
scoreLabel.Text = "0";
|
|
timeLabel.Text = "60";
|
|
|
|
buttonTimer.Interval = interval;
|
|
buttonTimer.Start();
|
|
gameTimer.Start();
|
|
}
|
|
|
|
private void GameTimer_Tick(object sender, EventArgs e)
|
|
{
|
|
timeLeft--;
|
|
timeLabel.Text = $"{timeLeft}";
|
|
|
|
if (timeLeft <= 0)
|
|
{
|
|
gameTimer.Stop();
|
|
buttonTimer.Stop();
|
|
MessageBox.Show($"Игра окончена! Ваш счет: {score}", "Результат");
|
|
}
|
|
}
|
|
|
|
private void ButtonTimer_Tick(object sender, EventArgs e)
|
|
{
|
|
foreach (Control control in this.Controls)
|
|
{
|
|
if (control is Button button && button.Name.StartsWith("button") && button != startButton)
|
|
{
|
|
button.Visible = false;
|
|
}
|
|
}
|
|
|
|
Button randomButton = this.Controls.Find($"button{random.Next(1, 10)}", true)[0] as Button;
|
|
randomButton.Location = new Point(
|
|
random.Next(this.ClientSize.Width - randomButton.Width),
|
|
random.Next(50, this.ClientSize.Height - randomButton.Height)
|
|
);
|
|
randomButton.Visible = true;
|
|
}
|
|
|
|
private void CubeButton_Click(object sender, EventArgs e)
|
|
{
|
|
Button clickedButton = sender as Button;
|
|
|
|
if (clickedButton != null && clickedButton.Visible)
|
|
{
|
|
score++;
|
|
scoreLabel.Text = $"{score}";
|
|
clickedButton.Visible = false;
|
|
|
|
if (score % 5 == 0 && interval > 300)
|
|
{
|
|
interval -= 100;
|
|
buttonTimer.Interval = interval;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
} |