Экземпляр
класса является фигурой на игровой доске
|
Shape
|
Экземпляр
класса является основным обработчиком алгоритмов тетриса
|
Build
|
Экземпляр
класса является танком на игровой доске
|
Tank
|
Экземпляр
класса является пулей на игровой доске
|
Shot
|
Экземпляр
класса является основным обработчиком алгоритмов игры «Гонки(танки)»
|
Tanks
|
Экземпляр
класса является главным GUIокном
приложения
|
MainWindow
|
5. Блок-схема алгоритма
Блок-схема функции voidLineRem()
- функция удаляет заполненные линии в игре «стройка» и опускает «постройку» в
низ.
Рис.
Блок-схема функции voidcheckCoord(int[,]
m)
- функция проверяет не вышли ли координаты фигурыза границы игровой доски.
Рис.
6. Алгоритмы функций
Алгоритм функции voidMainWindow_FormClosing(objectsender,
FormClosingEventArgse)-функция закрывает все активные потоки и закрывает
программу.
1. Начало.
Входные данные:
sender- системный
объект типа objectкоторый
вызвал событие.
e - объект типа EventArgs-
системные аргументы произошедшего события.
game- объект
класса MainWindow
типа stringхранящий
название запущенной игры.
Buld_ -объект
класса MainWindowтипа
Buildдля запуска игры
«стройка».
Tanks_- объект
класса MainWindowтипа
Tanks_ для запуска игры
«гонки(танки)».
2. if(game
== «Build») если
текущая игра «стройка» то выполняем пункт 3 иначе переходим к пункту8.
3. if
(Build_.thr
!= null) если поток игры
«стройка» запущен то выполняем пункт 4 иначе переходим к пункту 8.
4. if
(Build_.thr.ThreadState
== System.Threading.ThreadState.Suspended)еслипотокнаходитсявсостоянии
«паузы» то выполняем пункты 5-6 иначе переходим к пункту 7.
5. Build_.thr.Resume();
восстанавливаем поток.
6. Build_.thr.Abort();
останавливаем поток полностью.
7. Build_.thr.Abort();
останавливаем поток полностью.
8. if
(game == «Tanks»
&&Tanks_ != null)
если текущая игра «гонки(танки)» и объект класса MainWindowTanks_
инициализирован то выполняем пункт 9 иначе переходим к пункту 19.
9. if
(Tanks_.thr != null) если поток игры «гонки(танки)» инициализирован то выполняем
10 пункт иначе переходим к пункту 19.
10. if
(Tanks_.thr.ThreadState == System.Threading.ThreadState.Suspended) если поток
находится в состоянии «паузы» то выполняем пункты 11 - иначе переходим к пункту
16.
11. Tanks_.thr.Resume();
восстанавливаем поток.
12. Tanks_.thr.Abort();
останавливаем поток полностью.
13. thrTime.Resume();
восстанавливаем поток.
14. thrTime.Abort();
останавливаем поток полностью.
15. label11.Text
= «0»; обнуляем таймер.
16. Tanks_.thr.Abort();
останавливаем поток полностью.
17. thrTime.Abort();
останавливаем поток полностью.
18. label11.Text
= «0»; обнуляем таймер.
19. Конец.
АлгоритмфункцииvoidStartTanks(objectsender,
EventArgse)- функциязапускает или останавливает игру гонки(танки).
1. Начало.
Входные данные:
sender- системный
объект типа objectкоторый
вызвал событие.
e - объект типа EventArgs-
системные аргументы произошедшего события.
Tanks_ -объект
класса MainWindowтипа
Tanks для запуска игры
«гонки(танки)».
thrTime
- объект класса MainWindowтипа
Threadдля запуска таймера
в отдельном потоке.
richTextBox1,
richTextBox2 - объекты класса MainWindowтипа
RichTextBox содержащие имена
игроков.
2. if
(Tanks_ == null) если объект игры «гонки(танки)» не инициализирован то
выполняем пункты 3-9 иначе переходим к 10 пункту.
3. checkBox2.Text
= «Stop»; помечаем кнопку запуска теперь как кнопку остановки.
4. Tanks_
= newTanks(); инициализируем объект Tanks_.
5. Tanks_.Start();
запускаем игру «гонки(танки)».
6. richTextBox1.Enabled
= false; закрываем доступ для изменения имени игрока 1.
7. richTextBox2.Enabled
= false; закрываем доступ для изменения имени игрока 2.
8. Tanks_.Tank_1.name
= richTextBox2.Text; приваиваемимятанку 2.
9. Tanks_.Tank_.name
= richTextBox1.Text; приваиваемимятанку 1.
10. checkBox2.Text
= «Start»; помечаем кнопку остановки теперь как кнопку запуска.
11. Tanks_.thr.Abort();
останавливаем поток в котором выполняется игра «гонки(танки)».
12. Tanks_.ClearTable();
чистим игровую доску.
13. Tanks_
= null; обнуляем объект игры «гонки(танки)».
14. thrTime.Abort();
останавливаем поток в котором выполнялся таймер.
15. label11.Text
= «0»; обнуляем таймер
16. richTextBox1.Enabled
= true; открываем доступ для изменения имени игрока 1.
17. richTextBox2.Enabled
= true; открываем доступ для изменения имени игрока 2.
18. Конец
. Результат работы программы
Рисунок 7.2 - начало игры в гонки
Рисунок 7.3 - игровой процесс
Рисунок 7.4 - конец игры
Рисунок 7.5 - начало игры в стройку
Рисунок 7.6 - игровой процесс
Рисунок 7.7 - конец игры
Приложение А
Листинг программы
КлассShape - отвечает за падающую фигуру в игре
«стройка».System;System.Collections.Generic;System.Linq;System.Text;System.Threading.Tasks;System.Drawing;System.Drawing.Drawing2D;TetrixSystem
{
{lastShape = 0;count = 0;nextShape = 0;state =
1;d = true;[,] coord = {
{0,0}, //x,y
{0,0},
{0,0},
{0,0},
};[,] tcoord = {
{0,0}, //x,y
{0,0},
{0,0},
{0,0},
};left()
{( coord[0, 0] == 0 || coord[1, 0] == 0 ||
coord[2, 0] == 0 || coord[3, 0] == 0);x = 0;y = 0;x1 = 0;y1 = 0;f = false;(int
i = 0;i < 4; i++)
{
x = coord[i, 0];
y = coord[i, 1];(MainWindow.table[x - 1, y] ==
true)
{(int j = 0; j < 4; j++)
{
x1 = coord[j, 0];
y1 = coord[j, 1];(x - 1 == x1 && y ==
y1)
{
f = true;;
}
}(!f) return;
f = false;
}
}();
coord[0, 0]--;
coord[1, 0]--;
coord[2, 0]--;
coord[3, 0]--;
toTable();.Inv();
}right()
{(coord[0, 0] == 9 || coord[1, 0] == 9 ||
coord[2, 0] == 9 || coord[3, 0] == 9);x = 0;y = 0;x1 = 0;y1 = 0;f = false;(int
i = 0; i < 4; i++)
{
x = coord[i, 0];
y = coord[i, 1];(MainWindow.table[x + 1, y] ==
true)
{(int j = 0; j < 4; j++)
{
x1 = coord[j, 0];
y1 = coord[j, 1];(x + 1 == x1 && y ==
y1)
{
f = true;;
}
}(!f) return;
f = false;
}
}();
coord[0, 0]++;
coord[1, 0]++;
coord[2, 0]++;
coord[3, 0]++;
toTable();.Inv();
}down()
{(coord[0, 1] == 18 || coord[1, 1] == 18 ||
coord[2, 1] == 18 || coord[3, 1] == 18);x = 0;y = 0;x1 = 0;y1 = 0;f =
false;(int i = 0; i < 4; i++)
{
x = coord[i, 0];
y = coord[i, 1];(MainWindow.table[x, y + 1] ==
true)
{(int j = 0; j < 4; j++)
{
x1 = coord[j, 0];
y1 = coord[j, 1];(x == x1 && y + 1 ==
y1)
{
f = true;;
}
}(!f);
f = false;
}
}();
coord[0, 1]++;
coord[1, 1]++;
coord[2, 1]++;
coord[3, 1]++;
toTable();.Inv();;
}x(int index) { return coord[index, 0]; }y(int
index) { return coord[index, 1]; }setX(int index, int x) { coord[index, 0] = x;
}setY(int index, int y) { coord[index, 1] = y; }tmoveCoord(int id, string d,
int c = 1)
{(int i = 0; i < c; i++)
{(d)
{"Left":
tcoord[id, 0] = tcoord[id, 0] -
1;break;"Right":
tcoord[id, 0] = tcoord[id, 0] +
1;break;"Up":
tcoord[id, 1] = tcoord[id, 1] -
1;break;"Down":
tcoord[id, 1] = tcoord[id, 1] + 1;break;
}
}
}setCoord(int x1, int y1, int x2, int y2, int
x3, int y3, int x4, int y4)
{
coord[0, 0] = x1;
coord[0, 1] = y1;
coord[1, 0] = x2;
coord[1, 1] = y2;
coord[2, 0] = x3;
coord[2, 1] = y3;
coord[3, 0] = x4;
coord[3, 1] = y4;
}copy(int[,] m1, int[,] m2)
{(int i = 0; i < 4; i++)
{(int j = 0; j < 2; j++)
{
m1[i, j] = m2[i, j];
}
}
}checkCoord(int[,] m)
{(int i = 0; i < 4; i++)
{(m[i, 0] < 0 || m[i, 0] > 9);(m[i, 1]
< 0 || m[i, 1] > 18);(MainWindow.table[m[i, 0], m[i, 1]] == true)
{f = false;(int i_ = 0; i_ < 4; i_++)
{(m[i, 0] == coord[i_, 0] && m[i, 1] ==
coord[i_, 1])
f = true;
}(!f);
}
};rotate_left()
{(lastShape == 1);
copy(tcoord, coord);
(lastShape)
{2: // палка(state == 1)
{
tmoveCoord(2, "Down");
tmoveCoord(2, "Left");
tmoveCoord(1, "Down", 2);
tmoveCoord(1, "Right");
tmoveCoord(0, "Down", 3);
tmoveCoord(0, "Right",
2);(!checkCoord(tcoord));
remove();
state = 2;
copy(coord, tcoord);
}(state == 2)
{
tmoveCoord(2, "Up");
tmoveCoord(2, "Right");
tmoveCoord(1, "Up", 2);
tmoveCoord(1, "Left");
tmoveCoord(0, "Up", 3);
tmoveCoord(0, "Left",
2);(!checkCoord(tcoord));
remove();
state = 1;
copy(coord, tcoord);
};6: //левая(state == 1)
{
tmoveCoord(2, "Up");
tmoveCoord(3, "Right", 2);
tmoveCoord(3,
"Up");(!checkCoord(tcoord));
remove();
state = 2;
copy(coord, tcoord);
}(state == 2)
{
tmoveCoord(2, "Down");
tmoveCoord(3, "Left", 2);
tmoveCoord(3,
"Down");(!checkCoord(tcoord));
remove();
state = 1;
copy(coord, tcoord);
};7: //правая(state == 1)
{(0, "Right");
tmoveCoord(3, "Right");
tmoveCoord(3, "Up",
2);(!checkCoord(tcoord));
remove();
state = 2;
copy(coord, tcoord);
}(state == 2)
{
tmoveCoord(0, "Left");
tmoveCoord(3, "Left");
tmoveCoord(3, "Down", 2);(!checkCoord(tcoord));
remove();
state = 1;
copy(coord, tcoord);
};3: //_|_(state == 1)
{
tmoveCoord(1, "Right");
tmoveCoord(1, "Up");
tmoveCoord(2, "Right", 2);
tmoveCoord(2, "Up",
2);(!checkCoord(tcoord));
remove();
state = 2;
copy(coord, tcoord);
}(state == 2)
{
tmoveCoord(1, "Up");
tmoveCoord(1, "Left");
tmoveCoord(3, "Left", 2);
tmoveCoord(3, "Up",
2);(!checkCoord(tcoord));
remove();
state = 3;
copy(coord, tcoord);
}(state == 3)
{
tmoveCoord(1, "Left");
tmoveCoord(1, "Down");
tmoveCoord(2, "Down", 2);
tmoveCoord(2, "Left",
2);(!checkCoord(tcoord));
remove();
state = 4;
copy(coord, tcoord);
}(state == 4)
{
tmoveCoord(1, "Down");
tmoveCoord(1, "Right");
tmoveCoord(3, "Down", 2);
tmoveCoord(3, "Right",
2);(!checkCoord(tcoord));
remove();
state = 1;
copy(coord, tcoord);
};4:(state == 1)
{
tmoveCoord(2, "Right");
tmoveCoord(3, "Left");
tmoveCoord(0, "Right", 2);
tmoveCoord(0, "Down");
tmoveCoord(1, "Right", 2);
tmoveCoord(1,
"Down");(!checkCoord(tcoord));
remove();
state = 2;
copy(coord, tcoord);
}(state == 2)
{
tmoveCoord(3, "Up", 2);
tmoveCoord(3, "Right");
tmoveCoord(2, "Up", 2);
tmoveCoord(2,
"Right");(!checkCoord(tcoord));
remove();
state = 3;
}(state == 3)
{
tmoveCoord(0, "Left", 2);
tmoveCoord(0, "Up", 1);
tmoveCoord(1, "Left", 2);
tmoveCoord(1,
"Up");(!checkCoord(tcoord));
remove();
state = 4;
copy(coord, tcoord);
}(state == 4)
{
tmoveCoord(3, "Down", 2);
tmoveCoord(2, "Down", 2);
tmoveCoord(2, "Left",
2);(!checkCoord(tcoord));
remove();
state = 1;
copy(coord, tcoord);
};5:(state == 1)
{
tmoveCoord(2, "Left");
tmoveCoord(2, "Up", 2);
tmoveCoord(3, "Left");
tmoveCoord(3, "Up",
2);(!checkCoord(tcoord));
remove();
state = 2;
copy(coord, tcoord);
}(state == 2)
{
tmoveCoord(0, "Down");
tmoveCoord(0, "Left", 2);
tmoveCoord(1, "Down");
tmoveCoord(1, "Left",
2);(!checkCoord(tcoord));
remove();
state = 3;
copy(coord, tcoord);
}(state == 3)
{
tmoveCoord(2, "Down", 2);
tmoveCoord(3, "Right", 2);
tmoveCoord(3, "Down",
2);(!checkCoord(tcoord));
remove();
state = 4;
copy(coord, tcoord);
}(state == 4)
{
tmoveCoord(2, "Right");
tmoveCoord(3, "Left");
tmoveCoord(1, "Up");
tmoveCoord(1, "Right", 2);
tmoveCoord(0, "Up");
tmoveCoord(0, "Right",
2);(!checkCoord(tcoord));
remove();
state = 1;
copy(coord, tcoord);
};
}();.Inv();
}rotate_right()
{(lastShape == 1);
copy(tcoord, coord);
(lastShape)
{2:
rotate_left();;6:
rotate_left();;7:
rotate_left();;3: //_|_(state == 1)
{
tmoveCoord(1, "Left");
tmoveCoord(1, "Up");
tmoveCoord(3, "Left", 2);
tmoveCoord(3, "Up",
2);(!checkCoord(tcoord));
state = 4;
remove();
copy(coord, tcoord);
}(state == 4)
{(1, "Up");
tmoveCoord(1, "Right");
tmoveCoord(2, "Right", 2);
tmoveCoord(2, "Up",
2);(!checkCoord(tcoord));
state = 3;
remove();
copy(coord, tcoord);
}(state == 3)
{
tmoveCoord(1, "Right");
tmoveCoord(1, "Down");
tmoveCoord(3, "Down", 2);
tmoveCoord(3, "Right",
2);(!checkCoord(tcoord));
state = 2;
remove();
copy(coord, tcoord);
}(state == 2)
{
tmoveCoord(1, "Down");
tmoveCoord(1, "Left");
tmoveCoord(2, "Down", 2);
tmoveCoord(2, "Left", 2);(!checkCoord(tcoord));
state = 1;
remove();
copy(coord, tcoord);
};4:(state == 1)
{
tmoveCoord(3, "Up", 2);
tmoveCoord(2, "Right", 2);
tmoveCoord(2, "Up",
2);(!checkCoord(tcoord));
state = 4;
remove();
copy(coord, tcoord);
}(state == 4)
{
tmoveCoord(0, "Down");
tmoveCoord(1, "Down");
tmoveCoord(0, "Right", 2);
tmoveCoord(1, "Right",
2);(!checkCoord(tcoord));
state = 3;
remove();
copy(coord, tcoord);
}(state == 3)
{
tmoveCoord(3, "Left");
tmoveCoord(3, "Down", 2);
tmoveCoord(2, "Left");
tmoveCoord(2, "Down",
2);(!checkCoord(tcoord));
state = 2;
remove();
copy(coord, tcoord);
}(state == 2)
{
tmoveCoord(0, "Up");
tmoveCoord(1, "Up");
tmoveCoord(0, "Left", 2);
tmoveCoord(1, "Left", 2);
tmoveCoord(2, "Left");
tmoveCoord(3, "Right");(!checkCoord(tcoord));
state = 1;
remove();
copy(coord, tcoord);
};5:(state == 1)
{
tmoveCoord(2, "Left");
tmoveCoord(3, "Right");
tmoveCoord(1, "Left", 2);
tmoveCoord(1, "Down");
tmoveCoord(0, "Left", 2);
tmoveCoord(0,
"Down");(!checkCoord(tcoord));
state = 4;
remove();
copy(coord, tcoord);
}(state == 4)
{
tmoveCoord(2, "Up", 2);
tmoveCoord(3, "Up", 2);
tmoveCoord(3, "Left",
2);(!checkCoord(tcoord));
state = 3;
remove();
copy(coord, tcoord);
}(state == 3)
{
tmoveCoord(0, "Right", 2);
tmoveCoord(0, "Up");
tmoveCoord(1, "Right", 2);
tmoveCoord(1,
"Up");(!checkCoord(tcoord));
state = 2;
remove();
copy(coord, tcoord);
}(state == 2)
tmoveCoord(2, "Down", 2);
tmoveCoord(2, "Right");
tmoveCoord(3, "Down", 2);
tmoveCoord(3,
"Right");(!checkCoord(tcoord));
state = 1;
remove();
copy(coord, tcoord);;
}();.Inv();
}remove()
{x = 0;y = 0;(int i = 0; i < 4; i++)
{
x = coord[i, 0];
y = coord[i, 1];.table[x, y] = false;
}
}clear()
{(int i = 0; i < 4; i++)
{
coord[i, 0] = coord[i, 1] = 0;
}
lastShape = count = nextShape = 0;
}toTable()
{(int i = 0; i < 4; i++).table[coord[i, 0],
coord[i, 1]] = true;
}RandomShape()
{rand = newRandom();type = 0;
{
type = rand.Next(1, 7);(type == lastShape)
{
count++;(count < 4);
};
} while (true);type;
}createShape(int type)
{(type)
{1: //квадрат
setCoord(4, 0, 4, 1, 5, 0, 5, 1); break;2:
//палка
setCoord(5, 0, 5, 1, 5, 2, 5, 3); break;3: //_|_
setCoord(5, 0, 5, 1, 4, 1, 6, 1); break;4: //|_
setCoord(4, 0, 4, 1, 4, 2, 5, 2); break;5: //_|
setCoord(5, 0, 5, 1, 5, 2, 4, 2); break;6:
//левая
setCoord(5, 0, 5, 1, 4, 1, 4, 2); break;7:
//правая
setCoord(4, 0, 4, 1, 5, 1, 5, 2); break;
}
state = 1;
lastShape = type;.Inv();
}
}
}
КлассBuild - отвечает за игровой процесс игры
«стройка».System;System.Collections.Generic;System.Linq;System.Text;System.Threading.Tasks;System.Windows.Forms;System.Threading;TetrixSystem
{
{Level = 0;Score = 0;mode = 1;Shapes =
0;LinesRemoved = 0;speed = 600;space = false;isPaused = false;thr =
null;Start(int m)
{
ClearTable();
Level = 1;
Score = 0;
Shapes = 0;
mode = m;= newThread(newThreadStart(tableProc));
thr.Start();
}tableProc()
{.nextShape = Shape.RandomShape();(; ; )
{.createShape(Shape.nextShape);.nextShape =
Shape.RandomShape();.MF.nextPaint = true;++;(mode)
{1:(Shapes % 60 == 0)
{
Level++;
speed -= 50;.MF.setLevel(Level);
};2:(Shapes % 30 == 0)
{
Level++;
speed -= 50;.MF.setLevel(Level);
};3:(Shapes % 20 == 0)
{
Level++;
speed -= 50;.MF.setLevel(Level);
};
}
{.Sleep(speed);
} while(MainWindow.Shape_.down());
space = false;(mode)
{1:
Score += 12;;2:
Score += 15;;3:
Score += 18;;
}.MF.setScoreShape(Score, Shapes);
LineRem();(int i = 0; i < 4; i++)
{(Shape.y(i) == 0)
{.MF.EndGame();;
}
}
}
}LineRem()
{f = true;y = 0;(y = 18; y != 0; y--)
{
f = true;(int x = 0; x < 10; x++)
{(MainWindow.table[x, y] != true)
f = false;
}(f == true)
{(int y_ = y; y_ != 0; y_--)
{(int x_ = 0; x_ < 10; x_++)
{.table[x_, y_] = MainWindow.table[x_, (y_ -
1)];
}
}
y++;
LinesRemoved++;
Score +=
100;.MF.setRemovLines(LinesRemoved);.MF.setScoreShape(Score, Shapes);
}
}
}ClearTable()
{(int i = 0; i < 10; i++)(int j = 0; j <
19; j++).table[i, j] = false;.Inv();
}
}
}
КлассShot - отвечает за пулю выпущенную из
конкретного танка в игре «гоники(танки)».
using
System;System.Collections.Generic;System.Linq;System.Text;System.Threading.Tasks;System.Windows.Forms;System.Threading;TetrixSystem
{
{time;x = 0,
y = 0;tank;Shot(Tank t, int t_ = 250)
{
tank = t;
time = t_;
x = tank.coord[0, 0];
y = tank.coord[0, 1];
}go()
{(tank.state)
{1: y--; break;2: x--; break;3: y++; break;4:
x++; break;
}(!checkCoords());temp = tank.state;(true)
{
remove();(temp)
{1:
y--;(!checkCoords());;2:
x--;(!checkCoords());;3:
y++;(!checkCoords());;4:
x++;;
}(!checkCoords());
toTable();.Inv();.Sleep(time);
}
}toTable()
{.table[x, y] = true;
}remove()
{.table[x, y] = false;
}
checkCoords()
{(y < 0)
{
y++;
remove();.Inv();;
}(y > 18)
{
y--;
remove();.Inv();;
}(x < 0)
{
x++;
remove();.Inv();;
}(x > 9)
{
x--;
remove();.Inv();;
}(MainWindow.table[x, y] == true)
{
remove();.Inv();
DestroyObj();;
};
}DestroyObj()
{(MainWindow.Tanks_.Tank_.inMe(x, y))
{.Tanks_.Tank_.wounded();;
}(MainWindow.Tanks_.Tank_1.inMe(x, y))
{.Tanks_.Tank_1.wounded();;
}
}
}
}
КлассTank - отвечает за танк в игре
«гоники(танки)».System;System.Collections.Generic;System.Linq;System.Text;System.Threading.Tasks;System.Windows.Forms;System.Threading;TetrixSystem
{
{Tank(string p = null, bool ToTable = false,
string n = "player")
{(p != null)
createTank(p);(ToTable)
toTable();
name = n;
}health = 3;score = 0;cheat = 5;name =
"";[,] coord = {
{0,0}, //x,y
{0,0},
{0,0},
{0,0}
};[,] tcoord = {
{0,0}, //x,y
{0,0},
{0,0},
{0,0}
{
coord[0, 0] = x1;
coord[0, 1] = y1;
coord[1, 0] = x2;
coord[1, 1] = y2;
coord[2, 0] = x3;
coord[2, 1] = y3;
coord[3, 0] = x4;
coord[3, 1] = y4;
}tmoveCoord(int id, string d, int c = 1)
{(int i = 0; i < c; i++)
{(d)
{"Left":
tcoord[id, 0] = tcoord[id, 0] - 1;
break;"Right":
tcoord[id, 0] = tcoord[id, 0] + 1; break;"Up":
tcoord[id, 1] = tcoord[id, 1] - 1;
break;"Down":
tcoord[id, 1] = tcoord[id, 1] + 1; break;
}
}
}checkCoord(int[,] m)
{(int i = 0; i < 4; i++)
{(m[i, 0] < 0 || m[i, 0] > 9);(m[i, 1]
< 0 || m[i, 1] > 18);(MainWindow.table[m[i, 0], m[i, 1]] == true)
{f = false;(int i_ = 0; i_ < 4; i_++)
{(m[i, 0] == coord[i_, 0] && m[i, 1] ==
coord[i_, 1])
f = true;
}(!f);
}
};
}remove()
{x = 0;y = 0;(int i = 0; i < 4; i++)
{
x = coord[i, 0];
y = coord[i, 1];.table[x, y] = false;
}
}createTank(string pose)
{(pose)
{"center":
setCoord(5, 8, 5, 9, 4, 9, 6,
9);;"down":
setCoord(4, 17, 4, 18, 3, 18, 5,
18);;"up":
setCoord(6, 1, 6, 0, 7, 0, 5, 0);
state = 3;;"left":
setCoord(1, 7, 0, 7, 0, 6, 0, 8);
state = 2;;"right":
setCoord(8, 9, 9, 9, 9, 10, 9, 8);
state = 4;;
}
}toTable()
{(int i = 0; i < 4; i++).table[coord[i, 0],
coord[i, 1]] = true;.Inv();
}copy(int[,] m1, int[,] m2)
{(int i = 0; i < 4; i++)
{(int j = 0; j < 2; j++)
{
m1[i, j] = m2[i, j];
}
}
}left()
{(coord[0, 0] == 0 || coord[1, 0] == 0 ||
coord[2, 0] == 0 || coord[3, 0] == 0);x = 0;y = 0;x1 = 0;y1 = 0;f = false;(int
i = 0; i < 4; i++)
{
x = coord[i, 0];
y = coord[i, 1];(MainWindow.table[x - 1, y] ==
true)
{(int j = 0; j < 4; j++)
{
x1 = coord[j, 0];
y1 = coord[j, 1];(x - 1 == x1 && y ==
y1)
{
f = true;;
}
}(!f) return;
f = false;
}
}();
coord[0, 0]--;
coord[1, 0]--;
coord[2, 0]--;
coord[3, 0]--;
toTable();.Inv();
}right()
{(coord[0, 0] == 9 || coord[1, 0] == 9 ||
coord[2, 0] == 9 || coord[3, 0] == 9);x = 0;y = 0;x1 = 0;y1 = 0;f = false;(int
i = 0; i < 4; i++)
{
x = coord[i, 0];
y = coord[i, 1];(MainWindow.table[x + 1, y] ==
true)
{(int j = 0; j < 4; j++)
{
x1 = coord[j, 0];
y1 = coord[j, 1];(x + 1 == x1 && y ==
y1)
{
f = true;;
}
}(!f) return;
f = false;
}
}();
coord[0, 0]++;
coord[1, 0]++;
coord[2, 0]++;
coord[3, 0]++;
toTable();.Inv();
}down()
{(coord[0, 1] == 18 || coord[1, 1] == 18 ||
coord[2, 1] == 18 || coord[3, 1] == 18);x = 0;y = 0;x1 = 0;y1 = 0;f =
false;(int i = 0; i < 4; i++)
{
x = coord[i, 0];
y = coord[i, 1];(MainWindow.table[x, y + 1] ==
true)
{(int j = 0; j < 4; j++)
{
x1 = coord[j, 0];
y1 = coord[j, 1];(x == x1 && y + 1 ==
y1)
{
f = true;;
}
}(!f);
f = false;
}
}();
coord[0, 1]++;
coord[1, 1]++;
coord[2, 1]++;
coord[3, 1]++;
toTable();.Inv();;
}up()
{(coord[0, 1] == 0 || coord[1, 1] == 0 ||
coord[2, 1] == 0 || coord[3, 1] == 0);x = 0;y = 0;x1 = 0;y1 = 0;f = false;(int
i = 0; i < 4; i++)
{
x = coord[i, 0];
y = coord[i, 1];(MainWindow.table[x, y - 1] ==
true)
{(int j = 0; j < 4; j++)
{
x1 = coord[j, 0];
y1 = coord[j, 1];(x == x1 && y - 1 ==
y1)
{
f = true;;
}
}(!f);
f = false;
}
}();
coord[0, 1]--;
coord[1, 1]--;
coord[2, 1]--;
coord[3, 1]--;
toTable();.Inv();;
}rightRot(string test = "no test")
{
copy(tcoord, coord);stateBackup = state;(state
== 1)
{
tmoveCoord(1, "Left");
tmoveCoord(1, "Up");
tmoveCoord(3, "Left", 2);
tmoveCoord(3, "Up",
2);(!checkCoord(tcoord));
state = 4;
}(state == 4)
{
tmoveCoord(1, "Up");
tmoveCoord(1, "Right");
tmoveCoord(2, "Right", 2);
tmoveCoord(2, "Up", 2);(!checkCoord(tcoord));
state = 3;
}(state == 3)
{
tmoveCoord(1, "Right");
tmoveCoord(1, "Down");
tmoveCoord(3, "Down", 2);
tmoveCoord(3, "Right",
2);(!checkCoord(tcoord));
state = 2;
}(state == 2)
{
tmoveCoord(1, "Down");
tmoveCoord(1, "Left");
tmoveCoord(2, "Down", 2);
tmoveCoord(2, "Left",
2);(!checkCoord(tcoord));
state = 1;
}(test == "no test")
{
remove();
copy(coord, tcoord);
toTable();.Inv();
}
state = stateBackup;
;
}leftRot(string test = "no test")
{
copy(tcoord, coord);stateBackup = state;(state
== 1)
{
tmoveCoord(1, "Right");
tmoveCoord(1, "Up");
tmoveCoord(2, "Right", 2);
tmoveCoord(2, "Up",
2);(!checkCoord(tcoord));
state = 2;
}(state == 2)
{
tmoveCoord(1, "Up");
tmoveCoord(1, "Left");
tmoveCoord(3, "Left", 2);
tmoveCoord(3, "Up", 2);(!checkCoord(tcoord));
state = 3;
}(state == 3)
{
tmoveCoord(1, "Left");
tmoveCoord(1, "Down");
tmoveCoord(2, "Down", 2);
tmoveCoord(2, "Left",
2);(!checkCoord(tcoord));
state = 4;
}(state == 4)
{
tmoveCoord(1, "Down");
tmoveCoord(1, "Right");
tmoveCoord(3, "Down", 2);
tmoveCoord(3, "Right",
2);(!checkCoord(tcoord));
state = 1;
}(test == "no test")
{
remove();
copy(coord, tcoord);
toTable();.Inv();
}
state = stateBackup;;
}go()
{(state)
{1:
up(); break;2:
left(); break;3:
down(); break;4:
right(); break;
}
}goBack()
{(!rightRot("test"))(!leftRot("test"))(state)
{1: down(); break;2: right(); break;3: up();
break;4: left(); break;
}
}push()
{sh = newShot(this);
score -= 40;thr = newThread(sh.go);
thr.Start();
}inMe(int x, int y, bool fl = false)
{(y == 0 && fl)
{(int i = 0; i < 4; i++)
{(coord[i, 0] == x);
}
}(x == 0 && fl)
{(int i = y + 1; i < 4; i++)
{(coord[i, 1] == y);
}
}(int i = 0; i < 4; i++)
{(coord[i, 0] == x && coord[i, 1] == y);
};
}destroy()
{
remove();.Inv();
}wounded()
{
health--;
score -= 50;
toTable();(health == 0)
{.Tanks_.GameOver(name);
}.MF.updateT();
}cheatUse(string dir)
{(cheat == 0);
cheat--;(cheat >= 0)
{(dir == "l")
{
left();
}(dir == "r")
{
right();
}
};
score -= 200;.MF.updateT();
}
}
}
КлассTanks - отвечает за игровой процесс игры
«гоники(танки)».System;System.Collections.Generic;System.Linq;System.Text;System.Threading.Tasks;System.Windows.Forms;System.Threading;TetrixSystem
{
{thr;Tank_;Tank_1;gOver = false;Start()
{
ClearTable();
thr = newThread(newThreadStart(tableProc));
thr.Start();
}tableProc()
{
Tank_ = newTank("down", true);
Tank_1 = newTank("up", true);.Inv();
}isTable(Tank t)
{(int i = 0; i < 4; i++)
{(MainWindow.table[t.coord[i, 0], t.coord[i, 1]]
== true);
};
}ClearTable()
{(int i = 0; i < 10; i++)(int j = 0; j <
19; j++).table[i, j] = false;.Inv();
}GameOver(string name)
{
gOver = true;.MF.gOver(name);
}
}
}
КлассMainWindow - отвечает за обработку всех
событий устройств ввода, а так же отображения информации на экран пользователю
текущей информации.System;System.Collections.Generic;System.ComponentModel;System.Data;System.Drawing;System.Drawing.Drawing2D;System.Linq;System.Text;System.Threading.Tasks;System.Collections;System.Windows.Forms;System.IO;System.Threading;TetrixSystem
{: Form
{game = "";fullPaint = true;nextPaint
= false;MF;thrTime;Build_ = newBuild();Shape_ = newShape();Tanks_ = null;[,]
table = newbool[10, 19];Inv()
{
MF.PanelPad.Invalidate();
}EndGame()
{_build End = newEnd_build();
End.ShowDialog();
}toRecords(string name)
{
listView1.Items.Add(name);
listView1.Items[listView1.Items.Count -
1].SubItems.Add(Build.Score.ToString());
listView1.Items[listView1.Items.Count -
1].SubItems.Add(Build.Level.ToString());
listView1.Items[listView1.Items.Count -
1].SubItems.Add(Build.LinesRemoved.ToString());
listView1.Items[listView1.Items.Count -
1].SubItems.Add(Build.mode.ToString());
Sort();
saveRecords();
}saveRecords()
{tw = newStreamWriter("records.dat",
false);(ListViewItem item inthis.listView1.Items)
{(ListViewItem.ListViewSubItem subItem in item.SubItems)
{
tw.WriteLine(subItem.Text);
}
}.Close();
}Sort(int e = 2)
{
// Create an instance of the ColHeader
class.clickedCol = (ColHeader)this.listView1.Columns[e];
// Set the ascending property to sort in the
opposite order.
clickedCol.ascending = !clickedCol.ascending;
// Get the number of items in the list.numItems
= this.listView1.Items.Count;
// Turn off display while data is
repoplulated..listView1.BeginUpdate();
// Populate an ArrayList with a SortWrapper of
each list item.SortArray = newArrayList();(int i = 0; i < numItems; i++)
{
SortArray.Add(newSortWrapper(this.listView1.Items[i],
e));
}
// Sort the elements in the ArrayList using a
new instance of the SortComparer
// class. The parameters are the starting index,
the length of the range to sort,
// and the IComparer implementation to use for
comparing elements. Note that
// the IComparer implementation (SortComparer)
requires the sort
// direction for its constructor; true if
ascending, othwise false.
SortArray.Sort(0, SortArray.Count,
newSortWrapper.SortComparer(clickedCol.ascending));
// Clear the list, and repopulate with the
sorted items..listView1.Items.Clear();(int i = 0; i < numItems;
i++).listView1.Items.Add(((SortWrapper)SortArray[i]).sortItem);
// Turn display back on..listView1.EndUpdate();
}setScoreShape(int s, int s_)
{
label1.Text = s.ToString();
label4.Text = s_.ToString();
}setRemovLines(int l)
{
label2.Text = l.ToString();
}setLevel(int l)
{
label3.Text = l.ToString();
}MainWindow()
{
InitializeComponent();.listView1.Columns.Add(newColHeader("Name",
50, HorizontalAlignment.Left,
true));.listView1.Columns.Add(newColHeader("Score", 46,
HorizontalAlignment.Left,
true));.listView1.Columns.Add(newColHeader("Level", 38,
HorizontalAlignment.Left,
true));.listView1.Columns.Add(newColHeader("Lines", 49,
HorizontalAlignment.Left,
true));.listView1.Columns.Add(newColHeader("Diff", 40,
HorizontalAlignment.Left, true));i = 0;tr =
newStreamReader("records.dat");(tr.Peek() != -1)
{
listView1.Items.Add(tr.ReadLine());
listView1.Items[i].SubItems.Add(tr.ReadLine());
listView1.Items[i].SubItems.Add(tr.ReadLine());
listView1.Items[i].SubItems.Add(tr.ReadLine());
i++;
}.Close();
}OnPaint(PaintEventArgs e)
{
fullPaint = true;
gObj = Graphics.FromImage(PanelPad.Image);
gObj.SmoothingMode =
SmoothingMode.HighSpeed;(debug.Enabled)
{
debug.Text = "";(int x = 0; x < 19;
x++)
{(int y = 0; y < 10; y++)
{(table[y, x] == true)
debug.Text += "1 ";
debug.Text += "0 ";
}
debug.Text += "\n";
}
}
(nextPaint)
{
nextPaint = false;x1 = 0;x2 = 0;x3 = 0;x4 = 0;y1
= 0;y2 = 0;y3 = 0;y4 = 0;gObj_ = panelNextShape.CreateGraphics();
gObj_.Clear(SystemColors.Control);(Shape.nextShape)
{1:
x1 = 3;
y1 = 1; //..
x2 = 4;
y2 = 1;
x3 = 3;
y3 = 2;
x4 = 4;
y4 = 2;;2:
x1 = 2;
y1 = 1; //..
x2 = 3;
y2 = 1;
x3 = 4;
y3 = 1;
x4 = 5;
y4 = 1;;3:
x1 = 3;
y1 = 1; //..
x2 = 3;
y2 = 2;
x3 = 2;
y3 = 2;
x4 = 4;
y4 = 2;;4:
x1 = 3;
y1 = 0; //..
x2 = 3;
y2 = 1;
x3 = 3;
y3 = 2;
x4 = 4;
y4 = 2;;5:
x1 = 3;
y1 = 0; //..
x2 = 3;
y2 = 1;
x3 = 3;
y3 = 2;
x4 = 2;
y4 = 2;;6:
x1 = 4;
y1 = 0; //..
x2 = 4;
y2 = 1;
x3 = 3;
y3 = 1;
x4 = 3;
y4 = 2;;7:
x1 = 2;
y1 = 0; //..
x2 = 2;
y2 = 1;
x3 = 3;
y3 = 1;
x4 = 3;
y4 = 2;;
}(Shape.nextShape != 0)
{
gObj_.FillRectangle(newLinearGradientBrush(newRectangle(x1
* 30, y1 * 30, 30, 30), Color.DarkRed, SystemColors.Control,
LinearGradientMode.BackwardDiagonal), x1 * 30, y1 * 30, 30, 30);
gObj_.FillRectangle(newLinearGradientBrush(newRectangle(x2
* 30, y2 * 30, 30, 30), Color.DarkRed, SystemColors.Control,
LinearGradientMode.BackwardDiagonal), x2 * 30, y2 * 30, 30, 30);
gObj_.FillRectangle(newLinearGradientBrush(newRectangle(x3
* 30, y3 * 30, 30, 30), Color.DarkRed, SystemColors.Control,
LinearGradientMode.BackwardDiagonal), x3 * 30, y3 * 30, 30, 30);
gObj_.FillRectangle(newLinearGradientBrush(newRectangle(x4
* 30, y4 * 30, 30, 30), Color.DarkRed, SystemColors.Control,
LinearGradientMode.BackwardDiagonal), x4 * 30, y4 * 30, 30, 30);
}
}(fullPaint)
{
gObj.Clear(Color.LightGray);
(int x = 0; x < 10; x++)
{(int y = 0; y < 19; y++)
{(table[x, y] == true)
{px1 = x * 30;px2 = y *
30;.FillRectangle(newLinearGradientBrush(newRectangle(px1, px2, 30, 30),
Color.DarkRed, Color.Gainsboro, LinearGradientMode.BackwardDiagonal), px1, px2,
30, 30);
}
}
}
//fullPaint = false;
}
{x = 0;y = 0;(int i = 0; i < 4; i++)
{
x = Shape.coord[i, 0];
y = Shape.coord[i, 1];(x == 0 && y ==
0);
gObj.FillRectangle(newLinearGradientBrush(newRectangle(x
* 30, y * 30, 30, 30), Color.DarkRed, Color.Gainsboro,
LinearGradientMode.BackwardDiagonal), x * 30, y * 30, 30, 30);
}
}
}button1_Click(object sender, EventArgs e)
{
}Form1_KeyDown(object sender, KeyEventArgs e)
{(e.KeyCode == Keys.Left)
{(game == "Build")
Shape_.left();
Tanks_.Tank_.leftRot();
e.SuppressKeyPress = true;
}(e.KeyCode == Keys.Right)
{(game == "Build")
Shape_.right();
Tanks_.Tank_.rightRot();
e.SuppressKeyPress = true;
}(e.KeyCode == Keys.Space)
{(game == "Build")
{.space = true;
Shape_.down();
}
{
Tanks_.Tank_.push();
}
e.SuppressKeyPress = true;
}(e.KeyCode == Keys.Down)
{(game == "Build").rotate_left();
Tanks_.Tank_.goBack();
e.SuppressKeyPress = true;
}(e.KeyCode == Keys.Up)
{(game == "Build").rotate_right();
Tanks_.Tank_.go();
e.SuppressKeyPress = true;
}(e.KeyCode == Keys.W)
{
Tanks_.Tank_1.go();
e.SuppressKeyPress = true;
}(e.KeyCode == Keys.A)
{
Tanks_.Tank_1.leftRot();
e.SuppressKeyPress = true;
}(e.KeyCode == Keys.D)
{
Tanks_.Tank_1.rightRot();
e.SuppressKeyPress = true;
}(e.KeyCode == Keys.S)
{
Tanks_.Tank_1.goBack();
e.SuppressKeyPress = true;
}(e.KeyCode == Keys.ControlKey)
{
Tanks_.Tank_1.push();
e.SuppressKeyPress = true;
}(e.KeyCode == Keys.Q)
{
Tanks_.Tank_1.cheatUse("l");
e.SuppressKeyPress = true;
}(e.KeyCode == Keys.E)
{
Tanks_.Tank_1.cheatUse("r");
e.SuppressKeyPress = true;
}(e.KeyCode == Keys.End)
{
Tanks_.Tank_.cheatUse("r");
e.SuppressKeyPress = true;
}(e.KeyCode == Keys.ShiftKey)
{
Tanks_.Tank_.cheatUse("l");
e.SuppressKeyPress = true;
}
}Form1_KeyPress(object sender, KeyPressEventArgs
e)
{
}Form1_PreviewKeyDown(object sender,
PreviewKeyDownEventArgs e)
{(e.KeyCode)
{.Left:.Right:.Down:.Space:.Up:.LShiftKey:.Shift:.ShiftKey:.RShiftKey:.Alt:.ControlKey:
e.IsInputKey = true;;
}
}checkBox1_PreviewKeyDown(object sender,
PreviewKeyDownEventArgs e)
{(e.KeyCode)
{.Left:.Right:.Down:.Space:.Up:.LShiftKey:.Shift:.ShiftKey:.RShiftKey:.Alt:.ControlKey:
e.IsInputKey = true;;
}
}checkBox1_CheckedChanged(object sender,
EventArgs e)
{(Pause.Checked)
{
Build_.thr.Suspend();.isPaused = true;
label5.Visible = true;
PanelPad.Visible = false;
checkBox1.Enabled = false;
}
{
Build_.thr.Resume();
fullPaint = true;.isPaused = false;
PanelPad.Visible = true;
label5.Visible = false;
checkBox1.Enabled = true;
}
}radioButton2_CheckedChanged(object sender,
EventArgs e)
{
}checkBox1_CheckedChanged_1(object sender,
EventArgs e)
{
startButton();
}startButton()
{gObj = PanelPad.CreateGraphics();(checkBox1.Checked)
{
MF = (MainWindow)Form.ActiveForm;mode =
0;(radioButton1.Checked)
mode = 1;(radioButton2.Checked)
mode = 2;(radioButton3.Checked)
mode = 3;_.Start(mode);
checkBox1.Text = "Stop";
groupBox7.Enabled = false;.Text =
Build.Score.ToString();
label2.Text = Build.LinesRemoved.ToString();
label3.Text = Build.Level.ToString();
label4.Text = Build.Shapes.ToString();
}
{
Build_.thr.Abort();
gObj.Clear(Color.LightGray);
checkBox1.Text = "Start";
groupBox7.Enabled = true;
}
}MainWindow_FormClosing(object sender,
FormClosingEventArgs e)
{(game == "Build")(Build_.thr !=
null)(Build_.thr.ThreadState == System.Threading.ThreadState.Suspended)
{
Build_.thr.Resume();
Build_.thr.Abort();
}
Build_.thr.Abort();(game ==
"Tanks"&& Tanks_ != null)(Tanks_.thr != null)(Tanks_.thr.ThreadState
== System.Threading.ThreadState.Suspended)
{
Tanks_.thr.Resume();
Tanks_.thr.Abort();
thrTime.Resume();
thrTime.Abort();
label11.Text = "0";
}
{
Tanks_.thr.Abort();
thrTime.Abort();
label11.Text = "0";
}
}button1_Click_1(object sender, EventArgs e)
{(Build_.thr != null)(Build_.thr.ThreadState ==
System.Threading.ThreadState.Suspended)
{
Build_.thr.Resume();
Build_.thr.Abort();
}
Build_.thr.Abort();
game = "Build";
checkBox1.Enabled = true;
checkBox1.Checked = false;
Pause.Checked = false;.Visible = false;
RightPanel.Visible = false;
PanelPad.Visible = false;
PanelMenu.Visible = true;
}button2_Click(object sender, EventArgs e)
{
game = "Build";
PanelMenu.Visible = false;
PanelPad.Visible = true;
LeftPanel.Visible = true;
LeftPanel.Enabled = true;
RightPanel.Visible = true;
RightPanel.Enabled = true;
label1.Text = "0";
label2.Text = "0";
label3.Text = "0";
label4.Text = "0";
}button4_Click(object sender, EventArgs e)
{(debug.Enabled)
debug.Enabled = false;
debug.Enabled = true;
}listView1_ColumnClick(object sender,
ColumnClickEventArgs e)
{
// Create an instance of the ColHeader
class.clickedCol = (ColHeader)this.listView1.Columns[e.Column];
// Set the ascending property to sort in the
opposite order.
clickedCol.ascending = !clickedCol.ascending;
// Get the number of items in the list.numItems
= this.listView1.Items.Count;
// Turn off display while data is
repoplulated..listView1.BeginUpdate();
// Populate an ArrayList with a SortWrapper of
each list item.SortArray = newArrayList();(int i = 0; i < numItems; i++)
{
SortArray.Add(newSortWrapper(this.listView1.Items[i],
e.Column));
}
// Sort the elements in the ArrayList using a
new instance of the SortComparer
// class. The parameters are the starting index,
the length of the range to sort,
// and the IComparer implementation to use for
comparing elements. Note that
// the IComparer implementation (SortComparer)
requires the sort
// direction for its constructor; true if
ascending, othwise false.
SortArray.Sort(0, SortArray.Count,
newSortWrapper.SortComparer(clickedCol.ascending));
// Clear the list, and repopulate with the
sorted items..listView1.Items.Clear();(int i = 0; i < numItems;
i++).listView1.Items.Add(((SortWrapper)SortArray[i]).sortItem);
// Turn display back on..listView1.EndUpdate();
}MainWindow_Load(object sender, EventArgs e)
{
}MainWindow_Load_1(object sender, EventArgs e)
{
}RightPanel_Paint(object sender, PaintEventArgs
e)
{
}button3_Click(object sender, EventArgs e)
{
MF = (MainWindow)Form.ActiveForm;
PanelPad.Visible = true;
PanelMenu.Visible = false;
panel2.Enabled = true;
panel2.Visible = true;
panel3.Visible = true;
panel3.Enabled = true;
game = "Tanks";
}checkBox3_CheckedChanged(object sender,
EventArgs e)
{(checkBox1.Checked)
{
Tanks_.thr.Resume();
thrTime.Resume();
label5.Visible = false;
checkBox2.Enabled = true;
}
{
Tanks_.thr.Suspend();
thrTime.Suspend();
label5.Visible = true;
checkBox2.Enabled = false;
}
}groupBox1_Enter(object sender, EventArgs e)
{
}richTextBox1_TextChanged(object sender,
EventArgs e)
{
}time()
{time = 0;(true)
{
updateT();.Sleep(1000);
time++;
Tanks_.Tank_.score += 40;
Tanks_.Tank_1.score += 40;(time % 60 == 0)
{
label11.Text = (time / 60).ToString() +
":" + "0";
}
{
label11.Text = (time / 60).ToString() +
":" + (time % 60).ToString();
}
}
}gOver(string name)
{
Tanks_.ClearTable();
checkBox2.Checked = false;.Show("Танк
" + name + " был убит!", "GameOver",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}updateT()
{(Tanks_ == null);.Text =
Tanks_.Tank_.health.ToString();
label12.Text = Tanks_.Tank_1.health.ToString();
label7.Text = Tanks_.Tank_.cheat.ToString();
label8.Text = Tanks_.Tank_1.cheat.ToString();
label9.Text = Tanks_.Tank_.score.ToString();
}button5_Click(object sender, EventArgs e)
{(Tanks_.thr != null)(Tanks_.thr.ThreadState ==
System.Threading.ThreadState.Suspended)
{
Tanks_.thr.Resume();
Tanks_.thr.Abort();
thrTime.Resume();
thrTime.Abort();
}
{
Tanks_.thr.Abort();
thrTime.Abort();
}
game = "Tanks";
checkBox2.Enabled = true;
checkBox2.Checked = false;
checkBox3.Checked = false;.Visible = false;
panel2.Enabled = false;
panel3.Visible = false;
panel3.Enabled = false;
PanelPad.Visible = false;
PanelMenu.Visible = true;
}Pause_PreviewKeyDown(object sender,
PreviewKeyDownEventArgs e)
{(e.KeyCode)
{.Left:.Right:.Down:.Space:.Up:.LShiftKey:.Shift:.ShiftKey:.RShiftKey:.Alt:.ControlKey:
e.IsInputKey = true;;
}
}button1_PreviewKeyDown(object sender,
PreviewKeyDownEventArgs e)
{(e.KeyCode)
{.Left:.Right:.Down:.Space:.Up:.LShiftKey:.Shift:.ShiftKey:.RShiftKey:.Alt:.ControlKey:
e.IsInputKey = true;;
}
}checkBox2_PreviewKeyDown(object sender,
PreviewKeyDownEventArgs e)
{(e.KeyCode)
{.Left:.Right:.Down:.Space:.Up:.LShiftKey:.Shift:.ShiftKey:.RShiftKey:.Alt:.ControlKey:
e.IsInputKey = true;;
}
}checkBox3_PreviewKeyDown(object sender,
PreviewKeyDownEventArgs e)
{(e.KeyCode)
{.Left:.Right:.Down:.Space:.Up:.LShiftKey:.Shift:.ShiftKey:.RShiftKey:.Alt:.ControlKey:
e.IsInputKey = true;;
}
}button5_PreviewKeyDown(object sender,
PreviewKeyDownEventArgs e)
{(e.KeyCode)
{.Left:.Right:.Down:.Space:.Up:.LShiftKey:.Shift:.ShiftKey:.RShiftKey:.Alt:.ControlKey:
e.IsInputKey = true;;
}
}startTanks(object sender, EventArgs e)
{(Tanks_ == null)
{
checkBox2.Text = "Stop";
Tanks_ = newTanks();
Tanks_.Start();
thrTime = newThread(newThreadStart(time));
thrTime.Start();
richTextBox1.Enabled = false;
richTextBox2.Enabled = false;
Tanks_.Tank_1.name = richTextBox2.Text;
Tanks_.Tank_.name = richTextBox1.Text;
}
{
checkBox2.Text = "Start";
Tanks_.thr.Abort();
Tanks_.ClearTable();
Tanks_ = null;
thrTime.Abort();
label11.Text = "0";
richTextBox1.Enabled = true;
richTextBox2.Enabled = true;
}
}
}
{sortItem;sortColumn;
// A SortWrapper requires the item and the index
of the clicked column.SortWrapper(ListViewItem Item, int iColumn)
{
sortItem = Item;
sortColumn = iColumn;
}
// Text property for getting the text of an
item.Text
{
{sortItem.SubItems[sortColumn].Text;
}
}
// Implementation of the IComparer
// interface for sorting ArrayList items.:
IComparer
{ascending;
// Constructor requires the sort order;
// true if ascending, otherwise
descending.SortComparer(bool asc)
{.ascending = asc;
}
// Implemnentation of the IComparer:Compare
// method for comparing two
objects.Compare(object x, object y)
{xItem = (SortWrapper)x;yItem =
(SortWrapper)y;xText = xItem.sortItem.SubItems[xItem.sortColumn].Text;yText =
yItem.sortItem.SubItems[yItem.sortColumn].Text;xText.CompareTo(yText) *
(this.ascending ? 1 : -1);
}
}
}: ColumnHeader
{ascending;ColHeader(string text, int width,
HorizontalAlignment align, bool asc)
{.Text = text;.Width = width;.TextAlign =
align;.ascending = asc;
}
}
}
Заключение
В результате данной работы была создана
программа, для игры в гонки и стройку на основе игровой системы тетрис.
Программа выполненна в современной эргономике и будет интересна разным
вовзрастным категориям. Есть возможность на базе этой программы разрабатывать
дополнительные игры.
Поддерживаемые операционный системы:
· Windows 98, 2000,
XP, Vista, 7 (x86 или
x86_64)
Список литературы
.Документация
MSDNна http://MSDN.microsoft.com.
.C#
в подлиннике. Наиболее полное руководство Х. Дейтел. Санк-Петербург
«БХВ-Петербург» 2006