PROJECTS
How do I use P R O J E C T S
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: VSCode.cs
Copy
1248 static void WriteWorkspaceSettings()
1249 {
1250 if (Debug)
1251 {
1252 UnityEngine.Debug.Log("[VSCode] Workspace Settings Written");
1253 }
1254
1255 if (!Directory.Exists(VSCode.SettingsFolder))
1256 {
1257 System.IO.Directory.CreateDirectory(VSCode.SettingsFolder);
1258 }
1259
1260 string exclusions =
1261 // Associations
1262 "{\n" +
1263 "\t\"files.associations\":\n" +
1264 "\t{\n" +
1265 "\t\t\"*.bjs\":\"javascript\",\n" +
1266 "\t\t\"*.javascript\":\"javascript\"\n" +
1267 "\t},\n" +
1268 "\t\"files.exclude\":\n" +
1269 "\t{\n" +
1270 // Hidden Files
1271 "\t\t\"**/.DS_Store\":true,\n" +
1272 "\t\t\"**/.git\":true,\n" +
1273 "\t\t\"**/.gitignore\":true,\n" +
1274 "\t\t\"**/.gitattributes\":true,\n" +
1275 "\t\t\"**/.gitmodules\":true,\n" +
1276 "\t\t\"**/.svn\":true,\n" +
1277
1278
1279 // Project Files
1280 "\t\t\"**/*.booproj\":true,\n" +
1281 "\t\t\"**/*.pidb\":true,\n" +
1282 "\t\t\"**/*.suo\":true,\n" +
1283 "\t\t\"**/*.user\":true,\n" +
1284 "\t\t\"**/*.userprefs\":true,\n" +
1285 "\t\t\"**/*.unityproj\":true,\n" +
1286 "\t\t\"**/*.dll\":true,\n" +
1287 "\t\t\"**/*.exe\":true,\n" +
1288
1289 // Media Files
1290 "\t\t\"**/*.pdf\":true,\n" +
1291
1292 // Video
1293 "\t\t\"**/*.mp4\":true,\n" +
1294
1295 // Audio
1296 "\t\t\"**/*.mid\":true,\n" +
1297 "\t\t\"**/*.midi\":true,\n" +
1298 "\t\t\"**/*.wav\":true,\n" +
1299 "\t\t\"**/*.mp3\":true,\n" +
1300 "\t\t\"**/*.ogg\":true,\n" +
1301
1302 // Textures
1303 "\t\t\"**/*.gif\":true,\n" +
1304 "\t\t\"**/*.ico\":true,\n" +
1305 "\t\t\"**/*.jpg\":true,\n" +
1306 "\t\t\"**/*.jpeg\":true,\n" +
1307 "\t\t\"**/*.png\":true,\n" +
1308 "\t\t\"**/*.psd\":true,\n" +
1309 "\t\t\"**/*.tga\":true,\n" +
1310 "\t\t\"**/*.tif\":true,\n" +
1311 "\t\t\"**/*.tiff\":true,\n" +
1312 "\t\t\"**/*.hdr\":true,\n" +
1313 "\t\t\"**/*.exr\":true,\n" +
1314
1315 // Models
1316 "\t\t\"**/*.3ds\":true,\n" +
1317 "\t\t\"**/*.3DS\":true,\n" +
1318 "\t\t\"**/*.fbx\":true,\n" +
1319 "\t\t\"**/*.FBX\":true,\n" +
1320 "\t\t\"**/*.lxo\":true,\n" +
1321 "\t\t\"**/*.LXO\":true,\n" +
1322 "\t\t\"**/*.ma\":true,\n" +
1323 "\t\t\"**/*.MA\":true,\n" +
1324 "\t\t\"**/*.obj\":true,\n" +
1325 "\t\t\"**/*.OBJ\":true,\n" +
1326
1327 // Unity File Types
1328 "\t\t\"**/*.asset\":true,\n" +
1329 "\t\t\"**/*.cubemap\":true,\n" +
1330 "\t\t\"**/*.flare\":true,\n" +
1331 "\t\t\"**/*.mat\":true,\n" +
1332 "\t\t\"**/*.meta\":true,\n" +
1333 "\t\t\"**/*.prefab\":true,\n" +
1334 "\t\t\"**/*.unity\":true,\n" +
1335
1336 // Folders
1337 "\t\t\"build/\":true,\n" +
1338 "\t\t\"Build/\":true,\n" +
1339 "\t\t\"Library/\":true,\n" +
1340 "\t\t\"library/\":true,\n" +
1341 "\t\t\"obj/\":true,\n" +
1342 "\t\t\"Obj/\":true,\n" +
1343 "\t\t\"ProjectSettings/\":true,\r" +
1344 "\t\t\"temp/\":true,\n" +
1345 "\t\t\"Temp/\":true\n" +
1346 "\t}\n" +
1347 "}";
1348
1349 // Dont like the replace but it fixes the issue with the JSON
1350 File.WriteAllText(VSCode.SettingsPath, exclusions);
1351 }
File name: InstructionsScript.cs
Copy
27 void OnGUI() {
28 if (this.gameScript.gameView == "instructions") {
29 GUI.skin = currentGUISkin;
30
31 this.gameScript.mainCamera.transform.eulerAngles = new Vector3 (120, 23, 0);
32
33 GUIStyle labelStyle = new GUIStyle(currentGUISkin.label);
34 labelStyle.alignment = TextAnchor.UpperLeft;
35 GUILayout.Label ("Instructions", "BigLabel");
36
37
38 scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.Width(Screen.width), GUILayout.Height(Mathf.Ceil(Screen.height * .80f)));
39
40 GUILayout.Label ("Object", "Subheader");
41
42 GUILayout.Label (@"The object of 2048-3D is to"
43 + " slide numbered blocks in such a way"
44 + " so that blocks with the same numbers collide"
45 + " and combine into a new block that is twice"
46 + " as much as the originals until"
47 + " the number 2048 is reached.", labelStyle);
48
49 GUILayout.Label ("Moving the Blocks", "Subheader");
50
51 GUILayout.Label (@"You cannot move blocks individually, but must"
52 + " move all blocks simultaneously in the same direction."
53 + " Blocks can move forward, backward, up, down, left"
54 + " and right along the green connectors."
55 + " Simply swipe any part of the screen to move up,"
56 + " down, left or right (keyboard: arrow keys). To move the"
57 + " blocks forward and backward use the"
58 + " big red arrow keys at the bottom of the screen (keyboard: a and z keys)."
59 + " When moving, all blocks that can slide in the chosen direction will move."
60 + " Any block moving toward another block with the same number will collide "
61 + " and form a single block with twice the number as the originals", labelStyle);
62
63
64 GUILayout.Label ("New Blocks", "Subheader");
65
66 GUILayout.Label (@"After each move is"
67 + " made a new block will appear randomly in an empty position."
68 + " This block will have a number of either 2 or 4."
69 + " For an extra challenge, there is a game option you can"
70 + " set so that zeros can also be assinged to a new block."
71 + " Zeros act like any other number in that they can"
72 + " collide with other zeros to make a block twice as much "
73 + " (which is still zero).", labelStyle);
74
75
76
77 GUILayout.Label ("Scoring and Finishing", "Subheader");
78
79 GUILayout.Label(@"For every block collision that occurs you receive"
80 + " the number of points of the newly"
81 + " created block. If after making a move"
82 + " all positions are filled and no new"
83 + " moves are possible, the game ends."
84 + " A separate high score / highest block is kept for each"
85 + " distinct combination of game options", labelStyle);
86
87
88 GUILayout.Label ("Game Layout Options", "Subheader");
89
90 GUILayout.Label (@"When I first made this game there"
91 + " was only one game layout, a 3x3x3 cube."
92 + " After testing it a bit, it was way to easy"
93 + " so the zero option was added."
94 + " It was still way to easy "
95 + " (e.g. you could swipe without even looking and get pretty far)."
96 + " Therefore there are now several diffent game layouts that"
97 + " make the game more challenging and fun.", labelStyle);
98
99 GUILayout.Label ("Game Timer Option", "Subheader");
100
101 GUILayout.Label (@"To give yourself even more of a challenge"
102 + " you can set game options to include a timer."
103 + " If a timer is chosen you have a specific"
104 + " amount of time to combined blocks to make the 64 block."
105 + " If you run out of time the game is over."
106 + " If you reach your target before the timer runs down you will"
107 + " receive additional time to reach the next target."
108 + " The time you received is as follows: \n"
109 + " 64: option time + 5 seconds (because the first one is the hardest!)\n"
110 + " 128: option time\n"
111 + " 256: 2X option time\n"
112 + " 512: 4X option time \n"
113 + " 1024: 8X option time \n"
114 + " you get the idea.", labelStyle);
115
116
117 GUILayout.Label ("Acknowledgements \nand Confessions", "Subheader");
118
119 GUILayout.Label (@"2048-3D is based upon the original" +
120 " 2048 game designed by Gabriele Cirulli " +
121 " \n\n" +
122 " Sound effects by freeSFX http://www.freesfx.co.uk.\n\n" +
123 " This game was designed using the Unity3D game engine.\n\n" +
124 " FOR MORE PROJECTS VISIT:" +
125 " https://code-projects.org/", labelStyle);
126
127
128 foreach (Touch touch in Input.touches) {
129 if (touch.phase == TouchPhase.Moved)
130 {
131 // dragging
132 this.scrollPosition.y += touch.deltaPosition.y;
133 }
134 }
135 GUILayout.EndScrollView();
136
137 if (GUILayout.Button ("Return to Menu")) {
138 this.gameScript.gameView = "menu";
139 }
140 }
141 }
File name: MenuScript.cs
Copy
21 void OnGUI() {
22 if (this.gameScript.gameView == "menu") {
23 this.gameScript.mainCamera.transform.eulerAngles = new Vector3 (180, 23, 0);
24 this.gameScript.gameLight.intensity = 0;
25
26 //set the sizes appropriately
27 GUI.skin = this.gameScript.currentGUISkin;
28
29 GUIStyle playButtonStyle = new GUIStyle(currentGUISkin.GetStyle("Button"));
30 playButtonStyle.fontSize = Mathf.CeilToInt(Screen.height * 0.10F);
31 playButtonStyle.fontStyle = FontStyle.Italic;
32
33
34 GUIStyle menuButtonStyle = new GUIStyle(currentGUISkin.GetStyle("Button"));
35 menuButtonStyle.fontSize = Mathf.CeilToInt(Screen.height * 0.06F);
36
37
38 GUIStyle titleLabelStyle = new GUIStyle(currentGUISkin.GetStyle("TitleLabel"));
39 titleLabelStyle.fontSize = Mathf.CeilToInt(Screen.height * 0.13F);
40
41 GUI.Label (new Rect (0, 0, Screen.width, Screen.height * 0.06F), "2048 - 3D", titleLabelStyle);
42
43
44 GUI.Label (new Rect (0, Screen.height * 0.15F, Screen.width, Screen.height * 0.06F), "");
45
46
47 if (GUI.Button(new Rect(Screen.width * 0.20f, Screen.height * 0.25f, Screen.width * 0.60F, Screen.height * 0.10F),"Options", menuButtonStyle)) {
48 this.gameScript.gameView = "options";
49 }
50 if (GUI.Button(new Rect(Screen.width * 0.20f, Screen.height * 0.40f, Screen.width * 0.60F, Screen.height * 0.10F),"Instructions", menuButtonStyle)) {
51 this.gameScript.gameView = "instructions";
52 }
53 if (GUI.Button(new Rect(Screen.width * 0.20f, Screen.height * 0.55F, Screen.width * 0.60F, Screen.height * 0.10F),"Exit", menuButtonStyle)) {
54 Application.Quit();
55 }
56
57 if (GUI.Button(new Rect(Screen.width * .20f, Screen.height * 0.70F, Screen.width * 0.60F, Screen.height * 0.15F),"Play!",playButtonStyle)) {
58 this.gameScript.gameView = "game";
59 }
60
61 GUI.Label (new Rect (0, Screen.height * 0.94F, Screen.width, Screen.height * 0.06F), " 2018 - Brought To You By code-projects.org");
62
63 }
64 }
File name: DeleteMembers.cs
Copy
20 private void button1_Click(object sender, EventArgs e)
21 {
22 try
23 {
24 SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=F:\Sem.4\C# Projects\GymManagementSystem in C#\GymManagementSystem\Gym.mdf;Integrated Security=True;User Instance=True");
25 con.Open();
26
27 string str = "DELETE FROM members WHERE m_id = '" + textBox1.Text + "'";
28
29 SqlCommand cmd = new SqlCommand(str, con);
30 cmd.ExecuteNonQuery();
31 con.Close();
32 MessageBox.Show(" Members Record Deleted Successfully");
33
34 using (SqlConnection newcon = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=F:\Sem.4\C# Projects\GymManagementSystem in C#\GymManagementSystem\Gym.mdf;Integrated Security=True;User Instance=True"))
35 {
36 string str1 = "SELECT * from members";
37 SqlCommand cmd1 = new SqlCommand(str1, newcon);
38 SqlDataAdapter da = new SqlDataAdapter(cmd1);
39 DataTable dt = new DataTable();
40 da.Fill(dt);
41 dataGridView1.DataSource = new BindingSource(dt, null);
42
43 }
44 }
45
46 catch (SqlException ex)
47 {
48 MessageBox.Show(ex.Message);
49 MessageBox.Show("Please Enter Employee Id..");
50 }
51 }
File name: DeleteMembers.cs
Copy
53 private void DeleteMembers_Load(object sender, EventArgs e)
54 {
55 // TODO: This line of code loads data into the 'gymDataSet1.members' table. You can move, or remove it, as needed.
56 this.membersTableAdapter.Fill(this.gymDataSet1.members);
57 using (SqlConnection newcon = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=F:\Sem.4\C# Projects\GymManagementSystem in C#\GymManagementSystem\Gym.mdf;Integrated Security=True;User Instance=True"))
58 {
59 string str1 = "SELECT * from members";
60 SqlCommand cmd1 = new SqlCommand(str1, newcon);
61 SqlDataAdapter da = new SqlDataAdapter(cmd1);
62 DataTable dt = new DataTable();
63 da.Fill(dt);
64 dataGridView1.DataSource = new BindingSource(dt, null);
65
66 }
67 }
File name: Equipment.cs
Copy
20 private void button1_Click(object sender, EventArgs e)
21 {
22 SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=F:\Sem.4\C# Projects\GymManagementSystem in C#\GymManagementSystem\Gym.mdf;Integrated Security=True;User Instance=True");
23 con.Open();
24
25 try
26 {
27 string str = " INSERT INTO equipment(name,description,used,cost) VALUES('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "'); ";
28
29 SqlCommand cmd = new SqlCommand(str, con);
30 cmd.ExecuteNonQuery();
31
32 string str1 = "select max(eqp_id) from equipment;";
33
34 SqlCommand cmd1 = new SqlCommand(str1, con);
35 SqlDataReader dr = cmd1.ExecuteReader();
36 if (dr.Read())
37 {
38 MessageBox.Show("" + textBox1.Text + "'s Equipment Details is Inserted Successfully.. ");
39 this.Hide();
40
41 }
42 this.Close();
43 }
44 catch (SqlException excep)
45 {
46 MessageBox.Show(excep.Message);
47 }
48 con.Close();
49 }
File name: Form1.cs
Copy
20 private void button1_Click(object sender, EventArgs e)
21 {
22 SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=F:\Sem.4\C# Projects\GymManagementSystem in C#\GymManagementSystem\Gym.mdf;Integrated Security=True;User Instance=True");
23 con.Open();
24 string str = "SELECT emp_username FROM employee WHERE password='" + textBox2.Text + "'";
25 SqlCommand cmd = new SqlCommand(str, con);
26 SqlDataReader dr;
27 dr = cmd.ExecuteReader();
28 if (dr.Read())
29 {
30 this.Visible = false;
31 Home obj2 = new Home();
32 obj2.ShowDialog();
33 }
34 else
35 {
36 MessageBox.Show("Invalid username and Password.");
37 }
38 }
File name: NewMember.cs
Copy
25 private void button1_Click(object sender, EventArgs e)
26 {
27 SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=F:\Sem.4\C# Projects\GymManagementSystem in C#\GymManagementSystem\Gym.mdf;Integrated Security=True;User Instance=True");
28 con.Open();
29 string gender = string.Empty;
30 if (radioButton1.Checked)
31 {
32 gender = "Male";
33 }
34 else if (radioButton2.Checked)
35 {
36 gender = "Female";
37 }
38 try
39 {
40 string str = " INSERT INTO members(f_name,l_name,gender,dob,mobile,email,jod,time,address,mem_time) VALUES('" + textBox1.Text + "','" + textBox2.Text + "','" + gender + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + comboBox1.Text + "','" + textBox7.Text + "','" + comboBox2.Text + "'); ";
41
42 SqlCommand cmd = new SqlCommand(str, con);
43 cmd.ExecuteNonQuery();
44
45 string str1 = "select max(m_id) from members ;";
46
47 SqlCommand cmd1 = new SqlCommand(str1, con);
48 SqlDataReader dr = cmd1.ExecuteReader();
49 if (dr.Read())
50 {
51 MessageBox.Show("" + textBox1.Text + "'s Details is Inserted Successfully.. " + textBox1.Text + "'s Id is " + dr.GetInt32(0) + ".", "Important Message");
52 this.Hide();
53
54 }
55 this.Close();
56 }
57 catch (SqlException excep)
58 {
59 MessageBox.Show(excep.Message);
60 }
61 con.Close();
62 }
File name: NewStaff.cs
Copy
20 private void button1_Click(object sender, EventArgs e)
21 {
22 SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=F:\Sem.4\C# Projects\GymManagementSystem in C#\GymManagementSystem\Gym.mdf;Integrated Security=True;User Instance=True");
23 con.Open();
24 string gender = string.Empty;
25 if (radioButton1.Checked)
26 {
27 gender = "Male";
28 }
29 else if (radioButton2.Checked)
30 {
31 gender = "Female";
32 }
33 try
34 {
35 string str = " INSERT INTO staff(f_name,l_name,gender,dob,mobile,email,jod,street,city) VALUES('" + textBox1.Text + "','" + textBox2.Text + "','" + gender + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text + "','" +textBox8.Text + "'); ";
36
37 SqlCommand cmd = new SqlCommand(str, con);
38 cmd.ExecuteNonQuery();
39
40 string str1 = "select max(stf_id) from staff;";
41
42 SqlCommand cmd1 = new SqlCommand(str1, con);
43 SqlDataReader dr = cmd1.ExecuteReader();
44 if (dr.Read())
45 {
46 MessageBox.Show("" + textBox1.Text + "'s Details is Inserted Successfully.. " + textBox1.Text + "'s Id is " + dr.GetInt32(0) + ".", "Important Message");
47 this.Hide();
48
49 }
50 this.Close();
51 }
52 catch (SqlException excep)
53 {
54 MessageBox.Show(excep.Message);
55 }
56 con.Close();
57 }
File name: Register.cs
Copy
20 private void button1_Click(object sender, EventArgs e)
21 {
22 SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=F:\Sem.4\C# Projects\GymManagementSystem in C#\GymManagementSystem\Gym.mdf;Integrated Security=True;User Instance=True");
23 con.Open();
24 string gender = string.Empty;
25 if (radioButton1.Checked)
26 {
27 gender = "Male";
28 }
29 else if (radioButton2.Checked)
30 {
31 gender = "Female";
32 }
33 try
34 {
35 string str = " INSERT INTO employee(emp_username,name,password,gender,email,mobile,address,date) VALUES('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + gender + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text + "'); ";
36
37 SqlCommand cmd = new SqlCommand(str, con);
38 cmd.ExecuteNonQuery();
39
40 string str1 = "select max(emp_id) from employee ;";
41
42 SqlCommand cmd1 = new SqlCommand(str1, con);
43 SqlDataReader dr = cmd1.ExecuteReader();
44 if (dr.Read())
45 {
46 MessageBox.Show("" + textBox1.Text + "'s Details is Inserted Successfully.. " + textBox1.Text + "'s Id is " + dr.GetInt32(0) + ".", "Important Message");
47 this.Hide();
48 Home obj1 = new Home();
49 obj1.ShowDialog();
50 }
51 this.Close();
52 }
53 catch (SqlException excep)
54 {
55 MessageBox.Show(excep.Message);
56 }
57 con.Close();
58 }
PROJECTS 122 lượt xem
Gõ tìm kiếm nhanh...