using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DxLibDLL;
using System.Net;
namespace DesignProject
{
partial class Scene
{
public void CreateConnect()
{
this.sceneMenu.Add(new MenuManager(this));
this.sceneMenu[this.sceneMenu.Count - 1].menu.Add(
new Menu(
this.sceneMenu[this.sceneMenu.Count - 1],
(Menu menu) =>
{
if (menu.system.key.PushMoment(DX.KEY_INPUT_UP))
{
menu.cursorY -= 1;
if (menu.cursorY < 0)
{
menu.cursorY = 0;
}
}
if (menu.system.key.PushMoment(DX.KEY_INPUT_DOWN))
{
menu.cursorY += 1;
if (menu.cursorY >= 3)
{
menu.cursorY = 2;
}
}
if (menu.system.key.PushMoment(DX.KEY_INPUT_Z))
{
switch (menu.cursorY)
{
case (0):
//ホスト
menu.parentManager.nextMenuID = 4;
break;
case (1):
//クライアント
menu.parentManager.nextMenuID = 1;
break;
case (2):
//戻る
menu.system.scene.nextSceneID = 0;
break;
default:
break;
}
}
if (menu.system.key.PushMoment(DX.KEY_INPUT_X))
{
//戻る
menu.system.scene.nextSceneID = 0;
}
return;
},
(Menu menu) =>
{
DX.DrawString(320 - 45 + 10, 240 - 100 + 10, "Connect", DX.GetColor(255, 0, 0));
DX.DrawString(320 - 50 + 10, 240 + 10, "ほすと", DX.GetColor(255, 255, 255));
DX.DrawString(320 - 50 + 10, 240 + 40, "くらいあんと", DX.GetColor(255, 255, 255));
DX.DrawString(320 - 50 + 10, 240 + 70, "もどる", DX.GetColor(255, 255, 255));
DX.DrawBox(
320 - 90 + 5,
240 + 5 + menu.cursorY * 30,
320 - 90 + 160,
240 + 5 + menu.cursorY * 30 + 25,
DX.GetColor(255, 255, 255),
DX.FALSE
);
return;
},
(Menu menu) =>
{
return;
}
)
);
this.sceneMenu[this.sceneMenu.Count - 1].menu.Add(
new Menu(
this.sceneMenu[this.sceneMenu.Count - 1],
(Menu menu) =>
{
if (menu.system.key.PushMoment(DX.KEY_INPUT_LEFT))
{
menu.cursorX -= 1;
if (menu.cursorX < 0)
{
menu.cursorX = 0;
}
}
if (menu.system.key.PushMoment(DX.KEY_INPUT_RIGHT))
{
menu.cursorX += 1;
if (menu.cursorX >= menu.system.ipAndPortArray.Length)
{
menu.cursorX = menu.system.ipAndPortArray.Length - 1;
}
}
if (menu.system.key.PushMoment(DX.KEY_INPUT_UP))
{
menu.system.ipAndPortArray[menu.cursorX] += 1;
if (menu.system.ipAndPortArray[menu.cursorX] > 9)
{
menu.system.ipAndPortArray[menu.cursorX] = 0;
}
}
if (menu.system.key.PushMoment(DX.KEY_INPUT_DOWN))
{
menu.system.ipAndPortArray[menu.cursorX] -= 1;
if (menu.system.ipAndPortArray[menu.cursorX] < 0)
{
menu.system.ipAndPortArray[menu.cursorX] = 9;
}
}
if (menu.system.key.PushMoment(DX.KEY_INPUT_Z))
{
//接続開始
Console.WriteLine(NetworkUDP.GetIPFromArray(menu.system.ipAndPortArray).ToString());
menu.parentManager.nextMenuID = 2;
}
if (menu.system.key.PushMoment(DX.KEY_INPUT_X))
{
//戻る
menu.parentManager.nextMenuID = 0;
}
return;
},
(Menu menu) =>
{
DX.DrawString(320 - 45 + 10, 240 - 100 + 10, "Connect", DX.GetColor(255, 0, 0));
for (int j = 0; j < 4; j++)
{
for (int i = 0; i < 3; i++)
{
DX.DrawString(
320 - 160 + (j * 3 + i) * 20, 240 + 10,
menu.system.ipAndPortArray[j * 3 + i].ToString(),
DX.GetColor(0, 255, 0)
);
}
if (j != 3)
{
DX.DrawString(
320 - 160 + (j * 3 + 2) * 20 + 10, 240 + 10,
".",
DX.GetColor(255, 255, 255)
);
}
else
{
DX.DrawString(
320 - 160 + (j * 3 + 2) * 20 + 10, 240 + 10,
":",
DX.GetColor(255, 255, 255)
);
}
}
for (int i = 0; i < 5; i++)
{
DX.DrawString(
320 - 160 + (3 * 4 + i) * 20, 240 + 10,
menu.system.ipAndPortArray[3 * 4 + i].ToString(),
DX.GetColor(0, 255, 0)
);
}
DX.DrawBox(
320 - 166 + menu.cursorX * 20,
240 + 5,
320 - 166 + 20 + menu.cursorX * 20,
240 + 5 + 25,
DX.GetColor(255, 0, 0),
DX.FALSE
);
return;
},
(Menu menu) =>
{
IPEndPoint clipIP = NetworkUDP.GetClipIP();
if (clipIP != null)
{
menu.system.ipAndPortArray = NetworkUDP.GetIPArray(clipIP);
}
return;
}
)
);
//クライアント側接続
this.sceneMenu[this.sceneMenu.Count - 1].menu.Add(
new Menu(
this.sceneMenu[this.sceneMenu.Count - 1],
(Menu menu) =>
{
if (menu.system.key.PushMoment(DX.KEY_INPUT_X))
{
//戻る
menu.system.udp.Close();
menu.parentManager.nextMenuID = 1;
}
if (menu.system.udp.receiveCount != 0)
{
UDPMessage message = menu.system.udp.GetReceiveMessage();
if (message.type == UDPMessage.MESSAGE_SYSTEM)
{
Console.WriteLine(message.DataToInt());
if (message.DataToInt() == UDPMessage.SYSTEM_CONNECT)
{
Console.WriteLine(NetworkUDP.GetIPFromArray(menu.system.ipAndPortArray).ToString()
+ " - " + menu.system.udp.clientEndPoint.ToString());
if (NetworkUDP.GetIPFromArray(menu.system.ipAndPortArray).ToString().Equals(
menu.system.udp.clientEndPoint.ToString()
))
{
menu.parentManager.nextMenuID = 3;
}
}
}
}
},
(Menu menu) =>
{
DX.DrawString(320 - 45 + 10, 240 - 100 + 10, "Connect", DX.GetColor(255, 0, 0));
DX.DrawString(320 - 50 + 5, 240 + 70, "connecting...", DX.GetColor(255, 255, 255));
},
(Menu menu) =>
{
menu.system.udp = new NetworkUDP(NetworkUDP.GetIPFromArray(menu.system.ipAndPortArray).Port);
menu.system.udp.StartReceiveThread();
menu.system.udp.SendSystemMessage(UDPMessage.SYSTEM_CONNECT, NetworkUDP.GetIPFromArray(menu.system.ipAndPortArray));
}
)
);
//クライアント側接続成功
this.sceneMenu[this.sceneMenu.Count - 1].menu.Add(
new Menu(
this.sceneMenu[this.sceneMenu.Count - 1],
(Menu menu) =>
{
if (menu.system.key.PushMoment(DX.KEY_INPUT_Z))
{
menu.system.udp.SendStringMessage("from Client", NetworkUDP.GetIPFromArray(menu.system.ipAndPortArray));
}
if (menu.system.udp.receiveCount != 0)
{
UDPMessage message = menu.system.udp.GetReceiveMessage();
if (message.type == UDPMessage.MESSAGE_STRING)
{
//Encoding sjisEnc = Encoding.GetEncoding("Shift_JIS");
//Console.WriteLine(sjisEnc.GetString(message.data, 0, message.dataLength) + " Received");
Console.WriteLine(message.DataToString() + " Received");
}
if (message.type == UDPMessage.MESSAGE_SYSTEM)
{
Console.WriteLine(message.DataToInt());
if (message.DataToInt() == UDPMessage.SYSTEM_CLOSE)
{
menu.system.udp.Close();
menu.parentManager.nextMenuID = 0;
}
}
}
if (menu.system.key.PushMoment(DX.KEY_INPUT_X))
{
//接続の終了
menu.system.udp.SendSystemMessage(UDPMessage.SYSTEM_CLOSE, NetworkUDP.GetIPFromArray(menu.system.ipAndPortArray));
menu.system.udp.Close();
menu.parentManager.nextMenuID = 0;
}
},
(Menu menu) =>
{
DX.DrawString(320 - 45 + 10, 240 - 100 + 10, "Connect", DX.GetColor(255, 0, 0));
DX.DrawString(320 - 50 + 5, 240 + 70, "connected!", DX.GetColor(255, 255, 255));
},
(Menu menu) =>
{
Console.WriteLine("Connected to Host");
}
)
);
//ホスト側接続待機
this.sceneMenu[this.sceneMenu.Count - 1].menu.Add(
new Menu(
this.sceneMenu[this.sceneMenu.Count - 1],
(Menu menu) =>
{
if (menu.system.key.PushMoment(DX.KEY_INPUT_X))
{
//戻る
menu.system.udp.Close();
menu.parentManager.nextMenuID = 0;
}
if (menu.system.udp.receiveCount != 0)
{
UDPMessage message = menu.system.udp.GetReceiveMessage();
if (message.type == UDPMessage.MESSAGE_SYSTEM)
{
//Console.WriteLine(BitConverter.ToInt32(message.data, 0));
Console.WriteLine(message.DataToInt());
if (message.DataToInt() == UDPMessage.SYSTEM_CONNECT)
{
menu.system.udp.SendSystemMessage(UDPMessage.SYSTEM_CONNECT, menu.system.udp.clientEndPoint);
menu.parentManager.nextMenuID = 5;
}
}
}
},
(Menu menu) =>
{
DX.DrawString(320 - 45 + 10, 240 - 100 + 10, "Connect", DX.GetColor(255, 0, 0));
DX.DrawString(320 - 50 + 5, 240 + 70, "waiting...", DX.GetColor(255, 255, 255));
},
(Menu menu) =>
{
NetworkUDP.SetClipIP();
menu.system.udp = new NetworkUDP(NetworkUDP.GetIPFromArray(menu.system.ipAndPortArray).Port);
menu.system.udp.StartReceiveThread();
}
)
);
//ホスト側接続成功
this.sceneMenu[this.sceneMenu.Count - 1].menu.Add(
new Menu(
this.sceneMenu[this.sceneMenu.Count - 1],
(Menu menu) =>
{
if (menu.system.key.PushMoment(DX.KEY_INPUT_Z))
{
menu.system.udp.SendStringMessage("from Host", menu.system.udp.clientEndPoint);
}
if (menu.system.udp.receiveCount != 0)
{
UDPMessage message = menu.system.udp.GetReceiveMessage();
if (message.type == UDPMessage.MESSAGE_STRING)
{
//Encoding sjisEnc = Encoding.GetEncoding("Shift_JIS");
//Console.WriteLine(sjisEnc.GetString(message.data, 0, message.dataLength) + " Received");
Console.WriteLine(message.DataToString() + " Received");
}
if (message.type == UDPMessage.MESSAGE_SYSTEM)
{
//Console.WriteLine(BitConverter.ToInt32(message.data, 0));
Console.WriteLine(message.DataToInt());
if (message.DataToInt() == UDPMessage.SYSTEM_CLOSE)
{
menu.system.udp.Close();
menu.parentManager.nextMenuID = 0;
}
}
}
if (menu.system.key.PushMoment(DX.KEY_INPUT_X))
{
//戻る
menu.system.udp.SendSystemMessage(UDPMessage.SYSTEM_CLOSE, menu.system.udp.clientEndPoint);
menu.system.udp.Close();
menu.parentManager.nextMenuID = 0;
}
},
(Menu menu) =>
{
DX.DrawString(320 - 45 + 10, 240 - 100 + 10, "Connect", DX.GetColor(255, 0, 0));
DX.DrawString(320 - 50 + 5, 240 + 70, "connected!", DX.GetColor(255, 255, 255));
},
(Menu menu) =>
{
Console.WriteLine("Connected from Client");
}
)
);
}
}
}
最終更新:2011年01月17日 02:07