2008-12-19 00:39:56 +00:00
|
|
|
/***************************************************************************
|
2008-12-19 00:36:04 +00:00
|
|
|
* Copyright (C) 2008 by Lothar May *
|
|
|
|
|
* *
|
|
|
|
|
* This file is part of pokerth_console. *
|
|
|
|
|
* pokerth_console is free software: you can redistribute it and/or *
|
|
|
|
|
* modify it under the terms of the GNU Affero General Public License *
|
|
|
|
|
* as published by the Free Software Foundation, either version 3 of *
|
|
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
|
* *
|
|
|
|
|
* pokerth_console is distributed in the hope that it will be useful, *
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
|
* *
|
|
|
|
|
* You should have received a copy of the *
|
|
|
|
|
* GNU Affero General Public License along with pokerth_console. *
|
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>. *
|
2008-12-19 00:39:56 +00:00
|
|
|
***************************************************************************/
|
2008-12-19 00:36:04 +00:00
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading;
|
2008-12-23 17:24:31 +00:00
|
|
|
using pokerth_lib;
|
2008-12-19 00:36:04 +00:00
|
|
|
|
|
|
|
|
namespace pokerth_console
|
|
|
|
|
{
|
|
|
|
|
class Program
|
|
|
|
|
{
|
|
|
|
|
static int Main(string[] args)
|
|
|
|
|
{
|
2008-12-25 21:12:59 +00:00
|
|
|
Console.WriteLine("pokerth_console V0.1 - Copyright (C) 2008 by Lothar May");
|
|
|
|
|
Console.WriteLine("See license.txt for license terms.");
|
|
|
|
|
Console.WriteLine();
|
|
|
|
|
Console.WriteLine("Enter your nickname:");
|
|
|
|
|
string name = Console.ReadLine();
|
|
|
|
|
Console.WriteLine("Connecting to server...");
|
2008-12-19 10:26:02 +00:00
|
|
|
Settings settings = new Settings();
|
2008-12-25 21:12:59 +00:00
|
|
|
PokerTHData data = new PokerTHData(name);
|
2008-12-23 02:15:49 +00:00
|
|
|
ConsoleCallback callback = new ConsoleCallback();
|
|
|
|
|
Client client = new Client(settings, data, callback);
|
2008-12-19 10:26:02 +00:00
|
|
|
client.Connect();
|
2008-12-21 14:23:40 +00:00
|
|
|
client.Start();
|
2008-12-23 02:15:49 +00:00
|
|
|
Thread.Sleep(2000);
|
2008-12-25 21:12:59 +00:00
|
|
|
string input;
|
|
|
|
|
bool joined = false;
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Open Games:");
|
|
|
|
|
Console.Write(data.GameList.GetOpenGamesString());
|
|
|
|
|
Console.WriteLine();
|
|
|
|
|
Console.WriteLine("Enter game id (or press enter to refresh)");
|
|
|
|
|
input = Console.ReadLine();
|
|
|
|
|
} while (input == "" || !Char.IsDigit(input[0]));
|
|
|
|
|
Console.WriteLine("Joining game...");
|
|
|
|
|
uint gameId = Convert.ToUInt32(input);
|
|
|
|
|
client.JoinGame(gameId);
|
2008-12-26 13:54:36 +00:00
|
|
|
// Hack this, because Mono does not support WaitOne(...).
|
|
|
|
|
DateTime cur = DateTime.Now;
|
|
|
|
|
while (!client.HasJoinedGame())
|
|
|
|
|
{
|
|
|
|
|
Thread.Sleep(15);
|
|
|
|
|
if (DateTime.Now.Subtract(cur).Seconds > 5)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (client.HasJoinedGame())
|
2008-12-25 21:12:59 +00:00
|
|
|
joined = true;
|
|
|
|
|
else
|
|
|
|
|
Console.WriteLine("Could not join game.");
|
|
|
|
|
} while (!joined);
|
|
|
|
|
Console.WriteLine("Waiting for admin to start the game...");
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
do
|
|
|
|
|
{
|
2008-12-26 13:54:36 +00:00
|
|
|
while (Console.KeyAvailable)
|
|
|
|
|
Console.ReadKey();
|
2008-12-25 21:12:59 +00:00
|
|
|
input = Console.ReadLine();
|
|
|
|
|
} while (input == "");
|
|
|
|
|
Hand.Action action = Hand.Action.None;
|
|
|
|
|
uint bet = 0;
|
2008-12-26 13:54:36 +00:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
switch (input[0])
|
|
|
|
|
{
|
|
|
|
|
case 'f':
|
|
|
|
|
action = Hand.Action.Fold;
|
|
|
|
|
break;
|
|
|
|
|
case 'c':
|
|
|
|
|
action = Hand.Action.Check;
|
|
|
|
|
break;
|
|
|
|
|
case 'l':
|
|
|
|
|
action = Hand.Action.Call;
|
|
|
|
|
break;
|
|
|
|
|
case 'b':
|
|
|
|
|
action = Hand.Action.Bet;
|
|
|
|
|
bet = Convert.ToUInt32(input.Substring(1));
|
|
|
|
|
break;
|
|
|
|
|
case 'r':
|
|
|
|
|
action = Hand.Action.Raise;
|
|
|
|
|
bet = Convert.ToUInt32(input.Substring(1));
|
|
|
|
|
break;
|
|
|
|
|
case 'a':
|
|
|
|
|
action = Hand.Action.AllIn;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (action != Hand.Action.None)
|
|
|
|
|
client.MyAction(action, bet);
|
|
|
|
|
}
|
|
|
|
|
catch (FormatException)
|
2008-12-25 21:12:59 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
} while (true);
|
2008-12-21 17:38:59 +00:00
|
|
|
client.SetTerminateFlag();
|
2008-12-19 10:26:02 +00:00
|
|
|
client.WaitTermination();
|
2008-12-19 00:36:04 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|