예제 #1
0
    IEnumerator LogSnakeStats()
    {
        //Connect to questions database
        string domain       = "http://34.205.7.163/";
        string attempts_url = domain + "snake_stats.php";

        // Create a form object for sending data to the server
        WWWForm form = new WWWForm();

        form.AddField("steps", steps.ToString());
        form.AddField("apples", apples.ToString());
        form.AddField("turns", turns.ToString());
        form.AddField("idplayer", SnakeId.GetInstance().GetSnakeId().ToString());
        form.AddField("killed", killed.ToString());
        form.AddField("attemptNo", SnakeId.GetInstance().GetAttempt().ToString());

        var download = UnityWebRequest.Post(attempts_url, form);

        // Wait until the download is done
        yield return(download.SendWebRequest());

        if (download.isNetworkError || download.isHttpError)
        {
            Debug.Log("Error downloading: " + download.error);
        }
        else
        {
            //Debug.Log(download.downloadHandler.text + "\nAttempt sent successfully");
        }
    }
예제 #2
0
    void Start()
    {
        GetInstance().NewSnake();

        size  = PlayerPrefs.GetInt("boardsize");
        board = new int[size, size];

        offset = size / 2;
        bool odd        = size % 2 != 0;
        int  wallOffset = offset + 1;

        lowerBound = -wallOffset;
        upperBound = wallOffset - (odd ? 0 : 1);
        //spawn all walls
        for (int i = -wallOffset; i < wallOffset + (odd ? 1 : 0); i++)
        {
            Instantiate(pfWall, new Vector2(i, lowerBound), Quaternion.identity);
            Instantiate(pfWall, new Vector2(lowerBound, i), Quaternion.identity);
            Instantiate(pfWall, new Vector2(i, upperBound), Quaternion.identity);
            Instantiate(pfWall, new Vector2(upperBound, i), Quaternion.identity);
        }

        a = FindObjectOfType <Apple>();

        gameSpeedSlider.onValueChanged.AddListener(delegate { SetGameSpeed(); });
        if (PlayerPrefs.GetInt("isbot") == 0)
        {
            gameSpeedSlider.value   = 8;
            gameSpeedSlider.enabled = false;
            gameStepsPerTurn        = 8;
        }

        nameText.text      = SnakeId.GetInstance().GetName();
        highscoreText.text = SnakeId.GetInstance().GetHighScore().ToString();
    }
예제 #3
0
    public void Eat()
    {
        ms = MoveScore.EAT;

        stepsWithoutFood = 0;

        GameObject go = Instantiate(goBodyPrefab, sbSnakeTail.transform.position, Quaternion.identity);
        SnakeBody  sb = go.GetComponent <SnakeBody>();

        SnakeId.GetInstance().SetHighScore(apples + 1);
        GameMaster.AddScore(1);

        if (length == 1)
        {
            sbSnakeHead.back = sb;
            sb.front         = sbSnakeHead;
            sbSnakeTail      = sb;
        }
        else
        {
            sbSnakeTail.back = sb;
            sb.front         = sbSnakeTail;
            sbSnakeTail      = sb;
        }

        apples++;
        length++;
    }
예제 #4
0
 public static SnakeId GetInstance()
 {
     if (snake == null)
     {
         snake = new SnakeId();
     }
     return(snake);
 }
예제 #5
0
    public void NewSnake()
    {
        GameObject go = Instantiate(pfSnakeHead);

        if (PlayerPrefs.GetInt("isbot") == 1)
        {
            go.AddComponent <RoboSnake>();
        }
        else
        {
            go.AddComponent <HumanSnake>();
        }
        SnakeId.GetInstance().NewAttempt();
    }
예제 #6
0
    IEnumerator LogNewSnake()
    {
        //Connect to questions database
        string domain       = "http://34.205.7.163/";
        string attempts_url = domain + "new_snake.php";

        // Create a form object for sending data to the server
        WWWForm form = new WWWForm();

        form.AddField("name", strName);
        form.AddField("isbot", (isBot ? 1 : 0).ToString());
        form.AddField("boardsize", (intBoardSize));

        form.AddField("learningRate", (fltLearningRate).ToString());
        form.AddField("discount", (fltDiscount).ToString());
        form.AddField("epsilon", (fltEpsilon).ToString());
        form.AddField("epsilonDec", (fltEpsilonDec).ToString());

        form.AddField("move", (intMoveScore));
        form.AddField("wall", (intWallScore));
        form.AddField("apple", (intAppleScore));

        form.AddField("vision", (intVisionId));

        var download = UnityWebRequest.Post(attempts_url, form);

        // Wait until the download is done
        yield return(download.SendWebRequest());

        if (download.isNetworkError || download.isHttpError)
        {
            Debug.Log("Error downloading: " + download.error);
        }
        else
        {
            //Debug.Log(download.downloadHandler.text);
            PlayerPrefs.SetInt("idplayer", int.Parse(download.downloadHandler.text));
            SnakeId.GetInstance().SetSnakeId(int.Parse(download.downloadHandler.text));

            SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
        }
    }
예제 #7
0
    void OnClick()
    {
        PlayerPrefs.SetString("name", txtName.text);
        SnakeId.GetInstance().SetName(txtName.text);

        PlayerPrefs.SetInt("isbot", isbot.isOn ? 1 : 0);
        PlayerPrefs.SetInt("boardsize", int.Parse(txtBoardSize.text));

        PlayerPrefs.SetFloat("learningRate", float.Parse(txtLearningRate.text));
        PlayerPrefs.SetFloat("discount", float.Parse(txtDiscount.text));
        PlayerPrefs.SetFloat("epsilon", float.Parse(txtEpsilon.text));
        PlayerPrefs.SetFloat("epsilonDec", float.Parse(txtEpsilonDec.text));

        PlayerPrefs.SetInt("move", int.Parse(txtMove.text));
        PlayerPrefs.SetInt("wall", int.Parse(txtWall.text));
        PlayerPrefs.SetInt("apple", int.Parse(txtApple.text));

        PlayerPrefs.SetInt("idvision", int.Parse(txtVision.text));

        StartCoroutine(LogNewSnake());
    }
예제 #8
0
 public static void AddScore(int points)
 {
     GetInstance().score             += points;
     GetInstance().scoreText.text     = GetInstance().score.ToString();
     GetInstance().highscoreText.text = SnakeId.GetInstance().GetHighScore().ToString();
 }