Commit 665f58a3 authored by mercury233's avatar mercury233

add hand param

parent cb1e5433
...@@ -40,6 +40,11 @@ namespace WindBot.Game.AI ...@@ -40,6 +40,11 @@ namespace WindBot.Game.AI
Enemy = Duel.Fields[1]; Enemy = Duel.Fields[1];
} }
public virtual int OnRockPaperScissors()
{
return Program.Rand.Next(1, 4);
}
public virtual bool OnSelectHand() public virtual bool OnSelectHand()
{ {
return Program.Rand.Next(2) > 0; return Program.Rand.Next(2) > 0;
......
...@@ -52,10 +52,19 @@ namespace WindBot.Game ...@@ -52,10 +52,19 @@ namespace WindBot.Game
_dialogs.SendDuelStart(); _dialogs.SendDuelStart();
} }
/// <summary>
/// Called when the AI do the rock-paper-scissors.
/// </summary>
/// <returns>1 for Scissors, 2 for Rock, 3 for Paper.</returns>
public int OnRockPaperScissors()
{
return Executor.OnRockPaperScissors();
}
/// <summary> /// <summary>
/// Called when the AI won the rock-paper-scissors. /// Called when the AI won the rock-paper-scissors.
/// </summary> /// </summary>
/// <returns>True if the AI should begin, false otherwise.</returns> /// <returns>True if the AI should begin first, false otherwise.</returns>
public bool OnSelectHand() public bool OnSelectHand()
{ {
return Executor.OnSelectHand(); return Executor.OnSelectHand();
......
...@@ -24,11 +24,13 @@ namespace WindBot.Game ...@@ -24,11 +24,13 @@ namespace WindBot.Game
private Room _room; private Room _room;
private Duel _duel; private Duel _duel;
private int _hand;
public GameBehavior(GameClient game) public GameBehavior(GameClient game)
{ {
Game = game; Game = game;
Connection = game.Connection; Connection = game.Connection;
_hand = game.Hand;
_packets = new Dictionary<StocMessage, Action<BinaryReader>>(); _packets = new Dictionary<StocMessage, Action<BinaryReader>>();
_messages = new Dictionary<GameMessage, Action<BinaryReader>>(); _messages = new Dictionary<GameMessage, Action<BinaryReader>>();
...@@ -207,7 +209,12 @@ namespace WindBot.Game ...@@ -207,7 +209,12 @@ namespace WindBot.Game
private void OnSelectHand(BinaryReader packet) private void OnSelectHand(BinaryReader packet)
{ {
Connection.Send(CtosMessage.HandResult, (byte)Program.Rand.Next(1, 4)); int result;
if (_hand > 0)
result = _hand;
else
result = _ai.OnRockPaperScissors();
Connection.Send(CtosMessage.HandResult, (byte)result);
} }
private void OnSelectTp(BinaryReader packet) private void OnSelectTp(BinaryReader packet)
......
...@@ -13,6 +13,7 @@ namespace WindBot.Game ...@@ -13,6 +13,7 @@ namespace WindBot.Game
public string Username; public string Username;
public string Deck; public string Deck;
public string Dialog; public string Dialog;
public int Hand;
private string _serverHost; private string _serverHost;
private int _serverPort; private int _serverPort;
...@@ -27,6 +28,7 @@ namespace WindBot.Game ...@@ -27,6 +28,7 @@ namespace WindBot.Game
Username = Info.Name; Username = Info.Name;
Deck = Info.Deck; Deck = Info.Deck;
Dialog = Info.Dialog; Dialog = Info.Dialog;
Hand = Info.Hand;
_serverHost = Info.Host; _serverHost = Info.Host;
_serverPort = Info.Port; _serverPort = Info.Port;
_roomInfo = Info.HostInfo; _roomInfo = Info.HostInfo;
......
...@@ -162,6 +162,9 @@ namespace WindBot ...@@ -162,6 +162,9 @@ namespace WindBot
string password = HttpUtility.ParseQueryString(RawUrl).Get("password"); string password = HttpUtility.ParseQueryString(RawUrl).Get("password");
if (password != null) if (password != null)
Info.HostInfo = password; Info.HostInfo = password;
string hand = HttpUtility.ParseQueryString(RawUrl).Get("hand");
if (hand != null)
Info.Hand = Int32.Parse(hand);
if (Info.Name == null || Info.Host == null || port == null) if (Info.Name == null || Info.Host == null || port == null)
{ {
......
...@@ -11,6 +11,7 @@ namespace WindBot ...@@ -11,6 +11,7 @@ namespace WindBot
public int Port { get; set; } public int Port { get; set; }
public string HostInfo { get; set; } public string HostInfo { get; set; }
public int Version { get; set; } public int Version { get; set; }
public int Hand { get; set; }
public WindBotInfo() public WindBotInfo()
{ {
...@@ -21,6 +22,7 @@ namespace WindBot ...@@ -21,6 +22,7 @@ namespace WindBot
Port = 7911; Port = 7911;
HostInfo = ""; HostInfo = "";
Version = 0x233C; Version = 0x233C;
Hand = 0;
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment