-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathTetrisGame.cs
113 lines (103 loc) · 1.87 KB
/
TetrisGame.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
* Created by SharpDevelop.
* User: user
* Date: 08.10.2013
* Time: 2:46
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace Tetris
{
public class TetrisGame
{
public Figure NextFigure;
private int score;
public int Score
{
get { return score; }
set
{
score=value;
OnStateChanged();
}
}
private int figDropped;
public int FiguresDropped
{
get { return figDropped; }
set
{
figDropped=value;
OnStateChanged();
}
}
private bool gameOver, paused, figChanged;
public bool GameOver
{
get { return gameOver; }
set
{
gameOver=value;
OnStateChanged();
}
}
public bool Paused
{
get { return paused; }
set
{
if(!paused && value)
{
GamePaused=DateTime.Now;
paused=value;
OnStateChanged();
}
if(paused && !value)
{
GameStarted=GameStarted+(DateTime.Now-GamePaused);
paused=value;
OnStateChanged();
}
}
}
public bool FigureChanged
{
get { return figChanged; }
set
{
figChanged=value;
OnStateChanged();
}
}
public DateTime GameStarted, GamePaused;
/// <summary>
/// Создаёт новый экземпляр TetrisGame, готовый к началу игры
/// </summary>
public TetrisGame()
{
Score=0; FiguresDropped=0;
NextFigure=Figure.RandomFigure();
GameOver=false; Paused=false; FigureChanged=false;
GameStarted=DateTime.Now;
}
/// <summary>
/// Завершает игру
/// </summary>
public void Over()
{
GameOver=true;
}
public event EventHandler StateChanged;
protected virtual void OnStateChanged()
{
if (StateChanged != null)
{
StateChanged(this, new EventArgs());
}
}
}
}