This repository has been archived by the owner on Nov 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FrmGame.cs
182 lines (163 loc) · 6.01 KB
/
FrmGame.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*
Copyright (C) 2009-2010 Tom Postma, Gertjan Buijs
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
namespace Frogger
{
using System;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
public partial class FrmGame : Form
{
#region Fields (5)
private FrmMenu frmmenu;
private GameEngine game;
#endregion Fields
#region Constructors (1)
/// <summary>
/// Creating a new instance of FrmGame.
/// </summary>
/// <param name="level">the level number, each numbers draws a other level.</param>
/// <param name="niveau">the niveau enumaration. freeplay you won't go gameover.
/// then there is easy, medium, hard and elite.</param>
public FrmGame(FrmMenu frmmenu, string lvlname, Niveau tier)
{
InitializeComponent();
this.frmmenu = frmmenu;
Program.CheckFullScreen(this);
this.game = new GameEngine(lvlname, this, tier);
this.Text = this.Text + " - level: " + lvlname + " - tier: " + tier.ToString();
}
#endregion Constructors
#region Methods (9)
// Public Methods (1)
/// <summary>
/// Form is closed.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void FrmGame_FormClosing(object sender, FormClosingEventArgs e)
{
game.StopEngine(true);
this.frmmenu.Menustate = MenuState.main;
this.frmmenu.MenuUpdated = true;
this.frmmenu.Show();
}
/// <summary>
/// Move a frog.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void FrmGame_KeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.A:
game.frog.Jump(Direction.East);
break;
//case Keys.Left:
// game.frog.Jump(Direction.East);
// break;
case Keys.D:
game.frog.Jump(Direction.West);
break;
//case Keys.Right:
// game.frog.Jump(Direction.West);
// break;
case Keys.S:
game.frog.Jump(Direction.South);
break;
//case Keys.Down:
// game.frog.Jump(Direction.South);
// break;
case Keys.W:
game.frog.Jump(Direction.North);
break;
//case Keys.Up:
// game.frog.Jump(Direction.North);
// break;
case Keys.Escape:
this.Close();
break;
}
}
/// <summary>
/// Draw every aspect of the game.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void FrmGame_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
game.RenderScreen(g);
lbTime.Text = GetFancyGameTime();
}
/// <summary>
/// Begin resizing window
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void FrmGame_ResizeBegin(object sender, EventArgs e)
{
game.StopEngine(false);
}
/// <summary>
/// repaint the form, so thing show up correctly a the new size.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void FrmGame_ResizeEnd(object sender, EventArgs e)
{
game.SetupEngine(false); //does resize all resources.
game.StartEngine();
this.Refresh();
}
/// <summary>
/// Format the game time string so seconds are always displayed with two numbers,
/// a lead zero if seconds lower then 10seconds is added.
/// And there is a : charcter between the minuts and seconds.
/// </summary>
private string GetFancyGameTime()
{
StringBuilder timestr = new StringBuilder(this.game.min.ToString() + ":");
if (this.game.sec < 10)
{
timestr.Append("0" + this.game.sec.ToString());
if (this.game.min == 0)
{
// less than 10s make red.
lbTime.ForeColor = Color.Red;
int fontsize = Convert.ToInt32(lbTime.Font.Size);
if (this.game.sec < 4 && this.game.sec>0)
{
// 3s and less, make bold
lbTime.Font = new Font(lbTime.Font.Name, fontsize, FontStyle.Bold);
}
else if (this.game.sec <= 0)
{
lbTime.Font = new Font(lbTime.Font.Name, fontsize, FontStyle.Regular);
}
}
}
else
{
// still more than `10seconds left.
timestr.Append(this.game.sec.ToString());
lbTime.ForeColor = Color.LightGray;
}
return timestr.ToString();
}
#endregion Methods
}
}