Example #1
0
    public static void SavePlayerData(PlayerSwitcher player, int playerNum)
    {
        // save to file (in progress)
        string data = JsonUtility.ToJson(player);

        SaveDataToFile(data, @"Data\Player" + playerNum + ".txt");
    }
 /// <summary>
 /// Creates a new <see cref="FourInARowGame"/>.
 /// </summary>
 /// <param name="playerOne">Name of player one.</param>
 /// <param name="playerTwo">Name of player two.</param>
 /// <param name="boardSize">The <see cref="BoardSize"/>.</param>
 public FourInARowGame(string playerOneName, string playerTwoName, BoardSize boardSize)
 {
     PlayerOne       = new Player(playerOneName, BoardSlotValue.P1);
     PlayerTwo       = new Player(playerTwoName, BoardSlotValue.P2);
     _boardGrid      = new BoardGrid(boardSize);
     _playerSwitcher = new PlayerSwitcher(new [] { PlayerOne, PlayerTwo });
 }
Example #3
0
    IEnumerator WaitSecond()
    {
        psScript = GameObject.Find("GameManager").GetComponent <PlayerSwitcher>();
        yield return(new WaitForSeconds(0.5f));

        psScript.stopFirstClick = true;
    }
Example #4
0
    public static PlayerSwitcher LoadPlayerData(int playerNum)
    {
        // load from file (in progress)
        string         data   = ReedDataFromFile(@"Data\Player" + playerNum + ".txt");
        PlayerSwitcher loaded = JsonUtility.FromJson <PlayerSwitcher>(data);

        return(loaded);
    }
Example #5
0
        public void PlayerInGroupAndPlayerInGroupSwitchesMatches(string player1Name, int group1Index, string player2Name, int group2Index)
        {
            GroupBase group1 = createdGroups[group1Index];
            GroupBase group2 = createdGroups[group2Index];

            Player player1 = FindPlayerInGroup(player1Name, group1);
            Player player2 = FindPlayerInGroup(player2Name, group2);

            PlayerSwitcher.SwitchMatchesOn(player1, player2);
        }
Example #6
0
        public void MatchBetIsRemovedWhenMatchLayoutIsChangedInOneMatch()
        {
            Better better = tournament.AddBetter(user);

            better.PlaceMatchBet(match, match.Player1);

            PlayerSwitcher.SwitchMatchesOn(match.Player1, match.Player2);

            better.Bets.Should().BeEmpty();
        }
Example #7
0
    void Start()
    {
        rangeMin = -(spotlight.spotAngle * .82f) / 100;
        rangeMax = -rangeMin;
        switcher = Camera.main.GetComponent <PlayerSwitcher> ();

        float totalAngle = rangeMax - rangeMin;

        raySpacing = totalAngle / numRays;
    }
Example #8
0
        public void MatchBetIsRemovedWhenMatchLayoutIsChangedInTwoMatches()
        {
            Better better = tournament.AddBetter(user);

            round.SetPlayersPerGroupCount(4);
            tournament.RegisterPlayerReference("Taeja");
            tournament.RegisterPlayerReference("Rain");
            group = round.Groups.First();

            Match firstMatch  = group.Matches[0];
            Match secondMatch = group.Matches[1];

            better.PlaceMatchBet(firstMatch, firstMatch.Player1);
            better.PlaceMatchBet(secondMatch, secondMatch.Player1);

            PlayerSwitcher.SwitchMatchesOn(firstMatch.Player1, secondMatch.Player1);

            better.Bets.Should().BeEmpty();
        }
Example #9
0
        public void CannotSwitchPlacesOnPlayerReferenceWhenAnyPlayerIsNull()
        {
            bracketRound.SetPlayersPerGroupCount(4);
            PlayerReference maruPlayerReference  = tournament.RegisterPlayerReference("Maru");
            PlayerReference storkPlayerReference = tournament.RegisterPlayerReference("Stork");
            PlayerReference taejaPlayerReference = tournament.RegisterPlayerReference("Taeja");

            BracketGroup group = bracketRound.Groups.First() as BracketGroup;

            Match firstMatch  = group.Matches[0];
            Match secondMatch = group.Matches[1];

            bool result = PlayerSwitcher.SwitchMatchesOn(firstMatch.Player1, secondMatch.Player2);

            result.Should().BeFalse();
            firstMatch.Player1.PlayerReferenceId.Should().Be(maruPlayerReference.Id);
            firstMatch.Player2.PlayerReferenceId.Should().Be(storkPlayerReference.Id);
            secondMatch.Player1.PlayerReferenceId.Should().Be(taejaPlayerReference.Id);
            secondMatch.Player2.PlayerReferenceId.Should().BeEmpty();
        }
Example #10
0
 // Use this for initialization
 void Start()
 {
     switcher = GetComponent<PlayerSwitcher> ();
     switcher.enabled = false;
     smoke.SetActive (false);
 }
Example #11
0
 public bool SwitchPlayersInMatches(Player player1, Player player2)
 {
     return(PlayerSwitcher.SwitchMatchesOn(player1, player2));
 }
Example #12
0
 // Use this for initialization
 void Start()
 {
     switcher         = GetComponent <PlayerSwitcher> ();
     switcher.enabled = false;
     smoke.SetActive(false);
 }
Example #13
0
    void Update()
    {
        if (e_health <= 0)
        {
            punch    = false;
            e_health = 10;
            Debug.Log("health");
            lastHealth       = true;
            psScript.testHit = false;
            e_Anim.SetBool("isDead", true);
            winText = GameObject.Find("Timer").GetComponent <TimeBalk>().playerTurnText;
            if (GameObject.FindGameObjectsWithTag("u_Player1").Length == 1 && psScript.switchPlayer)
            {
                e_dead       = true;
                test         = true;
                winText.text = ("Player 2 wins!!");
                win2         = true;
                e_health     = 10;
                StartCoroutine(WaitForDeadAni());
                Debug.Log("testttt1");
                psScript.endGame = true;
                tbScript         = GameObject.Find("Timer").GetComponent <TimeBalk>();
                tbScript.dead    = true;
            }
            if (GameObject.FindGameObjectsWithTag("u_Player2").Length == 1 && !psScript.switchPlayer)
            {
                e_dead       = true;
                test         = true;
                winText.text = ("Player 1 wins!!");
                win1         = true;
                e_health     = 10;
                StartCoroutine(WaitForDeadAni());
                Debug.Log("testttt2");
                psScript.endGame = true;
                tbScript         = GameObject.Find("Timer").GetComponent <TimeBalk>();
                tbScript.dead    = true;
            }
            else
            {
                if (test == false)
                {
                    tbScript = GameObject.Find("Timer").GetComponent <TimeBalk>();
                    tbScript.Change();
                    e_health = 10;
                    StartCoroutine(WaitForDeadAni());
                    Debug.Log("testttt5");
                }
            }
        }
        else
        {
        }


        psScript = GameObject.Find("GameManager").GetComponent <PlayerSwitcher>();
        if (walkOn)
        {
            float moveHorizontal = Input.GetAxis("Horizontal");
            float moveVertical   = Input.GetAxis("Vertical");

            if (Input.GetKey(KeyCode.LeftShift) && Input.GetKey("w"))
            {
                transform.position += transform.TransformDirection(Vector3.forward) * Time.deltaTime * speed * 1.5f;
            }
            if (Input.GetKey("w") && !Input.GetKey(KeyCode.LeftShift))
            {
                transform.position += transform.TransformDirection(Vector3.forward) * Time.deltaTime * speed;
            }
            else if (Input.GetKey("s"))
            {
                transform.position -= transform.TransformDirection(Vector3.forward) * Time.deltaTime * speed;
            }

            if (Input.GetKey("a") && !Input.GetKey("d"))
            {
                transform.position += transform.TransformDirection(Vector3.left) * Time.deltaTime * speed;
            }
            else if (Input.GetKey("d") && !Input.GetKey("a"))
            {
                transform.position -= transform.TransformDirection(Vector3.left) * Time.deltaTime * speed;
            }

            if (Input.GetKey("w") || Input.GetKey("a") || Input.GetKey("s") || Input.GetKey("d"))
            {
                psScript.anim.SetBool("isWalking", true);
            }
            else
            {
                psScript.anim.SetBool("isWalking", false);
            }

            if (Input.GetKey("x"))
            {
                psScript.anim.SetBool("isReady", true);
            }
            else
            {
                psScript.anim.SetBool("isReady", false);
            }

            float h = horizontalSpeed * Input.GetAxis("Mouse X");
            transform.Rotate(0, h, 0);
        }

        if (Input.GetMouseButtonDown(0) && punch == true)
        {
            if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, rayDistance))
            {
                Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * hit.distance, Color.yellow);
                if (hit.transform.tag == "u_Player2" && !psScript.switchPlayer && canClick)
                {
                    startGame = true;
                    Debug.Log("Attack");
                    e_health   = hit.transform.gameObject.GetComponent <UnitValues>().health;
                    e_strength = hit.transform.gameObject.GetComponent <UnitValues>().strength;
                    e_defense  = hit.transform.gameObject.GetComponent <UnitValues>().defense;

                    e_dead = hit.transform.gameObject.GetComponent <UnitValues>().dead;

                    e_Anim = hit.transform.gameObject.GetComponent <Animator>();

                    enemy = hit.transform.gameObject;

                    psScript.anim.SetBool("isPunching", true);
                    e_Anim.SetBool("isHit", true);
                }
                else if (hit.transform.tag == "u_Player1" && psScript.switchPlayer && canClick)
                {
                    Debug.Log("Attack");
                    e_health   = hit.transform.gameObject.GetComponent <UnitValues>().health;
                    e_strength = hit.transform.gameObject.GetComponent <UnitValues>().strength;
                    e_defense  = hit.transform.gameObject.GetComponent <UnitValues>().defense;

                    e_dead = hit.transform.gameObject.GetComponent <UnitValues>().dead;

                    e_Anim = hit.transform.gameObject.GetComponent <Animator>();

                    enemy = hit.transform.gameObject;

                    psScript.anim.SetBool("isPunching", true);
                    e_Anim.SetBool("isHit", true);
                }
            }
        }
        if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit2, rayDistance))
        {
            Debug.Log(hit2.transform.gameObject.name);
            if (Input.GetKey("e") && hit2.transform.gameObject.name == "Sword_tex(Clone)")
            {
                if (!psScript.switchPlayer)
                {
                    cmScript = GameObject.Find("Main Camera").GetComponent <CameraMove>();
                    weapon1  = true;
                    sword    = hit2.transform.gameObject;



                    Debug.Log(psScript.playerNow.transform.GetChild(3).GetChild(2).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChild(0));
                    sword.transform.parent        = psScript.playerNow.transform.GetChild(3).GetChild(2).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetChild(0);
                    sword.transform.rotation      = new Quaternion(0, 0, 0, 0);
                    sword.transform.localPosition = new Vector3(0, 0, 0);
                }
                if (psScript.switchPlayer)
                {
                    weapon2 = true;
                    sword2  = hit2.transform.gameObject;
                    sword2.transform.parent        = psScript.playerNow.transform.GetChild(3).GetChild(2).GetChild(0).GetChild(0).GetChild(2).GetChild(0).GetChild(0).GetChild(0);
                    sword2.transform.rotation      = new Quaternion(0, 0, 0, 0);
                    sword2.transform.localPosition = new Vector3(0, 0, 0);
                }
            }
        }
    }
Example #14
0
    void OnMouseDown()
    {
        RaycastHit hit;

        if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 100) && svScript.raycastOn)
        {
            if (svScript.playerOnePoints < 10)
            {
                svScript.playerOneDone = true;
                StartCoroutine(WaitSecond());
                svScript.raycastOn = false;
            }
            if (svScript.playerTwoPoints < 10)
            {
                svScript.playerTwoDone = true;
                StartCoroutine(WaitSecond());
                svScript.raycastOn = false;
            }
            if ((svScript.switchTurn == false))
            {
                if (svScript.playerOnePoints == 0 && test == 0)
                {
                    psScript = GameObject.Find("GameManager").GetComponent <PlayerSwitcher>();
                    svScript.playerOneDone = true;
                    svScript.switchTurn    = true;
                    Vector3 targetLocation = hit.point;
                    targetLocation += new Vector3(0, transform.localScale.y / 2, 0);
                    GameObject newUnit = Instantiate(unitP1, targetLocation, Quaternion.identity);
                    newUnit.transform.parent = UnitListP1.transform;

                    UnitValues uvScript = newUnit.GetComponent <UnitValues>();
                    uvScript.health   = svScript.sliderValue3[0];
                    uvScript.strength = svScript.sliderValue3[1];
                    uvScript.speed    = svScript.sliderValue2[0];
                    uvScript.defense  = svScript.sliderValue2[1];

                    svScript.switchTurn = true;
                    svScript.SwitchPlayer();
                    test = 2;
                    svScript.raycastOn = false;
                    StartCoroutine(WaitSecond());
                }
                else if (test == 0)
                {
                    Vector3 targetLocation = hit.point;
                    targetLocation += new Vector3(0, transform.localScale.y / 2, 0);
                    GameObject newUnit = Instantiate(unitP1, targetLocation, Quaternion.identity);
                    newUnit.transform.parent = UnitListP1.transform;

                    UnitValues uvScript = newUnit.GetComponent <UnitValues>();
                    uvScript.health    = svScript.sliderValue3[0];
                    uvScript.strength  = svScript.sliderValue3[1];
                    uvScript.speed     = svScript.sliderValue2[0];
                    uvScript.defense   = svScript.sliderValue2[1];
                    svScript.raycastOn = false;
                    StartCoroutine(WaitSecond());

                    if (svScript.playerTwoDone)
                    {
                        svScript.switchTurn = false;
                        svScript.SwitchPlayer();
                        svScript.raycastOn = false;
                    }
                    else
                    {
                        svScript.switchTurn = !svScript.switchTurn;
                        svScript.SwitchPlayer();
                        svScript.raycastOn = false;
                    }
                }
                return;
            }
            if ((svScript.switchTurn == true))
            {
                if (svScript.playerTwoPoints == 0 && test2 == 0)
                {
                    Debug.Log("yo");
                    psScript = GameObject.Find("GameManager").GetComponent <PlayerSwitcher>();
                    svScript.playerTwoDone = true;
                    svScript.switchTurn    = false;
                    Vector3 targetLocation = hit.point;
                    targetLocation += new Vector3(0, transform.localScale.y / 2, 0);
                    GameObject newUnit = Instantiate(unitP2, targetLocation, Quaternion.identity);
                    newUnit.transform.parent = UnitListP2.transform;

                    UnitValues uvScript = newUnit.GetComponent <UnitValues>();
                    uvScript.health   = svScript.sliderValue3[0];
                    uvScript.strength = svScript.sliderValue3[1];
                    uvScript.speed    = svScript.sliderValue2[0];
                    uvScript.defense  = svScript.sliderValue2[1];

                    svScript.SwitchPlayer();
                    test2 = 2;
                    svScript.raycastOn = false;
                    StartCoroutine(WaitSecond());
                }
                else if (test2 == 0)
                {
                    Vector3 targetLocation = hit.point;
                    targetLocation += new Vector3(0, transform.localScale.y / 2, 0);
                    GameObject newUnit = Instantiate(unitP2, targetLocation, Quaternion.identity);
                    newUnit.transform.parent = UnitListP2.transform;

                    UnitValues uvScript = newUnit.GetComponent <UnitValues>();
                    uvScript.health   = svScript.sliderValue3[0];
                    uvScript.strength = svScript.sliderValue3[1];
                    uvScript.speed    = svScript.sliderValue2[0];
                    uvScript.defense  = svScript.sliderValue2[1];
                    StartCoroutine(WaitSecond());

                    if (svScript.playerOneDone)
                    {
                        svScript.switchTurn = true;
                        svScript.SwitchPlayer();
                    }
                    else
                    {
                        svScript.switchTurn = !svScript.switchTurn;
                        svScript.SwitchPlayer();
                    }
                }
            }
        }
    }