-
17-01-2010, 03:56 PM #1Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
làm sao để thời gian chạy song song với 1 hàm khác
e có 1 hàm đếm thừi gian như sau
Mã:{ int t = 90; Thread.Sleep(1000); while (t >= 1) { t--; Thread.Sleep(1000); Console.SetCursorPosition(55,1); Console.Write(t); }
Mã:public void Level1() { int j = 0; int l = 0; Console.Clear(); do { Console.SetCursorPosition(45, 1); Console.WriteLine("Marks: "); Console.SetCursorPosition(53, 1); Console.WriteLine(RecordPoints); Console.Clear(); int Chances=9; string Name = "countryside"; Console.SetCursorPosition(0, 1); Console.Write("Chances: "); Console.SetCursorPosition(10, 1); Console.WriteLine(Chances); Console.SetCursorPosition(45, 1); Console.WriteLine("Marks: "); Console.SetCursorPosition(0, 15); Console.WriteLine("Total Characters: {0}", Name.Length); string[] array = new string[Name.Length]; int so = 0; for (int i = 0; i < Name.Length; i++) { string len = Name.Substring(i, 1); array[so] = len; so++; } Random auto = new Random(); int value = auto.Next(so); //----------------------------------------/ int point = (50 - (Name.Length)); int diem = 0; for (int i = 0; i < Name.Length; i++) { if (array[i] == array[value]) { Console.SetCursorPosition(point, 5); Console.WriteLine(array[value]); diem++; } else { Console.SetCursorPosition(point, 5); Console.WriteLine("_"); } point += 2; } //----------------------/ j = (Name.Length) - diem; int Loop = 0; Console.SetCursorPosition(2, 10); Console.Write("Guess: "); while (Loop < Chances) { Console.SetCursorPosition(9, 10); string Guess = Console.ReadLine(); int point2 = (50 - (Name.Length)); for (int i = 0; i < Name.Length; i++) { if (Guess == array[value]) { break; } if (Guess == array[i]) { for (int y = i; y < Name.Length; y++) { if (Guess == array[y]) { Console.SetCursorPosition(point2, 5); Console.WriteLine(Guess); l++; RecordPoints++; Console.SetCursorPosition(53, 1); Console.WriteLine(RecordPoints); } point2 += 2; } break; } if (i == (Name.Length - 1)) { Loop++; int s = (Chances - Loop); Console.SetCursorPosition(10, 1); Console.WriteLine(s); if (Loop == Chances) { Console.Clear(); Console.SetCursorPosition(30, 3); Console.WriteLine("GAME OVER!"); } break; } point2 += 2; } if (j == l) { break; } } } while (j == l); }
em làm nó cứ 1 cái chạy trước 1 cái chạy sauView more random threads:
- Chỉ cho người dùng mở chương trình C# 1 lần?
- Lấy ra từng giá trị trong vòng lặp For
- Không thể mở file .exe ở 1 máy chưa cài c#
- Decode Quoted-Printable cho tiếng Việt
- Truyền dữ liệu từ các textbox của form này sang 1 listview của form khác?
- Lấy font của text ?
- Lưu nội dung từ RichTextBox ra file đúng định dạng
- Cách sử dụng hàm trong C# như thế nào?
- làm bảng chấm công trong c# như thế nào?
- Sử Dụng Xml làm Database như thế nào
-
17-01-2010, 04:00 PM #2Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Dùng multi-thread đi bạn [IMG]images/smilies/biggrin.png[/IMG]
-
17-01-2010, 04:19 PM #3Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
dùng như thế nào hả bạn
mình mới học nên chưa biết nhiều lắm
-
17-01-2010, 04:24 PM #4Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Mã:System.Threading.Thread thread = new System.Threading.Thread(<hàm cần chạy>);thread.Start();
-
17-01-2010, 04:45 PM #5Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
mọi người chỉ cụ thể hơn được ko ạ
em viết hàm main như sau
Mã:class Program { static void Main(string[] args) { GameVH obj = new GameVH(); obj.Guide(); obj.Name(); System.Threading.Thread thread = new System.Threading.Thread(Level1); thread.Start(); int t = 90; Thread.Sleep(1000); while (t >= 1) { t--; Thread.Sleep(1000); Console.SetCursorPosition(55, 1); Console.Write(t); } } }
-
17-01-2010, 05:18 PM #6Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Cái phương thức Level1() bạn đặt ở trong class Program luôn hả, có phải static ko. Còn phần này
Mã:int t = 90; Thread.Sleep(1000); while (t >= 1) { t--; Thread.Sleep(1000); Console.SetCursorPosition(55, 1); Console.Write(t); }
-
17-01-2010, 05:48 PM #7Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Làm thế này nè bạn
Mã nguồn PHP:using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading;namespace ConsoleApplication2{ class Program { public static void Main(string[] args) { GameVH obj = new GameVH(); obj.Guide(); obj.Name(); Thread thread1 = new Thread(new ThreadStart(Level1)); thread1.Start(); int t = 90; Thread.Sleep(1000); while (t >= 1) { t--; Thread.Sleep(1000); Console.SetCursorPosition(55, 1); Console.Write(t); } } public static void Level1() { int j = 0; int l = 0; Console.Clear(); do { Console.SetCursorPosition(45, 1); Console.WriteLine("Marks: "); Console.SetCursorPosition(53, 1); Console.WriteLine(RecordPoints); Console.Clear(); int Chances = 9; string Name = "countryside"; Console.SetCursorPosition(0, 1); Console.Write("Chances: "); Console.SetCursorPosition(10, 1); Console.WriteLine(Chances); Console.SetCursorPosition(45, 1); Console.WriteLine("Marks: "); Console.SetCursorPosition(0, 15); Console.WriteLine("Total Characters: {0}", Name.Length); string[] array = new string[Name.Length]; int so = 0; for (int i = 0; i < Name.Length; i++) { string len = Name.Substring(i, 1); array[so] = len; so++; } Random auto = new Random(); int value = auto.Next(so); //----------------------------------------/ int point = (50 - (Name.Length)); int diem = 0; for (int i = 0; i < Name.Length; i++) { if (array[i] == array[value]) { Console.SetCursorPosition(point, 5); Console.WriteLine(array[value]); diem++; } else { Console.SetCursorPosition(point, 5); Console.WriteLine("_"); } point += 2; } //----------------------/ j = (Name.Length) - diem; int Loop = 0; Console.SetCursorPosition(2, 10); Console.Write("Guess: "); while (Loop < Chances) { Console.SetCursorPosition(9, 10); string Guess = Console.ReadLine(); int point2 = (50 - (Name.Length)); for (int i = 0; i < Name.Length; i++) { if (Guess == array[value]) { break; } if (Guess == array[i]) { for (int y = i; y < Name.Length; y++) { if (Guess == array[y]) { Console.SetCursorPosition(point2, 5); Console.WriteLine(Guess); l++; RecordPoints++; Console.SetCursorPosition(53, 1); Console.WriteLine(RecordPoints); } point2 += 2; } break; } if (i == (Name.Length - 1)) { Loop++; int s = (Chances - Loop); Console.SetCursorPosition(10, 1); Console.WriteLine(s); if (Loop == Chances) { Console.Clear(); Console.SetCursorPosition(30, 3); Console.WriteLine("GAME OVER!"); } break; } point2 += 2; } if (j == l) { break; } } } while (j == l); } }}
Thông qua phân tích dữ liệu Google từ 86 quốc gia, mới đây, một công ty tại Anh đã công bố bảng xếp hạng kích tấc "cậu nhỏ" của các nước trên thế giới. Kết quả, hầu hết các nước xếp ở nhóm đầu của...
"Chim" của chàng trai Việt thuộc...