Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
minhkhanhhaugiang committed Jan 13, 2011
1 parent a8f19ab commit 08a5410
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 20 deletions.
9 changes: 7 additions & 2 deletions vcards/BlueAI/BlueAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,22 @@ public void OnOtherLeavePlay(PlayerInfo pInfo)
throw new NotImplementedException();
}

public void OnTurnToOtherPlayer(PlayerInfo pInfo)
{
throw new NotImplementedException();
}

public void OnServerPhatBai(PackLogical pack)
{
throw new NotImplementedException();
}

public PackLogical OnTurnToMe(BuocDi buoc)
public CardCombination OnTurnToMe(BuocDi buoc)
{
throw new NotImplementedException();
}

public void OnOnePlayerGo(PlayerInfo player, CardCombination cards)
public void OnOtherPlayerGo(PlayerInfo player, CardCombination cards)
{
throw new NotImplementedException();
}
Expand Down
9 changes: 7 additions & 2 deletions vcards/ChickenAI/ChickenAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,22 @@ public void OnOtherLeavePlay(PlayerInfo pInfo)
throw new NotImplementedException();
}

public void OnTurnToOtherPlayer(PlayerInfo pInfo)
{
throw new NotImplementedException();
}

public void OnServerPhatBai(PackLogical pack)
{
throw new NotImplementedException();
}

public PackLogical OnTurnToMe(BuocDi buoc)
public CardCombination OnTurnToMe(BuocDi buoc)
{
throw new NotImplementedException();
}

public void OnOnePlayerGo(PlayerInfo player, CardCombination cards)
public void OnOtherPlayerGo(PlayerInfo player, CardCombination cards)
{
throw new NotImplementedException();
}
Expand Down
9 changes: 5 additions & 4 deletions vcards/ShareLibrary/InterfaceAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ namespace ShareLibrary
public interface InterfaceAI
{
string NameAI { get; }
void OnOtherJoinPlay(PlayerInfo pInfo);
void OnOtherLeavePlay(PlayerInfo pInfo);
void OnOtherJoinPlay(PlayerInfo pInfo);// ham nay chua can dung, thuat toan cao moi can dung
void OnOtherLeavePlay(PlayerInfo pInfo);// ham nay chua can dung, thuat toan cao moi can dung
void OnTurnToOtherPlayer(PlayerInfo player);// ham nay chua can dung, thuat toan cao moi can dung
void OnServerPhatBai(PackLogical pack);
PackLogical OnTurnToMe(BuocDi buoc); // tra ve null neu ko di ma bo luot
void OnOnePlayerGo(PlayerInfo player, CardCombination cards);
CardCombination OnTurnToMe(BuocDi buoc); // tra ve null neu ko di ma bo luot
void OnOtherPlayerGo(PlayerInfo player, CardCombination cards);
}
}
9 changes: 7 additions & 2 deletions vcards/SolarAI/SolarAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,22 @@ public void OnOtherLeavePlay(PlayerInfo pInfo)
throw new NotImplementedException();
}

public void OnTurnToOtherPlayer(PlayerInfo pInfo)
{
throw new NotImplementedException();
}

public void OnServerPhatBai(PackLogical pack)
{
throw new NotImplementedException();
}

public PackLogical OnTurnToMe(BuocDi buoc)
public CardCombination OnTurnToMe(BuocDi buoc)
{
throw new NotImplementedException();
}

public void OnOnePlayerGo(PlayerInfo player, CardCombination cards)
public void OnOtherPlayerGo(PlayerInfo player, CardCombination cards)
{
throw new NotImplementedException();
}
Expand Down
4 changes: 2 additions & 2 deletions vcards/vCards/Gaming/GameManagerServer/BanChoi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public bool OnPlayerSkip(int iIndex)

return true;
}
private void TurnToOtherPlayer()//bao cho nguoi choi biet luot den voi nguoi choi khac
private void TurnToOtherPlayer()//bao cho moi nguoi choi biet luot den voi nguoi choi khac tru nguoi dang co luot
{
foreach (PlayerServer pl in player)
{
Expand All @@ -129,7 +129,7 @@ private void TurnToOtherPlayer()//bao cho nguoi choi biet luot den voi nguoi cho
}
}
}
private void TurnToOtherPlayer(CardCombination cards)//bao cho nguoi choi biet luot den voi nguoi choi khac
private void TurnToOtherPlayer(CardCombination cards)//bao cho moi nguoi choi biet co nguoi di bai
{
foreach (PlayerServer pl in player)
{
Expand Down
37 changes: 30 additions & 7 deletions vcards/vCards/Gaming/GameManagerServer/PlayerClientAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,48 @@
namespace vCards
{
class PlayerClientAI: PlayerClient
{
public PlayerClientAI(PlayerInfo playerinfo)
{
InterfaceAI objAI = null;
public PlayerClientAI(PlayerInfo playerinfo, string strNameAI)
: base(playerinfo)
{

objAI = QuanLyAI.CreateObjAIByName(strNameAI);
if (objAI==null) // ten dua vao ko co thi dung cai dau tien
{
objAI = QuanLyAI.CreateObjAIByIndex(0);
}
}
public override void OnServerPhatBai(PackLogical pack)
{
base.OnServerPhatBai(pack);
objAI.OnServerPhatBai(pack);
}
public override void OnTurnToMe(BuocDi buoc)
{
base.OnTurnToMe(buoc);
if (buoc.Cards==null)
//if (buoc.Cards==null)//code dung test den luot cua minh ma la luot moi thi di con rac
//{
// CardCombination card = CardCombination.CreateCombination(packLogic.ListCards[0]);
// base.SendBaiPlayerDanh(card);
//}
//else SendPlayerSkip();
CardCombination cards = objAI.OnTurnToMe(buoc);
if (cards == null)
{
SendPlayerSkip();
}
else
{
SendBaiPlayerDanh(cards);
}
}
public override void OnOnePlayerGo(PlayerInfo player, CardCombination cards)
{
base.OnOnePlayerGo(player, cards);
if (player.IdPlayer!=info.IdPlayer)
{
CardCombination card = CardCombination.CreateCombination(packLogic.ListCards[0]);
base.SendBaiPlayerDanh(card);
objAI.OnOtherPlayerGo(player, cards);
}
else SendPlayerSkip();
}
}
}
2 changes: 1 addition & 1 deletion vcards/vCards/Gaming/GameStates/GameStateCustom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public override void InitControls()
banChoi = BanChoi.Create();
player1 = new PlayerClientUser(new PlayerInfo("Khanh"));
player1.JoinPlay();
player2 = new PlayerClientAI(new PlayerInfo("MinhAI"));
player2 = new PlayerClientAI(new PlayerInfo("MinhAI"), "Chicken AI");
player2.JoinPlay();
banChoi.NewGame(); // tao game moi phat bai cho client de hien thi len
//((PlayerClientUser)player1).Rearrange(gamePanel.GameGraphics);
Expand Down
37 changes: 37 additions & 0 deletions vcards/vCards/QuanLyAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,42 @@ public static string[] GetAINameList()
}
return temp.ToArray();
}
public static InterfaceAI CreateObjAIByName(string strName)
{
string strPath = System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName;
strPath = strPath.Replace(System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0].Name, "");
foreach (string fileName in Directory.GetFiles(strPath))
{
//Tạo biến giữ thông tin file
FileInfo file = new FileInfo(fileName);
//Nếu file có đuôi là dll thì ok
if (file.Extension.Equals(".dll"))
{
Assembly asm = Assembly.LoadFrom(fileName);
foreach (Type loai in asm.GetTypes())
{
foreach (Type face in loai.GetInterfaces())
{
if (face.FullName == "ShareLibrary.InterfaceAI")
{
InterfaceAI t = (InterfaceAI)Activator.CreateInstance(asm.GetType(loai.ToString()));
if (t.NameAI==strName)
{
return t;
}
}
}
}
}
}
return null;
}

public static InterfaceAI CreateObjAIByIndex(int iNum)
{
string[] temp = GetAINameList();
if (temp.Count() > 0) return CreateObjAIByName(temp[0]);
return null;
}
}
}
2 changes: 2 additions & 0 deletions vcards/vCards/frmMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Text;
using System.Windows.Forms;
using System.Threading;
using ShareLibrary;

namespace vCards
{
Expand All @@ -24,6 +25,7 @@ public frmMain()
InitializeComponent();

string[] str = QuanLyAI.GetAINameList();
InterfaceAI tmp = QuanLyAI.CreateObjAIByName("Chicken AI");

gamePanel = new GamePanel(this);
resrcManager = new MyResourceManager(gamePanel.GameGraphics);
Expand Down

0 comments on commit 08a5410

Please sign in to comment.