Skip to content

Commit

Permalink
- Doi ten tieng Anh
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Dec 20, 2010
1 parent aacafe2 commit b41ba4d
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 89 deletions.
20 changes: 17 additions & 3 deletions vcards/vCards/Gaming/GamePanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ public enum MessageID
MessageUpdate,
MessageRender,
MessageDraw,
MessageExit
MessageExit,

MouseDown,
MouseUp
}

public class GamePanel
Expand Down Expand Up @@ -56,11 +59,11 @@ public GamePanel(Control frm)

GameStateID currStateID = GameStateID.StateMenu;

public void SendMessage(MessageID messID)
public void SendMessage(MessageID messID, params object[] paras)
{
GameState target = listGameStates.Find(i => i.StateID == currStateID);
if (target != null)
target.HandleMessage(messID);
target.HandleMessage(messID, paras);
}

bool playing = true;
Expand Down Expand Up @@ -97,6 +100,17 @@ public void GameLoop()
}
}

public void GameLoop2()
{
while (playing)
{
SendMessage(MessageID.MessageRender);
SendMessage(MessageID.MessageDraw);

Thread.Sleep(10);
}
}

//MyButtonState clickState = MyButtonState.Up;
//public MyButtonState ClickState
//{
Expand Down
21 changes: 15 additions & 6 deletions vcards/vCards/Gaming/GameStates/GameState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,16 @@ public IBitmap BackIBmp
set { ibmpBack = value; }
}

public abstract void EnterState();
public abstract void UpdateState();
public abstract void RenderState();
public abstract void DrawState();
public abstract void ExitState();
public virtual void EnterState(){}
public virtual void UpdateState(){}
public virtual void RenderState(){}
public virtual void DrawState(){}
public virtual void ExitState(){}

public void HandleMessage(MessageID messID)
public virtual void OnMouseDown(params object[] paras){}
public virtual void OnMouseUp(){}

public void HandleMessage(MessageID messID, params object[] paras)
{
switch (messID)
{
Expand All @@ -67,6 +70,12 @@ public void HandleMessage(MessageID messID)
case MessageID.MessageExit:
ExitState();
break;
case MessageID.MouseDown:
OnMouseDown(paras);
break;
case MessageID.MouseUp:
OnMouseUp();
break;
default:
throw new ApplicationException("HandleMessage() : Message ID unknown.");
}
Expand Down
26 changes: 26 additions & 0 deletions vcards/vCards/Gaming/GameStates/GameStateMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,31 @@ public override void DrawState()
public override void ExitState()
{
}

public override void OnMouseDown(params object[] paras)
{
Point click = (Point)paras[0];

foreach (MyBmpButton i in buttons)
{
if (i.IsIn(click))
{
i.State = MyButtonState.Down;
}
else
i.State = MyButtonState.Up;
}
}

public override void OnMouseUp()
{
foreach (MyBmpButton i in buttons)
{
if (i.State == MyButtonState.Down)
{
i.State = MyButtonState.Up;
}
}
}
}
}
20 changes: 11 additions & 9 deletions vcards/vCards/Gaming/GameStates/GameTestState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,22 @@ public GameTestState(GamePanel gpn)
Gpnel = gpn;
StateID = GameStateID.StateMenu;
}
TapCacLaBai list;

Deck list;
public override void EnterState()
{
BackIBmp = Gpnel.IGameGracphics.CreateBitmap(Gpnel.AppPath + @"Resources\Images\Misc\MenuBkgr.bmp", true);
list = new TapCacLaBai(new Rectangle(0, 0, Gpnel.IGameGracphics.ScreenWidth, Gpnel.IGameGracphics.ScreenHeight));
LaBai.iBaseHeight = 83;
LaBai.iBaseWidth = 66;
LaBai.iMaxWidth = 22;
LaBai lb = new LaBai(4);
list = new Deck(new Rectangle(0, 0, Gpnel.IGameGracphics.ScreenWidth, Gpnel.IGameGracphics.ScreenHeight));
Card.iBaseHeight = 83;
Card.iBaseWidth = 66;
Card.iMaxWidth = 22;
Card lb = new Card(4);
list.Add(lb);
lb = new LaBai(7);
lb = new Card(7);
list.Add(lb);
lb = new LaBai(11);
lb = new Card(11);
list.Add(lb);
lb = new LaBai(27);
lb = new Card(27);
list.Add(lb);
}

Expand All @@ -54,5 +55,6 @@ public override void ExitState()
{
throw new NotImplementedException();
}

}
}
10 changes: 5 additions & 5 deletions vcards/vCards/Logic/LaBai.cs → vcards/vCards/Logic/Card.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace vCards
{
public class LaBai : MyBmpControl, IComparable<LaBai>
public class Card : MyBmpControl, IComparable<Card>
{
public static int iBaseHeight; //bề cao lá bài
public static int iBaseWidth; //bề rộng lá bài
Expand All @@ -17,12 +17,12 @@ public int Index
get { return iIndex; }
set { iIndex = value; }
}
protected LaBai()
protected Card()
{

}
public LaBai(int index)
: base(new Rectangle(0, 0, LaBai.iBaseWidth, LaBai.iBaseHeight), ResourcesManager.GetCardBitmap(index))
public Card(int index)
: base(new Rectangle(0, 0, Card.iBaseWidth, Card.iBaseHeight), ResourcesManager.GetCardBitmap(index))
{
//this.BmpBackground = ResourcesManager.GetCardBitmap(index);
iIndex = index;
Expand All @@ -31,7 +31,7 @@ public LaBai(int index)

#region IComparable<LaBai> Members

public int CompareTo(LaBai other)
public int CompareTo(Card other)
{
/* LEGEND
* < 0 means that this object is less than other
Expand Down
64 changes: 64 additions & 0 deletions vcards/vCards/Logic/Deck.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace vCards
{
public class Deck: MyUserControl
{
private List<Card> listCard = new List<Card>();
protected Deck()
{

}
public Deck(Rectangle rect): base(rect)
{

}
public void Add(Card lb)
{
if(lb!=null) listCard.Add(lb);
}
public void Remove(Card lb)
{
if (lb != null) listCard.Remove(lb);
}
public void Draw(IGraphics igr) // update vi tri truoc khi xuat
{
foreach (Card lb in listCard)
{
lb.DrawBkgr(igr);
}
}
public void UpdatePos()
{
if (listCard.Count<=0)
{
return;
}
listCard.Sort();
int denta = this.Region.Width - Card.iBaseWidth;
int dentadef = Card.iMaxWidth * listCard.Count;
int left = Region.Left;
int width = Card.iMaxWidth;
if (denta>dentadef)
{
float temp = denta - dentadef;
temp /= 2;
left += (int)temp;
}
else
{
float f = denta / (listCard.Count - 1);
width = (int)f;
}
for (int i=0; i<listCard.Count; ++i)
{
Rectangle rect = new Rectangle(left + width * i, listCard[i].Region.Y, listCard[i].Region.Width, listCard[i].Region.Height);
listCard[i].Region = rect;
}
}
}
}
64 changes: 0 additions & 64 deletions vcards/vCards/Logic/TapCacLaBai.cs

This file was deleted.

4 changes: 2 additions & 2 deletions vcards/vCards/vCards.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@
<Compile Include="Graphics\Interfaces\IBitmap.cs" />
<Compile Include="Graphics\Interfaces\IFont.cs" />
<Compile Include="Graphics\Interfaces\IGraphics.cs" />
<Compile Include="Logic\LaBai.cs" />
<Compile Include="Logic\TapCacLaBai.cs" />
<Compile Include="Logic\Card.cs" />
<Compile Include="Logic\Deck.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="frmMain.resx">
Expand Down

0 comments on commit b41ba4d

Please sign in to comment.