Exemplo n.º 1
0
    private void CheckGameOver()
    {
        TextAndColor[] textAndColorArray = new TextAndColor[numbers - 1];

        int index = 0;

        for (int i = 0; i < size; i++)
        {
            for (int j = 0; j < size; j++)
            {
                if (index < numbers - 1)
                {
                    textAndColorArray[index]      = new TextAndColor();
                    textAndColorArray[index].text = buttons[i, j].Text;
                    index++;
                }
            }
        }

        string serializedArray = jsSerializer.Serialize(textAndColorArray);

        string request      = url + "?array=" + serializedArray + "&cmd=CheckGameOver";
        string resultString = webClient.DownloadString(new Uri(request));
        bool   isGameOver   = (bool)jsSerializer.Deserialize(resultString, typeof(bool));

        if (isGameOver)
        {
            ClientScript.RegisterClientScriptBlock(typeof(Page), "", "<script>confirm('Game Over! New Game?');</script>");
            StartNewGame();
        }
    }
Exemplo n.º 2
0
    //public static void load(AsyncResult state)
    //{
    //    Fraction[] arrFraction = new Fraction[2];
    //    for (int i = 0; i < 2; i++)
    //        arrFraction[i] = new Fraction(0, 1);

    //    JavaScriptSerializer myJavaScriptSerializer = new JavaScriptSerializer();
    //    string resultStr = myJavaScriptSerializer.Serialize(arrFraction);
    //    state._context.Response.Write(resultStr);
    //}

    //public static void PlusMinus(AsyncResult state, Fraction A, Fraction B)
    //{
    //    Fraction[] arrFraction = new Fraction[2];
    //    arrFraction[0] = A + B;
    //    arrFraction[1] = A - B;

    //    JavaScriptSerializer myJavaScriptSerializer = new JavaScriptSerializer();
    //    string resultStr = myJavaScriptSerializer.Serialize(arrFraction);
    //    state._context.Response.Write(resultStr);
    //}

    public static void initTextAndColor(AsyncResult state)
    {
        TextAndColor[] tac = new TextAndColor[16];
        Random         r   = new Random();

        System.Drawing.Color tmp;
        int[] arr = new int[15];
        for (int i = 0; i < 15; i++)
        {
            arr[i] = i + 1;
        }
        int k = 15, n;

        for (int i = 0; i < 15; i++)
        {
            tmp        = System.Drawing.Color.FromArgb(r.Next(206) + 50, r.Next(206) + 50, r.Next(206) + 50);
            n          = r.Next(k) + 1;
            tac[i]     = new TextAndColor(arr[n - 1].ToString(), System.Drawing.ColorTranslator.ToHtml(tmp));
            arr[n - 1] = arr[k - 1];
            k--;
        }
        tac[15] = new TextAndColor("-1", "-1");

        JavaScriptSerializer myJavaScriptSerializer = new JavaScriptSerializer();
        string resultStr = myJavaScriptSerializer.Serialize(tac);

        state._context.Response.Write(resultStr);
    }
Exemplo n.º 3
0
    public static void bgc(AsyncResult state, TextAndColor button, TextAndColor bg)
    {
        string s1 = button.strHtmlColor;
        string s2 = bg.strHtmlColor;

        System.Drawing.Color c        = System.Drawing.ColorTranslator.FromHtml(s1);
        System.Drawing.Color c2       = System.Drawing.ColorTranslator.FromHtml(s2);
        System.Drawing.Color newcolor = System.Drawing.Color.FromArgb((c.R + c2.R) / 2, (c.G + c2.G) / 2, (c.B + c2.B) / 2);
        String NewHtmlColor           = System.Drawing.ColorTranslator.ToHtml(newcolor);
        JavaScriptSerializer myJavaScriptSerializer = new JavaScriptSerializer();
        string resultStr = myJavaScriptSerializer.Serialize(NewHtmlColor);

        state._context.Response.Write(resultStr);
    }
Exemplo n.º 4
0
    private void ChangeBackgroundColor(Button button)
    {
        TextAndColor buttonColor = new TextAndColor();

        buttonColor.color[0] = button.BackColor.R;
        buttonColor.color[1] = button.BackColor.G;
        buttonColor.color[2] = button.BackColor.B;
        string buttonColorSerialized = jsSerializer.Serialize(buttonColor);

        TextAndColor bodyColor = new TextAndColor();
        string       bodyRgb   = Body.Attributes.CssStyle["background-color"];

        bodyColor.color[0] = Int32.Parse(bodyRgb.Split('(')[1].Split(')')[0].Split(',')[0]);
        bodyColor.color[1] = Int32.Parse(bodyRgb.Split('(')[1].Split(')')[0].Split(',')[1]);
        bodyColor.color[2] = Int32.Parse(bodyRgb.Split('(')[1].Split(')')[0].Split(',')[2]);
        string bodyColorSerialized = jsSerializer.Serialize(bodyColor);

        string       request      = url + "?first=" + buttonColorSerialized + "&second=" + bodyColorSerialized + "&cmd=GetAverageColor";
        string       resultString = webClient.DownloadString(new Uri(request));
        TextAndColor avg          = (TextAndColor)jsSerializer.Deserialize(resultString, typeof(TextAndColor));

        Body.Attributes.CssStyle["background-color"] = "rgb(" + avg.color[0] + "," + avg.color[1] + "," + avg.color[2] + ")";
    }