Ejemplo n.º 1
0
 // Use this for initialization
 void Start()
 {
     togglePressed();
     setMoveSpeed();
     TCPLocalConnection.startServer(4000);
     SinglePlayerGameMaster.init(takeInput, () => {});
 }
Ejemplo n.º 2
0
        public void requestMove(NetworkMessage boardMsg)
        {
            byte[] bytes = boardMsg.reader.ReadBytesAndSize();
            string msg   = Game.ClientController.Deserialize <Game.CommProtocol.StringMessage> (bytes).msg;

            TCPLocalConnection.sendMessage(msg);
        }
        public void handleGameInfo(NetworkMessage msg)
        {
            byte[]   bytes   = msg.reader.ReadBytesAndSize();
            GameInfo infoMsg = Game.ClientController.Deserialize <GameInfo> (bytes);;

            if (infoMsg.gameOver)
            {
                string gameOverString = TCP_API.APIStandardConstants.Fields.gameOver;
                TCPLocalConnection.sendMessage(gameOverString);
                isGameOver = true;
                UnetRoomConnector.shutdownCurrentConnection();

                string gameOverMsg;
                if (infoMsg.winnerColor == Game.PlayerColor.None)
                {
                    gameOverMsg = "It's a draw!";
                }
                else
                {
                    gameOverMsg = infoMsg.winnerColor + " won";
                }

                CurrentGame.gameOver(gameOverMsg);
            }
        }
Ejemplo n.º 4
0
        public void handleGameStatus(NetworkMessage gameStatusMsg)
        {
            byte[]   bytes = gameStatusMsg.reader.ReadBytesAndSize();
            GameInfo msg   = ClientController.Deserialize <GameInfo> (bytes);

            if (msg.gameOver)
            {
                string gameOverString = TCP_API.APIStandardConstants.Fields.gameOver;
                TCPLocalConnection.sendMessage(gameOverString);
                gameOver();
                waitingForInput = false;

                string gameOverMsg;
                if (msg.winnerColor == PlayerColor.None)
                {
                    gameOverMsg = "It's a draw!";
                }
                else
                {
                    gameOverMsg = msg.winnerColor + " won";
                }

                CurrentGame.gameOver(gameOverMsg);
            }
        }
        private void simulateFree(List <MemorySegment> allocList)
        {
            int freePos = allocList [Random.Range(0, allocList.Count - 1)].pos;

            TCPLocalConnection.sendMessage("Free " + freePos);
            print("Free " + freePos);
        }
Ejemplo n.º 6
0
    public void restartGame()
    {
        foreach (GameObject g in discs)
        {
            Destroy(g);
        }
        discs.Clear();

        foreach (TowerPole tp in poles)
        {
            tp.amountOfDiscs = 0;
        }
        board.Clear();


        board.Add(new List <int> ());
        board.Add(new List <int> ());
        board.Add(new List <int> ());

        for (int i = 0; i < (int)amountSlider.value; i++)
        {
            discs.Add(Instantiate(discPrefab, poles [0].addDisc(), Quaternion.identity));
            discs [discs.Count - 1].GetComponent <TowerDisc> ().init(materials [i], i);
            board [0].Add(i);
        }

        moveCounter = 0;
        wonGame     = false;
        TCPLocalConnection.sendMessage(formatBoard());
    }
Ejemplo n.º 7
0
 public static void init(GameConnectorUI connector)
 {
     gameConnector = connector;
     TCPLocalConnection.subscribeToTCPStatus(TCPStatusChanged);
     ClientUIOverlord.onUIStateChanged += UIStateChanged;
     Msf.Server.SetHandler((short)ServerCommProtocl.GameRoomInvite, handleStartGame);
 }
        private void simulateMalloc(List <MemorySegment> freeList)
        {
            int allocationSize = calcAllocSize();

            TCPLocalConnection.sendMessage("Malloc " + allocationSize);
            print("Malloc " + allocationSize);
        }
        public void handleGameInfoMsg(NetworkMessage initMsg)
        {
            GameInfo msg = Deserialize <GameInfo> (initMsg.reader.ReadBytesAndSize());

            if (msg.gameOver)
            {
                isGameOver        = true;
                canSendServerMsg  = false;
                isListeningForTCP = false;


                UnetRoomConnector.shutdownCurrentConnection();

                string gameOverString = TCP_API.APIStandardConstants.Fields.gameOver;
                string gameOverMsg;
                //Debug.LogError ("Winner: " + msg.winnerColor);
                if (msg.winnerColor == Game.PlayerColor.None)
                {
                    gameOverMsg = "It's a draw!";
                    TCPLocalConnection.sendMessage(gameOverString + ": 0");
                }
                else
                {
                    gameOverMsg = msg.winnerColor + " won";
                    TCPLocalConnection.sendMessage(gameOverString + ": " + (msg.winnerColor == PlayerColor.Blue ? "1" : "-1"));
                }
                CurrentGame.gameOver(gameOverMsg);
            }
        }
Ejemplo n.º 10
0
        public void handleGameState(NetworkMessage gameStateMsg)
        {
            byte[]    bytes    = gameStateMsg.reader.ReadBytesAndSize();
            GameState stateMsg = Game.ClientController.Deserialize <GameState> (bytes);

            localRenderer.updatePlayerPosition(stateMsg.currentPos, stateMsg.currentTarget, stateMsg.time);
            TCPLocalConnection.sendMessage(stateMsg.currentPos.ToString());
        }
Ejemplo n.º 11
0
    void Start()
    {
        if (TCPLocalConnection.isReady == false)
        {
            TCPLocalConnection.init();
        }

        //	Destroy (gameObject);
    }
        public void freeButtonPressed()
        {
            MemorySegment selectedSeg = segmentClicker.getSelectedSegment();

            if (selectedSeg != null)
            {
                TCPLocalConnection.sendMessage("Free " + selectedSeg.pos);
            }
        }
Ejemplo n.º 13
0
    public void gameOver()
    {
        moveQ.Clear();
        playing = false;
        string gameOverString = TCP_API.APIStandardConstants.Fields.gameOver;

        TCPLocalConnection.sendMessage(gameOverString + ": " + logic.getCurrentScore());
        //restartGame ();
    }
Ejemplo n.º 14
0
 void Start()
 {
     ClientUIOverlord.onUIStateChanged += (ClientUIStates newState) => { if (newState != ClientUIStates.PreGame)
                                                                         {
                                                                             resetPanel();
                                                                         }
     };
     TCPLocalConnection.subscribeToTCPStatus(locAlbotStatusChanged);
 }
Ejemplo n.º 15
0
    public static void startSinglePlayerLobby(PreGameBaseLobby theLobby, MapSelection theGame)
    {
        lobby   = theLobby;
        gameMap = theGame;
        singleton.realSinglePlayerLobby.setScene(gameMap.Scene);

        ClientUIOverlord.onUIStateChanged += UIStateChanged;
        TCPLocalConnection.subscribeToTCPStatus(tcpStatusChanged);
        playingSinglePlayerGame = true;
    }
Ejemplo n.º 16
0
 void Start()
 {
     TCPLocalConnection.subscribeToTCPStatus(TCPStatusChanged);
     TCPMessageQueue.readMsgInstant = takeInput;
     TCPLocalConnection.startServer(4000);
     //SinglePlayerGameMaster.init (takeInput, restartGame);
     logic.init(gameOver, roundFinished, updateScoreText);
     slideSpeed = moveSpeedSlider.value;
     //restartGame ();
 }
Ejemplo n.º 17
0
        private void sendStartMsg(SortingVisualNumber[] numbers)
        {
            string s = "";

            foreach (SortingVisualNumber n in numbers)
            {
                s += n.value + " ";
            }
            TCPLocalConnection.sendMessage(s);
        }
    void Awake()
    {
        if (hasInit)
        {
            return;
        }
        hasInit = true;

        singleton = this;
        TCPLocalConnection.subscribeToTCPStatus(TCPStatusChanged);
    }
Ejemplo n.º 19
0
 void Start()
 {
     if (ClientUI.ClientUIOverlord.hasLoaded)
     {
         return;
     }
     instance = this;
     //TCPLocalConnection.TCPStatusChanged += listenForTCPUpdate;
     TCPLocalConnection.subscribeToTCPStatus(UpdateStatusView);
     UpdateStatusView(ConnectionStatus.Disconnected);
 }
Ejemplo n.º 20
0
        public void startButtonPressed()
        {
            int arraySize = int.Parse(arraySizeField.text);

            numbers = controller.startNewSession(arraySize, 0, 99);
            theAnimator.init(numbers);

            TCPLocalConnection.stopServer();
            TCPLocalConnection.startServer(4000);
            gameStarted = true;
        }
        private void instantReadTCPMsg(ReceivedLocalMessage msg)
        {
            if (msg.message == "JUMP")
            {
                localPlayer.activateJump();
            }

            MainThread.fireEventAtMainThread(() => {
                print("Sending msg");
                TCPLocalConnection.sendMessage(formatBoard());
            });
        }
Ejemplo n.º 22
0
    private void waitForConnection()
    {
        isWaitingForConnection = true;
        TCPLocalConnection.fireTCPStatusChange(ConnectionStatus.Connecting);
        client = server.AcceptTcpClient();
        stream = client.GetStream();

        clientConnected = true;
        TCPLocalConnection.clientConnected(client);
        isWaitingForConnection = false;
        TCPLocalConnection.fireTCPStatusChange(ConnectionStatus.Connected);
    }
Ejemplo n.º 23
0
        public static void startNewSession(GameType type, Action startFunc, int port = 4000)
        {
            TCPLocalConnection.init();
            currentGameType = type;
            onStartFunc     = startFunc;
            if (type == GameType.Connect4)
            {
                router = new Connect4.Connect4APIRouter();
            }

            TCPLocalConnection.startServer(port);
            TCPLocalConnection.subscribeToTCPStatus(onBotConnected);
        }
Ejemplo n.º 24
0
 private void playMove()
 {
     if (moveQ.Count == 0)
     {
         TCPLocalConnection.sendMessage(logic.formatBoard());
     }
     else
     {
         int tempMove = moveQ [0];
         moveQ.RemoveAt(0);
         logic.playMove(tempMove);
     }
 }
Ejemplo n.º 25
0
 void Start()
 {
     if (hasInit)
     {
         return;
     }
     hasInit = true;
     TCPLocalConnection.subscribeToTCPStatus(locAlbotStatusChanged);
     ClientUIOverlord.onUIStateChanged += (ClientUIStates newState) => { if (newState != ClientUIStates.PreGame)
                                                                         {
                                                                             gameObject.SetActive(false);
                                                                         }
     };
 }
Ejemplo n.º 26
0
        private void requestBoard()
        {
            if (initBoard)
            {
                console.text = "Invalid start board";
            }
            else
            {
                console.text = "Waiting for board";
            }

            TCPLocalConnection.sendMessage("InitBoard");
            initBoard = true;
        }
Ejemplo n.º 27
0
        public void startServerClicked(bool forceOpen = false)
        {
            if (canOpenPort == false && forceOpen == false)
            {
                return;
            }

            LocalConnectionStatus status = TCPLocalConnection.startServer(int.Parse(portNumber.text));

            errorOpeningPort = status != LocalConnectionStatus.connecting;
            if (status != LocalConnectionStatus.connecting)
            {
                displayPortError(status);
            }
        }
Ejemplo n.º 28
0
        public void handleGameStatus(NetworkMessage gameStatusMsg)
        {
            byte[]   bytes = gameStatusMsg.reader.ReadBytesAndSize();
            GameInfo msg   = Deserialize <GameInfo> (bytes);

            if (msg.gameOver && isGameOver == false)
            {
                BoardState finalState = getFinalState(msg.winnerColor);
                TCPLocalConnection.sendMessage(Connect4JsonParser.formatBoardMsgFromServer(lastRawBoard, msg.myColor, finalState));
                localRenderer.onGameOver(msg.winnerColor == PlayerColor.Yellow ? Piece.Yellow : Piece.Red);

                gameOver();
                CurrentGame.gameOver(getGameOverText(msg.winnerColor));
            }
        }
Ejemplo n.º 29
0
        private static void onBotConnected(ConnectionStatus status)
        {
            if (status == ConnectionStatus.Disconnected)
            {
                TCPLocalConnection.restartServer();
                return;
            }

            if (status != ConnectionStatus.Connected)
            {
                return;
            }

            onStartFunc();
            TCPLocalConnection.sendMessage(currentGameType + " API session started.");
        }
Ejemplo n.º 30
0
 public void takeInput(string msg)
 {
     if (isMainPlayer())
     {
         TCPLocalConnection.sendMessage(msg);
     }
     else if (NPC)
     {
         bot.onReceiveInput(msg);
     }
     else if (Human)
     {
         onHumanTakeInput();
     }
     //Do nothing if us human
 }