Ejemplo n.º 1
0
        public void Start(StartPosition startPosition)
        {
            this.startPosition = startPosition;
            Render.RenderStartPosion();

            NetworkStream stream = new NetworkStream(serverSocket);

            string answer;

            sendBuffer = Encoding.Default.GetBytes("READY");
            stream.Write(sendBuffer, 0, sendBuffer.Length);

            stream.Read(recvBuffer, 0, 5);
            answer = Encoding.Default.GetString(recvBuffer);
            answer = Helper.DeleteSpaces(answer);

            Thread.Sleep(2000);

            stream.Close();

            if (answer == "BAD")
            {
                Render.RenderError("BAD");
            }
            else if (answer == "START")
            {
                new Thread(TimerHandler).Start();
                new Thread(StartSend).Start();
                new Thread(StartReceive).Start();
                new Thread(ChatHandler).Start();
                PlayHandler();
            }
        }
Ejemplo n.º 2
0
        private void TimerHandler()
        {
            sw.Start();
            Mutex mutex = new Mutex();

            while (true)
            {
                passedTime = sw.ElapsedMilliseconds / 1000;
                //mutex.WaitOne();
                //Helper.WriteAt(passedTime.ToString(), 65, 15);
                //mutex.ReleaseMutex();
                if (restartTimer)
                {
                    sw.Start();
                    restartTimer = false;
                }
                else if (passedTime > 3)
                {
                    Render.RenderError("Second player not responding");
                    runGame = false;
                    break;
                }
                Thread.Sleep(50);
            }

            sw.Stop();
        }