-
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:
- Hiển thị dữ liệu mã hóa trong datagridview
- Vẽ các đối tượng đồ họa 2 chiều trong lập trình C#
- so sánh thành viên static trong C# và java
- Sử dụng hàm API Sendmessage để gửi phím bấm tới notepad trong C#?
- xin hướng dẫn lập trình game đánh bài black jack bằng C#
- Lỗi thông dụng khi tạo form C# hay VB.net
- Chỉ học được ký tự được học sau cùng (Mạng neural)
- sử dụng postback trong httpwebrequest, httpwebresponse để lấy source trang web?
- Load dữ liệu trực tiếp vào Datagridview như thế nào ? Làm sao để sử dụng listview trong hàm static ?
- Lỗi ko thể truyền dữ liệu giữa Class và Form thông qua Properties
-
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); } }}
Giảm giá khi mua pallet nhựa Trà Vinh Tại Trà Vinh, một trong những địa điểm nổi tiếng với ngành nông nghiệp và sản xuất, pallet nhựa Trà Vinh đóng vai trò không thể phủ nhận trong quá trình vận...
Giảm giá khi mua pallet nhựa Trà...