Example #1
0
    //Determine Winner uses a dictionary of lists that contain the winners for each stance and compares them.
    public void DetermineWinner(stanceChoice playerStance, stanceChoice enemyStance)
    {
        List <stanceChoice> nuetralwinners = new List <stanceChoice>();

        nuetralwinners.Add(stanceChoice.Down);
        nuetralwinners.Add(stanceChoice.Left);

        List <stanceChoice> rightwinners = new List <stanceChoice>();

        rightwinners.Add(stanceChoice.Up);
        rightwinners.Add(stanceChoice.Neutral);

        List <stanceChoice> downwinners = new List <stanceChoice>();

        downwinners.Add(stanceChoice.Right);
        downwinners.Add(stanceChoice.Up);

        List <stanceChoice> leftwinners = new List <stanceChoice>();

        leftwinners.Add(stanceChoice.Right);
        leftwinners.Add(stanceChoice.Down);

        List <stanceChoice> upwinners = new List <stanceChoice>();

        upwinners.Add(stanceChoice.Neutral);
        upwinners.Add(stanceChoice.Left);

//stanceChoice is the key, and the list of winners for that stance is the value. We'll get the winners of they stance by using it as the key
        Dictionary <stanceChoice, List <stanceChoice> > winners = new Dictionary <stanceChoice, List <stanceChoice> >
        {
            { stanceChoice.Neutral, nuetralwinners },
            { stanceChoice.Right, rightwinners },
            { stanceChoice.Down, downwinners },
            { stanceChoice.Left, leftwinners },
            { stanceChoice.Up, upwinners },
        };

//This logic compares the playerStance to the enemy stance and determines the winner
        if (playerStance == enemyStance)
        {
            Debug.Log(playerStance + " collided with " + enemyStance);
            Debug.Log("It's a Draw!");
            return;
        }
        else
        {
            var playerWinners = winners[playerStance];
            if (playerWinners.Contains(enemyStance))
            {
                Debug.Log(playerStance + " collided with " + enemyStance);
                Debug.Log("You Win!!");
            }
            else
            {
                Debug.Log(playerStance + " collided with " + enemyStance);
                Debug.Log("You Lose!!");
            }
        }
    }
    public void OnCollisionEnter2D(Collision2D collision)
    {
        //Check if this object collided with the player object
        var playerCollision = collision.collider.GetComponent <PlayerMovement>();

        //Getting the playerStance from the player upon collision
        playerStance = playerCollision.playerStance;

        //Getting the current stance at collision from the enemy
        enemyStance = gameObject.GetComponent <EnemyAI>().currentStance;

        //If the collision was with the player then run DetermineWinner();
        if (playerCollision != null)
        {
            StanceLogic.GetComponent <StanceLogic>().DetermineWinner(playerStance, enemyStance);
        }
    }
 public void ChooseStance()
 {
     currentStance = RandomStance();
     textStance.GetComponent <TextMesh>().text = currentStance.ToString() + " Stance";
 }
Example #4
0
    // Update is called once per frame
    void Update()
    {
        horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;

        animator.SetFloat("Speed", Mathf.Abs(horizontalMove));

        if (Input.GetButtonDown("Cancel"))
        {
            SceneManager.LoadScene(0);
        }

        if (Input.GetButtonDown("Jump"))
        {
            jump = true;
            animator.SetBool("IsJumping", true);
        }

        if (Input.GetButtonDown("Crouch"))
        {
            crouch = true;
        }
        else if (Input.GetButtonUp("Crouch"))
        {
            crouch = false;
        }

        // foreach(KeyCode vKey in System.Enum.GetValues(typeof(KeyCode))){
        //  if(Input.GetKey(vKey))
        //  {
        //      if (vKey == KeyCode.Return)
        //      {
        //          kCode = vKey;
        //          Debug.Log(kCode);
        //      }
        //  }
        // }
        // stanceName = Input.GetButtonDown(); //shitsuxxx
        if (Input.GetButtonDown("Fire1"))
        {
            textStance.GetComponent <TextMesh>().text = "Up Stance";
            playerStance = stanceChoice.Up;
        }
        if (Input.GetButtonDown("Fire2"))
        {
            textStance.GetComponent <TextMesh>().text = "Down Stance";
            playerStance = stanceChoice.Down;
        }
        if (Input.GetButtonDown("Fire3"))
        {
            textStance.GetComponent <TextMesh>().text = "Left Stance";
            playerStance = stanceChoice.Left;
        }
        if (Input.GetButtonDown("Fire4"))
        {
            textStance.GetComponent <TextMesh>().text = "Right Stance";
            playerStance = stanceChoice.Right;
        }
        if (Input.GetButton("Fire5"))
        {
            chargeTimer += Time.deltaTime;
        }
        if (Input.GetButtonUp("Fire5") && (chargeTimer > 2))
        {
            GetComponent <Rigidbody2D>().velocity = new Vector3(90, 5, 0);
            animator.SetBool("IsJumping", true);
            chargeTimer = 0;
        }
        if (Input.GetButtonUp("Fire5") && (chargeTimer < 2))
        {
            chargeTimer = 0;
        }
    }