Пример #1
0
    public bool isReadyToLaunchGame()
    {
        foreach (SharedPlayer np in Shared.inst.players)
        {
            if (!np.isReady)
            {
                return(false);
            }
        }

        if (Shared.inst.players.Count != 2)
        {
            return(false);
        }

        SharedPlayer p1 = Shared.inst.players[0];
        SharedPlayer p2 = Shared.inst.players[1];

        if (p1.role == p2.role || p1.role == 0 || p2.role == 0)
        {
            return(false);
        }

        return(true);
    }
Пример #2
0
    public SharedPlayer getOrAddPlayerById(int id)
    {
        if (id == -1)
        {
            id++;
        }

        foreach (SharedPlayer n in players)
        {
            if (n.playerID == id)
            {
                return(n);
            }
        }


        SharedPlayer newPlayer = new SharedPlayer();

        newPlayer.playerID = id;
        newPlayer.isHost   = id == 0;
        players.Add(newPlayer);

        if (MainMenu.isMultiplayerSelectedFromMenu)
        {
            LobbyMenuManager.inst.OnNewPlayerConnected(newPlayer);
        }

        return(newPlayer);
    }
Пример #3
0
    // This function uploads the score of the current player to the server
    public IEnumerator postScores()
    {
        // Put together the request URL
        SharedPlayer devicePlayer = Shared.inst.getDevicePlayer();
        string       request      = "?action=save&hat=" + (devicePlayer.role == SharedPlayer.WHITEHAT ? "white" : "black")
                                    + "&name=" + UnityWebRequest.EscapeURL(devicePlayer.username) + "&score=" + (devicePlayer.role == SharedPlayer.WHITEHAT ? Shared.inst.gameMetrics.whitehat_score : Shared.inst.gameMetrics.blackhat_score)
                                    + "&diff=" + (int)MainMenu.difficulty + "&start=" + Shared.inst.gameMetrics.startTime + "&end=" + Shared.inst.gameMetrics.endTime
                                    + "&updates=" + (devicePlayer.role == SharedPlayer.WHITEHAT ? whiteHatUpdatesRemaining() : BlackHatMenu.inst.updates_remaining);
        // TODO: How should we deal with acquiring the player's name? (Random based on IP or mac address?)

        // Send the store request
        UnityWebRequest www = UnityWebRequest.Get(databaseURL + request);

        yield return(www.Send());

        // Check to see if there are any errors
        if (www.error != null)
        {
            Debug.Log(www.error);
        }
        else
        {
            Debug.Log("Data successfully saved to server.");
        }
    }
Пример #4
0
 public string getMoveResult(Point2 from, Point2 to, SharedPlayer player)
 {
     if (player != players[turn])
     {
         return("Not your turn, cheater!");
     }
     if (!(from.x < board.GetLength(0) && from.x >= 0 && from.y < board.GetLength(1) && from.y >= 0))
     {
         return("out of bounds from point.");
     }
     if (!(to.x < board.GetLength(0) && to.x >= 0 && to.y < board.GetLength(1) && to.y >= 0))
     {
         return("out of bounds to point.");
     }
     if (board[from.x, from.y] == null)
     {
         return("there's no piece there.");
     }
     if (board[from.x, from.y].owner != turn)
     {
         return("that's not your piece!");
     }
     if (board[from.x, from.y].getAttackablePositions(from, boardSize).Contains(to) && board[to.x, to.y] != null && board[to.x, to.y].owner != turn)
     {
         //Destroy(board[to.x, to.y]);
         if (board[to.x, to.y].GetType() == typeof(King))
         {
             board[to.x, to.y]     = board[from.x, from.y];
             board[from.x, from.y] = null;
             checkPromotePawn(to);
             players[(turn + 1) % 2].RpcRecieveGameResult(false);
             players[(turn + 1) % 2].RpcRecieveTurnResult("You lose!");
             players[turn].RpcRecieveGameResult(true);
             return("You win!");
         }
         board[to.x, to.y]     = board[from.x, from.y];
         board[from.x, from.y] = null;
         checkPromotePawn(to);
         nextTurn();            //sketchu
         players[(turn + 1) % 2].RpcRecieveTurnResult("Your piece got taken!");
         return("you took a piece!");
     }
     if (board[from.x, from.y].getMovablePositions(from, boardSize).Contains(to) && board[to.x, to.y] == null)
     {
         board[to.x, to.y]     = board[from.x, from.y];
         board[from.x, from.y] = null;
         checkPromotePawn(to);
         nextTurn();
         return("move successful.");
     }
     return("That piece can't move there.");
 }
Пример #5
0
    public void setPlayerToReady(int playerID)
    {
        SharedPlayer p = getOrAddPlayerById(playerID);

        if (MainMenu.isMultiplayerSelectedFromMenu)
        {
            inst.syncEvents.Add(new SyncEvent(MessageTypes.SET_PLAYERS_READY_STATUS, p.playerID + "," + true));
        }
        else
        {
            p.isReady = true;
        }
    }
Пример #6
0
    public void setPlayerIsReady(string csv)
    {
        string[] data     = csv.Split(',');
        int      playerID = int.Parse(data[0]);
        bool     isReady  = bool.Parse(data[1]);


        SharedPlayer player = Shared.inst.getOrAddPlayerById(playerID);

        if (playerID == -1)
        {
            return;
        }

        player.isReady = isReady;
    }
Пример #7
0
    public void setPlayerSettings(string data)
    {
        string[] settings  = data.Split(',');
        int      playerID  = int.Parse(settings[0]);
        string   username  = settings[1];
        bool     isReady   = bool.Parse(settings[2]);
        int      dropValue = int.Parse(settings[3]);

        if (playerID == -1)
        {
            return;
        }

        SharedPlayer player = Shared.inst.getOrAddPlayerById(playerID);

        player.username = username;
        player.isReady  = isReady;
        player.role     = dropValue;
        // id,name,ready,role

        LobbyMenuManager.inst.OnSettingsChanged(playerID);
    }
Пример #8
0
 public void OnNewPlayerConnected(SharedPlayer p)
 {
     UpdateLobbyPlayerChanges();
 }
Пример #9
0
 public void AddPlayer(SharedPlayer player)
 {
     players.Add(player);
     Invoke("ShowBoardToNewPlayer", .00001f);
 }
Пример #10
0
 public void processMove(Point2 from, Point2 to, SharedPlayer player)
 {
     player.RpcRecieveTurnResult(getMoveResult(from, to, player));
 }