Размер видео: 1280 X 720853 X 480640 X 360
Показать панель управления
Автовоспроизведение
Автоповтор
очень здорово спасибоможно было бы побольше объяснений, что делает код,а так очень круто
спасибо, учту
легенда
пасиб братик, после армии вернусь мб
Здравствуйте спасибо за крутое видео, вопрос такой можно ли где неб найти код данной игры
Привет, спасибо. Вот код:using System;using System.Collections.Generic;using System.Drawing;using System.Windows.Forms;namespace Find_Pair{ public partial class Form1 : Form { TableLayoutPanel layoutPanel = new TableLayoutPanel(); List icons = new List(); List chars = new List(); Timer mainTimer = new Timer(); Timer timer = new Timer(); int seconds = 25; int countCells = 4; public Form1() { InitializeComponent(); Init(); } bool CheckWin() { foreach (var item in layoutPanel.Controls) { var currentIcon = item as Label; if (currentIcon.ForeColor == currentIcon.BackColor) { return false; } } mainTimer.Stop(); return true; } void CompareLabels(object sender, EventArgs e) { timer.Stop(); if (chars[0].Text != chars[1].Text) { chars[0].ForeColor = chars[0].BackColor; chars[1].ForeColor = chars[0].BackColor; } else if (CheckWin()) { MessageBox.Show("Поздравляю", "Харооош"); } chars.Clear(); } char GetIcon() { var r = new Random(); int t = r.Next(0, icons.Count); char icon = icons[t]; icons.RemoveAt(t); return icon; } void GenerateIcons() { for (char i = 'А'; i < 'А' + countCells * countCells / 2; i++) { icons.Add(i); } for (char i = 'А'; i < 'А' + countCells * countCells / 2; i++) { icons.Add(i); } } void Init() { Text = "Find Pair"; Width = 600; Height = 600; BackColor = Color.Bisque; timer.Interval = 500; timer.Tick += CompareLabels; mainTimer.Interval = 1000; mainTimer.Tick += TimeRedaction; GenerateIcons(); for (int i = 0; i < countCells; i++) { layoutPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 100 / countCells)); layoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100 / countCells)); } layoutPanel.Dock = DockStyle.Fill; layoutPanel.CellBorderStyle = TableLayoutPanelCellBorderStyle.Inset; Controls.Add(layoutPanel); for (int i = 0; i < countCells; i++) { for (int j = 0; j < countCells; j++) { if (!(i == countCells - 1 && j == countCells - 1) || countCells % 2 == 0) layoutPanel.Controls.Add(new Label { Text = GetIcon().ToString(), Font = new Font("Webdings", Width / Convert.ToInt32(countCells * 1.8)), Dock = DockStyle.Fill, BackColor = Color.Bisque, ForeColor = BackColor }, i, j); } } foreach (var item in layoutPanel.Controls) { var currentIcon = item as Label; currentIcon.Click += LabelClick; } } private void TimeRedaction(object sender, EventArgs e) { seconds--; Text = "Find Pair: " + seconds; if (seconds == 0) { mainTimer.Stop(); foreach (var item in layoutPanel.Controls) { var currentIcon = item as Label; currentIcon.Enabled = false; } MessageBox.Show("Поражение"); } } private void LabelClick(object sender, EventArgs e) { if (timer.Enabled) return; mainTimer.Start(); var currentIcon = sender as Label; currentIcon.ForeColor = Color.Black; chars.Add(currentIcon); if (chars.Count == 2) { timer.Start(); } } }}
Максимально убогий код
@@ДанилТемежников Ясно, школьник, учись, все впереди
очень здорово спасибо
можно было бы побольше объяснений, что делает код,а так очень круто
спасибо, учту
легенда
пасиб братик, после армии вернусь мб
Здравствуйте спасибо за крутое видео, вопрос такой можно ли где неб найти код данной игры
Привет, спасибо. Вот код:
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace Find_Pair
{
public partial class Form1 : Form
{
TableLayoutPanel layoutPanel = new TableLayoutPanel();
List icons = new List();
List chars = new List();
Timer mainTimer = new Timer();
Timer timer = new Timer();
int seconds = 25;
int countCells = 4;
public Form1()
{
InitializeComponent();
Init();
}
bool CheckWin()
{
foreach (var item in layoutPanel.Controls)
{
var currentIcon = item as Label;
if (currentIcon.ForeColor == currentIcon.BackColor)
{
return false;
}
}
mainTimer.Stop();
return true;
}
void CompareLabels(object sender, EventArgs e)
{
timer.Stop();
if (chars[0].Text != chars[1].Text)
{
chars[0].ForeColor = chars[0].BackColor;
chars[1].ForeColor = chars[0].BackColor;
}
else if (CheckWin())
{
MessageBox.Show("Поздравляю", "Харооош");
}
chars.Clear();
}
char GetIcon()
{
var r = new Random();
int t = r.Next(0, icons.Count);
char icon = icons[t];
icons.RemoveAt(t);
return icon;
}
void GenerateIcons()
{
for (char i = 'А'; i < 'А' + countCells * countCells / 2; i++)
{
icons.Add(i);
}
for (char i = 'А'; i < 'А' + countCells * countCells / 2; i++)
{
icons.Add(i);
}
}
void Init()
{
Text = "Find Pair";
Width = 600;
Height = 600;
BackColor = Color.Bisque;
timer.Interval = 500;
timer.Tick += CompareLabels;
mainTimer.Interval = 1000;
mainTimer.Tick += TimeRedaction;
GenerateIcons();
for (int i = 0; i < countCells; i++)
{
layoutPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 100 / countCells));
layoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100 / countCells));
}
layoutPanel.Dock = DockStyle.Fill;
layoutPanel.CellBorderStyle = TableLayoutPanelCellBorderStyle.Inset;
Controls.Add(layoutPanel);
for (int i = 0; i < countCells; i++)
{
for (int j = 0; j < countCells; j++)
{
if (!(i == countCells - 1 && j == countCells - 1) || countCells % 2 == 0)
layoutPanel.Controls.Add(new Label
{
Text = GetIcon().ToString(),
Font = new Font("Webdings", Width / Convert.ToInt32(countCells * 1.8)),
Dock = DockStyle.Fill,
BackColor = Color.Bisque,
ForeColor = BackColor
}, i, j);
}
}
foreach (var item in layoutPanel.Controls)
{
var currentIcon = item as Label;
currentIcon.Click += LabelClick;
}
}
private void TimeRedaction(object sender, EventArgs e)
{
seconds--;
Text = "Find Pair: " + seconds;
if (seconds == 0)
{
mainTimer.Stop();
foreach (var item in layoutPanel.Controls)
{
var currentIcon = item as Label;
currentIcon.Enabled = false;
}
MessageBox.Show("Поражение");
}
}
private void LabelClick(object sender, EventArgs e)
{
if (timer.Enabled)
return;
mainTimer.Start();
var currentIcon = sender as Label;
currentIcon.ForeColor = Color.Black;
chars.Add(currentIcon);
if (chars.Count == 2)
{
timer.Start();
}
}
}
}
Максимально убогий код
@@ДанилТемежников Ясно, школьник, учись, все впереди