Beispiel #1
0
    public void OnSuccess(object response)
    {
        Game game = (Game)response;

        App42Log.Console("gameName is " + game.GetName());

        t.rect.offsetMax = new Vector2(t.width, 0);
        t.rect.offsetMin = new Vector2(0, -t.heigh * game.GetScoreList().Count);

        System.Collections.Generic.IList <Game.Score> list = game.GetScoreList();
        for (int i = 0; i < list.Count; i++)
        {
            MonoBehaviour.print("index__" + i);
            Game.Score score = list[i];
            App42Log.Console("userName is : " + score.GetUserName());
            App42Log.Console("score is : " + score.GetValue());

            GameObject g = (GameObject)MonoBehaviour.Instantiate(t.item, t.rect.position, Quaternion.identity);

            g.transform.parent = t.rect.transform;
            RectTransform R = g.GetComponent <RectTransform>();
            R.offsetMax  = new Vector2(t.width, -t.heigh * i);
            R.offsetMin  = new Vector2(0, -t.heigh * (i + 1));
            R.localScale = new Vector3(1, 1, 1);
            R.GetChild(0).GetComponent <Text>().text = score.GetUserName();
            R.GetChild(1).GetComponent <Text>().text = score.GetValue().ToString();
        }


        //for (int i = 0; i < game.GetScoreList().Count; i++)
        //{
        //    Game.Score score = game.GetScoreList()[i];
        //    App42Log.Console("userName is : " + score.GetUserName());
        //    App42Log.Console("score is : " + score.GetValue());

        //    GameObject g = (GameObject)Instantiate(t.item, t.rect.position, Quaternion.identity);
        //    g.transform.parent = t.rect.transform;
        //    RectTransform R = g.GetComponent<RectTransform>();
        //    R.offsetMax = new Vector2(t.width, -t.heigh * i);
        //    R.offsetMin = new Vector2(0, -t.heigh * (i + 1));

        //    R.GetChild(0).GetComponent<Text>().text = score.GetUserName();
        //    R.GetChild(1).GetComponent<Text>().text = score.GetValue().ToString();
        //}

        iTween.MoveTo(t.loadingPanel.gameObject, iTween.Hash("position", t.othePosition.position));
    }
Beispiel #2
0
        public static void Main()
        {
            string command = string.Empty;
            char[,] playingField = CreatePlayingField();
            char[,] bombsPossitions = PutBombsOnPlayingField();
            int points = 0;
            bool isOnBomb = false;
            List<Score> topScores = new List<Score>(6);
            int row = 0;
            int column = 0;
            bool isNewGame = true;
            const int MaxScore = 35;
            bool isMaxScore = false;

            do
            {
                if (isNewGame)
                {
                    Console.WriteLine("Lets play  “Minesweeper”. Try to find the fields without minesweepers." + Environment.NewLine +
                        "   Command 'top' show top scores," + Environment.NewLine +
                        "   command 'restart' start new game," + Environment.NewLine +
                        "   command 'exit' exit from the game!");
                    DrawBoard(playingField);
                    isNewGame = false;
                }

                Console.Write("Pls, input row and column: ");
                command = Console.ReadLine().Trim();

                if (command.Length >= 3)
                {
                    if (int.TryParse(command[0].ToString(), out row) &&
                        int.TryParse(command[2].ToString(), out column) &&
                        row <= playingField.GetLength(0) &&
                        column <= playingField.GetLength(1))
                    {
                        command = "move";
                    }
                }

                switch (command)
                {
                    case "top":
                        ShowTopScores(topScores);
                        break;
                    case "restart":
                        playingField = CreatePlayingField();
                        bombsPossitions = PutBombsOnPlayingField();
                        DrawBoard(playingField);
                        isOnBomb = false;
                        isNewGame = false;
                        break;
                    case "exit":
                        Console.WriteLine("Bye, Bye, Bye!");
                        break;
                    case "move":
                        if (bombsPossitions[row, column] != '*')
                        {
                            if (bombsPossitions[row, column] == '-')
                            {
                                MakeMove(playingField, bombsPossitions, row, column);
                                points++;
                            }

                            if (MaxScore == points)
                            {
                                isMaxScore = true;
                            }
                            else
                            {
                                DrawBoard(playingField);
                            }
                        }
                        else
                        {
                            isOnBomb = true;
                        }

                        break;
                    default:
                        Console.WriteLine(Environment.NewLine + "Invalid command" + Environment.NewLine);
                        break;
                }

                if (isOnBomb)
                {
                    DrawBoard(bombsPossitions);

                    Console.Write("{1}Sorry you are dead. Your score is {0} points. Pls, enter your nickname: ", points, Environment.NewLine);

                    string nickname = Console.ReadLine();
                    Score currentScore = new Score(nickname, points);

                    if (topScores.Count < 5)
                    {
                        topScores.Add(currentScore);
                    }
                    else
                    {
                        for (int i = 0; i < topScores.Count; i++)
                        {
                            if (topScores[i].Points < currentScore.Points)
                            {
                                topScores.Insert(i, currentScore);
                                topScores.RemoveAt(topScores.Count - 1);
                                break;
                            }
                        }
                    }

                    topScores.Sort((Score r1, Score r2) => r2.Name.CompareTo(r1.Name));
                    topScores.Sort((Score r1, Score r2) => r2.Points.CompareTo(r1.Points));
                    ShowTopScores(topScores);

                    playingField = CreatePlayingField();
                    bombsPossitions = PutBombsOnPlayingField();
                    points = 0;
                    isOnBomb = false;
                    isNewGame = true;
                }

                if (isMaxScore)
                {
                    Console.WriteLine(Environment.NewLine + "Bravooo! You open all 35 boxes without to step on bomb!");
                    DrawBoard(bombsPossitions);
                    Console.WriteLine("Pls, write your nickname: ");
                    string nickname = Console.ReadLine();
                    Score currentScore = new Score(nickname, points);
                    topScores.Add(currentScore);
                    ShowTopScores(topScores);
                    playingField = CreatePlayingField();
                    bombsPossitions = PutBombsOnPlayingField();
                    points = 0;
                    isMaxScore = false;
                    isNewGame = true;
                }
            }
            while (command != "exit");

            Console.WriteLine("Made in Bulgaria!");
            Console.WriteLine("See you next time!");
            Console.Read();
        }
        public static void Main()
        {
            string command = string.Empty;

            char[,] playingField    = CreatePlayingField();
            char[,] bombsPossitions = PutBombsOnPlayingField();
            int          points     = 0;
            bool         isOnBomb   = false;
            List <Score> topScores  = new List <Score>(6);
            int          row        = 0;
            int          column     = 0;
            bool         isNewGame  = true;
            const int    MaxScore   = 35;
            bool         isMaxScore = false;

            do
            {
                if (isNewGame)
                {
                    Console.WriteLine("Lets play  “Minesweeper”. Try to find the fields without minesweepers." + Environment.NewLine +
                                      "   Command 'top' show top scores," + Environment.NewLine +
                                      "   command 'restart' start new game," + Environment.NewLine +
                                      "   command 'exit' exit from the game!");
                    DrawBoard(playingField);
                    isNewGame = false;
                }

                Console.Write("Pls, input row and column: ");
                command = Console.ReadLine().Trim();

                if (command.Length >= 3)
                {
                    if (int.TryParse(command[0].ToString(), out row) &&
                        int.TryParse(command[2].ToString(), out column) &&
                        row <= playingField.GetLength(0) &&
                        column <= playingField.GetLength(1))
                    {
                        command = "move";
                    }
                }

                switch (command)
                {
                case "top":
                    ShowTopScores(topScores);
                    break;

                case "restart":
                    playingField    = CreatePlayingField();
                    bombsPossitions = PutBombsOnPlayingField();
                    DrawBoard(playingField);
                    isOnBomb  = false;
                    isNewGame = false;
                    break;

                case "exit":
                    Console.WriteLine("Bye, Bye, Bye!");
                    break;

                case "move":
                    if (bombsPossitions[row, column] != '*')
                    {
                        if (bombsPossitions[row, column] == '-')
                        {
                            MakeMove(playingField, bombsPossitions, row, column);
                            points++;
                        }

                        if (MaxScore == points)
                        {
                            isMaxScore = true;
                        }
                        else
                        {
                            DrawBoard(playingField);
                        }
                    }
                    else
                    {
                        isOnBomb = true;
                    }

                    break;

                default:
                    Console.WriteLine(Environment.NewLine + "Invalid command" + Environment.NewLine);
                    break;
                }

                if (isOnBomb)
                {
                    DrawBoard(bombsPossitions);

                    Console.Write("{1}Sorry you are dead. Your score is {0} points. Pls, enter your nickname: ", points, Environment.NewLine);

                    string nickname     = Console.ReadLine();
                    Score  currentScore = new Score(nickname, points);

                    if (topScores.Count < 5)
                    {
                        topScores.Add(currentScore);
                    }
                    else
                    {
                        for (int i = 0; i < topScores.Count; i++)
                        {
                            if (topScores[i].Points < currentScore.Points)
                            {
                                topScores.Insert(i, currentScore);
                                topScores.RemoveAt(topScores.Count - 1);
                                break;
                            }
                        }
                    }

                    topScores.Sort((Score r1, Score r2) => r2.Name.CompareTo(r1.Name));
                    topScores.Sort((Score r1, Score r2) => r2.Points.CompareTo(r1.Points));
                    ShowTopScores(topScores);

                    playingField    = CreatePlayingField();
                    bombsPossitions = PutBombsOnPlayingField();
                    points          = 0;
                    isOnBomb        = false;
                    isNewGame       = true;
                }

                if (isMaxScore)
                {
                    Console.WriteLine(Environment.NewLine + "Bravooo! You open all 35 boxes without to step on bomb!");
                    DrawBoard(bombsPossitions);
                    Console.WriteLine("Pls, write your nickname: ");
                    string nickname     = Console.ReadLine();
                    Score  currentScore = new Score(nickname, points);
                    topScores.Add(currentScore);
                    ShowTopScores(topScores);
                    playingField    = CreatePlayingField();
                    bombsPossitions = PutBombsOnPlayingField();
                    points          = 0;
                    isMaxScore      = false;
                    isNewGame       = true;
                }
            }while (command != "exit");

            Console.WriteLine("Made in Bulgaria!");
            Console.WriteLine("See you next time!");
            Console.Read();
        }