-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFormGame15.cs
85 lines (80 loc) · 2.43 KB
/
FormGame15.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Game15
{
public partial class FormGame15 : Form
{
Game game = new Game();
public FormGame15()
{
InitializeComponent();
}
private void FormGame15_Load(object sender, EventArgs e)
{
StartGame();
}
private void menu_start_Click(object sender, EventArgs e)
{
StartGame();
}
private void button15_Click(object sender, EventArgs e)
{
int position = Convert.ToInt16(((Button)sender).Tag);
game.CountSteps();
game.Shift(position);
Refresh();
if (game.CheckNumbers())
{
MessageBox.Show("Поздравляем! Вы победили!\nКоличество шагов: " + game.CountSteps().ToString());
game.RefreshCount();
StartGame();
}
}
private Button ButtonPosition (int position)
{
switch (position)
{
case 0: return button0;
case 1: return button1;
case 2: return button2;
case 3: return button3;
case 4: return button4;
case 5: return button5;
case 6: return button6;
case 7: return button7;
case 8: return button8;
case 9: return button9;
case 10: return button10;
case 11: return button11;
case 12: return button12;
case 13: return button13;
case 14: return button14;
case 15: return button15;
default: return null;
}
}
private void StartGame()
{
game.Start();
for (int j = 0; j < 100; j++)
game.ShiftRandom();
Refresh();
}
private void Refresh()
{
for (int position = 0; position < 16; position++)
{
int nr = game.GetNumber(position);
ButtonPosition(position).Text = nr.ToString();
ButtonPosition(position).Visible = (nr > 0);
}
}
}
}