Esempio n. 1
0
 public bool Pass(Player to, Game g)
 {
     int passed = 0;
     for (int i = 0; i < g.playerName.Length; i++)
     {
         if (g.reg.Lookup(g.playerName[i]).passcardstatus)
             passed++;
     }
     if (passed == g.playerName.Length - 1)
     {
         return false;
     }
     if (this.last == to)
     {
         return false;
     }
     to.onpass = this.onpass;
     this.onpass = null;
     this.passcardstatus = true;
     return true;
 }
Esempio n. 2
0
 public bool Guess(bool honest, Game g)
 {
     // Reset all player to next round
     for (int i = 0; i < g.playerName.Length; i++)
     {
         g.reg.Lookup(g.playerName[i]).passcardstatus = false;
     }
     if (this.claim.Equals(this.onpass.type))
     {
         return (honest) ? true : false;
     }
     else
     {
         return (!honest) ? true : false;
     }
 }
Esempio n. 3
0
 public void Claim(string cardname, Player to, Game g)
 {
     to.claim = cardname;
     to.last_str = g.reg.getRef(this);
     to.last = this;
 }
Esempio n. 4
0
 internal static string See(Game g)
 {
     //var json = JsonConvert.SerializeObject(g, Formatting.Indented);
     var json = JsonConvert.SerializeObject(g, new JsonSerializerSettings()
     {
         ReferenceLoopHandling = ReferenceLoopHandling.Ignore
     });
     return json.ToString();
 }
Esempio n. 5
0
        public void doChat()
        {
            int requestCount = 0;
            byte[] bytesFrom = new byte[10025];
            string dataFromClient = null;
            string rCount = null;
            requestCount = 0;

            while ((true))
            {
                try
                {
                    requestCount = requestCount + 1;
                    NetworkStream networkStream = clientSocket.GetStream();
                    networkStream.Read(bytesFrom, 0, (int)clientSocket.ReceiveBufferSize);
                    dataFromClient = Encoding.ASCII.GetString(bytesFrom);
                    dataFromClient = dataFromClient.Substring(0, dataFromClient.IndexOf("$"));
                    Console.WriteLine("From Client - " + clNo + " : " + dataFromClient);
                    rCount = Convert.ToString(requestCount);

                    string response = null;
                    string player = "";
                    string ready = "";
                    if(!allReady())
                    {
                        string[] readys = dataFromClient.Split(',');
                        player = readys[0];
                        ready = readys[1];
                        if (ready.Equals("ready"))
                            playerReady[player] = true;
                        response = dataFromClient;
                    }
                    Console.WriteLine(JsonConvert.SerializeObject(this.playerReady, Formatting.Indented).ToString());
                    if (allReady())
                    {
                        if (this.g == null)
                        {
                            this.g = this.h.g;
                            if (ready.Equals("ready"))
                            {
                                response = "game.started";
                            }
                            else if (dataFromClient == "get.game.instance")
                            {
                                response = this.g.starter;
                                response += "%%" + GameMonitor.See(this.g);
                            }
                        }
                        else
                        {
                            if (dataFromClient == "get.game.instance")
                            {
                                response = this.g.starter;
                                response += "%%" + GameMonitor.See(this.g);
                            }
                            else
                            {
                                response = this.g.Input(dataFromClient);
                                response += "%" + dataFromClient+ "%"+GameMonitor.See(this.g);
                            }
                        }
                    }

                    WPF_Final_v2.HostPage.broadcast(response, clNo, false);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }
        }
Esempio n. 6
0
        private void doServer(string IP, int gameNum)
        {
            AllocConsole();
            IPAddress localaddr = IPAddress.Parse(IP);
            Int32 port = 8888;
            TcpListener serverSocket = new TcpListener(localaddr, port);
            TcpClient clientSocket = default(TcpClient);
            int counter = 0;
            serverSocket.Start();
            Console.WriteLine("Server Started...at: " + IP);
            counter = 0;
            while ((true))
            {
                counter += 1;

                clientSocket = serverSocket.AcceptTcpClient();
                byte[] bytesFrom = new byte[10025];
                String dataFromClient = null;

                NetworkStream networkStream = clientSocket.GetStream();
                networkStream.Read(bytesFrom, 0, (int)clientSocket.ReceiveBufferSize);
                dataFromClient = Encoding.ASCII.GetString(bytesFrom);
                dataFromClient = dataFromClient.Substring(0, dataFromClient.IndexOf("$"));

                clientsList.Add(dataFromClient, clientSocket);

                string msg = dataFromClient + " Joined , Wait For "+ (gameNum - counter) + " Player(s) to Join.";
                broadcast(msg, dataFromClient, false);
                string[] ready = dataFromClient.Split(',');
                playerReadyDic.Add(ready[0], false);
                Console.WriteLine(msg);
                if (gameNum == counter)
                {
                    string[] pArray = playerReadyDic.Keys.ToArray();
                    this.g = new Game(pArray);
                    Console.WriteLine("Game Instance Created.");
                }
                handleClient client = new handleClient();
                client.startClient(clientSocket, dataFromClient, clientsList, playerReadyDic, this);
            }
        }