PDA

View Full Version : cho Mình Hỏi Ve Mảng ArayList Trong C# Ti Ai pro chi voi



thangkho0909
19-09-2010, 01:18
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Collections;

namespace ConsoleApplication7
{
class Game
{
public int n;
public string Player1;
public string Player2;
public string Player3;
public string Player4;
Random random = new Random();
int index;
int songuoichoi;
int count = 0;



public void player()
{

do
{
Console.WriteLine("the first player to collect five cards of the sane the game .");
Console.Write("Enter the Number of player <2-4>:");
n = Convert.ToInt32(Console.ReadLine());
}
while (n < 2);

switch (n)
{
case 2:
songuoichoi = 2;
Console.Write("Nhap Ten Nguoi Choi 1:");
Player1 = Convert.ToString(Console.ReadLine());
Console.Write("Nhap Ten Nguoi Choi 2:");
Player2 = Convert.ToString(Console.ReadLine());

break;
case 3:
songuoichoi = 3;
Console.Write("Nhap Ten Nguoi Choi 1:");
Player1 = Convert.ToString(Console.ReadLine());
Console.Write("Nhap Ten Nguoi Choi 2:");
Player2 = Convert.ToString(Console.ReadLine());
Console.Write("Nhap Ten Nguoi Choi 3:");
Player3 = Convert.ToString(Console.ReadLine());
break;
case 4:
songuoichoi = 4;
Console.Write("Nhap Ten Nguoi Choi 1:");
Player1 = Convert.ToString(Console.ReadLine());
Console.Write("Nhap Ten Nguoi Choi 2:");
Player2 = Convert.ToString(Console.ReadLine());
Console.Write("Nhap Ten Nguoi Choi 3:");
Player3 = Convert.ToString(Console.ReadLine());
Console.Write("Nhap Ten Nguoi Choi 4:");
Player4 = Convert.ToString(Console.ReadLine());
break;



}

}

string[] bobai = new string[52];
string[] play1 = new string[6];
string[] play2 = new string[6];
string[] play3 = new string[6];
string[] play4 = new string[6];
string[] luubai = new string[52];
string data;
public void QuanBai()
{

StreamReader sr = new StreamReader(new FileStream(@"F:\text\QuanBai.txt", FileMode.Open, FileAccess.Read));
data = sr.ReadLine();
while (data != null)
{
bobai[index] = data;
index++;
data = sr.ReadLine();

}
sr.Close();
}
public void ChiaBai(int luot)
{

index = random.Next(0, 52);
ArrayList array = new ArrayList();


// if (luot == 1)
//{
//__________________________________________________ _
Console.WriteLine("Player 1:" + Player1);

for (count = 0; count < play1.Length - 1; count++)
{
index = random.Next(0, 52);
array.Add(index);
play1[count] = bobai[index];
Console.WriteLine("." + play1[count]);
array.Remove(index);


}
//}
// else

// if (luot == 2)
//{

//__________________________________________________ _____________________6
Console.WriteLine("___________________");
Console.WriteLine("Player 2:" + Player2);
for (count = 0; count < play2.Length - 1; count++)
{



index = random.Next(0, 52);
array.Add(index);
play2[count] = bobai[index];
Console.WriteLine("." + play2[count]);
array.Remove(index);
}
//}
//else
// if (luot == 3)
// {
//__________________________________________________ _____________________6
Console.WriteLine("___________________");
Console.WriteLine("Player 2:" + Player3);
for (count = 0; count < play2.Length - 1; count++)
{
index = random.Next(0, 52);
array.Add(index);
play3[count] = bobai[index];
Console.WriteLine("." + play3[count]);
array.Remove(index);
}
// }


}
}












class Program
{
static void Main(string[] args)
{
Game g = new Game();

g.player();
g.QuanBai();
g.ChiaBai(1);



}
}
}

Mình Bi sai Ngay CHo Gan Cai Mang Play1,Play2,Play3 Cho mang ArayList BoBai
day La Link Cua cái File Minh Bị Lỗi Vói7 Cai File QuanBai Ne`:
http://www.mediafire.com/myfiles.php