-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.cs
100 lines (81 loc) · 3.05 KB
/
Form1.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SnakeGame
{
public partial class Form1 : Form
{
private const string c_ImageFolderName = "image";
private const string c_SnakeMenuImage = "SnakeMenu.png";
private const int c_IconWidth = 120;
private const int c_IconHeight = 200;
private const int c_FormWidth = 700;
private const int c_FormHeight = 700;
private string m_Player;
private frmSnakeBoard m_frmGameBoard;
private Label lblTitle = new Label();
private PictureBox SnakeMenuImage = new PictureBox();
private Button btnNewGame = new Button();
private Button btnShowPlayers = new Button();
private Button btnExit = new Button();
public Form1()
{
InitializeComponent();
SetDeisgin();
btnNewGame.MouseDown += ClickNewGame;
btnExit.MouseDown += ClickToExit;
}
private void ClickNewGame(object sender, MouseEventArgs e)
{
if (m_frmGameBoard == null)
{
InitPlayerName();
m_frmGameBoard = new frmSnakeBoard(NamePlayer: m_Player);
m_frmGameBoard.ShowDialog();
}
}
private void InitPlayerName()
{
DialogSetName frm_SetPlayer = new DialogSetName();
frm_SetPlayer.ShowDialog();
m_Player = frm_SetPlayer.Name;
frm_SetPlayer.Close();
}
private void ClickToExit(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
this.Close();
}
private void SetDeisgin()
{
this.Size = new Size(c_FormWidth, c_FormHeight);
this.BackColor = Color.AntiqueWhite;
lblTitle.Text = "Snake Game";
lblTitle.Size = new Size(100, 50);
lblTitle.Location = new Point(300, 50);
lblTitle.ForeColor = System.Drawing.Color.Black;
this.Controls.Add(lblTitle);
SnakeMenuImage.Image = Image.FromFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, c_ImageFolderName, c_SnakeMenuImage));
SnakeMenuImage.Size = new Size(c_IconWidth, c_IconHeight);
SnakeMenuImage.Location = new Point(250, 150);
SnakeMenuImage.SizeMode = PictureBoxSizeMode.StretchImage;
this.Controls.Add(SnakeMenuImage);
btnNewGame.Text = "New Game";
btnShowPlayers.Text = "Stats Players";
btnExit.Text = "Exit";
btnNewGame.Location = new Point(150, 400);
btnShowPlayers.Location = new Point(250, 400);
btnExit.Location = new Point(350, 400);
this.Controls.Add(btnNewGame);
this.Controls.Add(btnShowPlayers);
this.Controls.Add(btnExit);
}
}
}