Konzolový Had 10 – Načítanie Hry


Warning: Undefined array key "use_multisite" in /data/6/7/67564740-3aeb-4a38-9571-fbf9ff96a0d8/akoprogramovat.sk/web/wp-content/plugins/azurecurve-toggle-showhide/azurecurve-toggle-showhide.php on line 92

Warning: Undefined array key "title_font" in /data/6/7/67564740-3aeb-4a38-9571-fbf9ff96a0d8/akoprogramovat.sk/web/wp-content/plugins/azurecurve-toggle-showhide/azurecurve-toggle-showhide.php on line 106

Warning: Undefined array key "title_font_size" in /data/6/7/67564740-3aeb-4a38-9571-fbf9ff96a0d8/akoprogramovat.sk/web/wp-content/plugins/azurecurve-toggle-showhide/azurecurve-toggle-showhide.php on line 107

Warning: Undefined array key "title_font_weight" in /data/6/7/67564740-3aeb-4a38-9571-fbf9ff96a0d8/akoprogramovat.sk/web/wp-content/plugins/azurecurve-toggle-showhide/azurecurve-toggle-showhide.php on line 108

Warning: Undefined array key "text_color" in /data/6/7/67564740-3aeb-4a38-9571-fbf9ff96a0d8/akoprogramovat.sk/web/wp-content/plugins/azurecurve-toggle-showhide/azurecurve-toggle-showhide.php on line 113

Warning: Undefined array key "text_font" in /data/6/7/67564740-3aeb-4a38-9571-fbf9ff96a0d8/akoprogramovat.sk/web/wp-content/plugins/azurecurve-toggle-showhide/azurecurve-toggle-showhide.php on line 114

Warning: Undefined array key "text_font_size" in /data/6/7/67564740-3aeb-4a38-9571-fbf9ff96a0d8/akoprogramovat.sk/web/wp-content/plugins/azurecurve-toggle-showhide/azurecurve-toggle-showhide.php on line 115

Warning: Undefined array key "text_font_weight" in /data/6/7/67564740-3aeb-4a38-9571-fbf9ff96a0d8/akoprogramovat.sk/web/wp-content/plugins/azurecurve-toggle-showhide/azurecurve-toggle-showhide.php on line 116

Warning: Undefined array key "disable_image" in /data/6/7/67564740-3aeb-4a38-9571-fbf9ff96a0d8/akoprogramovat.sk/web/wp-content/plugins/azurecurve-toggle-showhide/azurecurve-toggle-showhide.php on line 117

Warning: Undefined array key "width" in /data/6/7/67564740-3aeb-4a38-9571-fbf9ff96a0d8/akoprogramovat.sk/web/wp-content/plugins/azurecurve-toggle-showhide/azurecurve-toggle-showhide.php on line 118

Warning: Undefined array key "title_tag" in /data/6/7/67564740-3aeb-4a38-9571-fbf9ff96a0d8/akoprogramovat.sk/web/wp-content/plugins/azurecurve-toggle-showhide/azurecurve-toggle-showhide.php on line 153

Warning: Undefined array key "use_multisite" in /data/6/7/67564740-3aeb-4a38-9571-fbf9ff96a0d8/akoprogramovat.sk/web/wp-content/plugins/azurecurve-toggle-showhide/azurecurve-toggle-showhide.php on line 92

Warning: Undefined array key "title_font" in /data/6/7/67564740-3aeb-4a38-9571-fbf9ff96a0d8/akoprogramovat.sk/web/wp-content/plugins/azurecurve-toggle-showhide/azurecurve-toggle-showhide.php on line 106

Warning: Undefined array key "title_font_size" in /data/6/7/67564740-3aeb-4a38-9571-fbf9ff96a0d8/akoprogramovat.sk/web/wp-content/plugins/azurecurve-toggle-showhide/azurecurve-toggle-showhide.php on line 107

Warning: Undefined array key "title_font_weight" in /data/6/7/67564740-3aeb-4a38-9571-fbf9ff96a0d8/akoprogramovat.sk/web/wp-content/plugins/azurecurve-toggle-showhide/azurecurve-toggle-showhide.php on line 108

Warning: Undefined array key "text_color" in /data/6/7/67564740-3aeb-4a38-9571-fbf9ff96a0d8/akoprogramovat.sk/web/wp-content/plugins/azurecurve-toggle-showhide/azurecurve-toggle-showhide.php on line 113

Warning: Undefined array key "text_font" in /data/6/7/67564740-3aeb-4a38-9571-fbf9ff96a0d8/akoprogramovat.sk/web/wp-content/plugins/azurecurve-toggle-showhide/azurecurve-toggle-showhide.php on line 114

Warning: Undefined array key "text_font_size" in /data/6/7/67564740-3aeb-4a38-9571-fbf9ff96a0d8/akoprogramovat.sk/web/wp-content/plugins/azurecurve-toggle-showhide/azurecurve-toggle-showhide.php on line 115

Warning: Undefined array key "text_font_weight" in /data/6/7/67564740-3aeb-4a38-9571-fbf9ff96a0d8/akoprogramovat.sk/web/wp-content/plugins/azurecurve-toggle-showhide/azurecurve-toggle-showhide.php on line 116

Warning: Undefined array key "disable_image" in /data/6/7/67564740-3aeb-4a38-9571-fbf9ff96a0d8/akoprogramovat.sk/web/wp-content/plugins/azurecurve-toggle-showhide/azurecurve-toggle-showhide.php on line 117

Warning: Undefined array key "width" in /data/6/7/67564740-3aeb-4a38-9571-fbf9ff96a0d8/akoprogramovat.sk/web/wp-content/plugins/azurecurve-toggle-showhide/azurecurve-toggle-showhide.php on line 118

Warning: Undefined array key "title_tag" in /data/6/7/67564740-3aeb-4a38-9571-fbf9ff96a0d8/akoprogramovat.sk/web/wp-content/plugins/azurecurve-toggle-showhide/azurecurve-toggle-showhide.php on line 153

Warning: Undefined array key "use_multisite" in /data/6/7/67564740-3aeb-4a38-9571-fbf9ff96a0d8/akoprogramovat.sk/web/wp-content/plugins/azurecurve-toggle-showhide/azurecurve-toggle-showhide.php on line 92

Warning: Undefined array key "title_font" in /data/6/7/67564740-3aeb-4a38-9571-fbf9ff96a0d8/akoprogramovat.sk/web/wp-content/plugins/azurecurve-toggle-showhide/azurecurve-toggle-showhide.php on line 106

Warning: Undefined array key "title_font_size" in /data/6/7/67564740-3aeb-4a38-9571-fbf9ff96a0d8/akoprogramovat.sk/web/wp-content/plugins/azurecurve-toggle-showhide/azurecurve-toggle-showhide.php on line 107

Warning: Undefined array key "title_font_weight" in /data/6/7/67564740-3aeb-4a38-9571-fbf9ff96a0d8/akoprogramovat.sk/web/wp-content/plugins/azurecurve-toggle-showhide/azurecurve-toggle-showhide.php on line 108

Warning: Undefined array key "text_color" in /data/6/7/67564740-3aeb-4a38-9571-fbf9ff96a0d8/akoprogramovat.sk/web/wp-content/plugins/azurecurve-toggle-showhide/azurecurve-toggle-showhide.php on line 113

Warning: Undefined array key "text_font" in /data/6/7/67564740-3aeb-4a38-9571-fbf9ff96a0d8/akoprogramovat.sk/web/wp-content/plugins/azurecurve-toggle-showhide/azurecurve-toggle-showhide.php on line 114

Warning: Undefined array key "text_font_size" in /data/6/7/67564740-3aeb-4a38-9571-fbf9ff96a0d8/akoprogramovat.sk/web/wp-content/plugins/azurecurve-toggle-showhide/azurecurve-toggle-showhide.php on line 115

Warning: Undefined array key "text_font_weight" in /data/6/7/67564740-3aeb-4a38-9571-fbf9ff96a0d8/akoprogramovat.sk/web/wp-content/plugins/azurecurve-toggle-showhide/azurecurve-toggle-showhide.php on line 116

Warning: Undefined array key "disable_image" in /data/6/7/67564740-3aeb-4a38-9571-fbf9ff96a0d8/akoprogramovat.sk/web/wp-content/plugins/azurecurve-toggle-showhide/azurecurve-toggle-showhide.php on line 117

Warning: Undefined array key "width" in /data/6/7/67564740-3aeb-4a38-9571-fbf9ff96a0d8/akoprogramovat.sk/web/wp-content/plugins/azurecurve-toggle-showhide/azurecurve-toggle-showhide.php on line 118

Warning: Undefined array key "title_tag" in /data/6/7/67564740-3aeb-4a38-9571-fbf9ff96a0d8/akoprogramovat.sk/web/wp-content/plugins/azurecurve-toggle-showhide/azurecurve-toggle-showhide.php on line 153

]V desiatom diely série tutoriálov na konzolovú hru Had sa pozrieme na načíftaciu obrazovku.

Úvod

Načítacia obrazovka bude (ako už jej názov napovedá) slúžiť na výber a načítanie uloženej pozície hry. Táto bude podobná ako obrazovka uloženia hry, len bude mať na výber multi/single player.

Trieda SaveState

Triedu SaveState sme už v tejto sérií spomenuli niekoľko krát. Nikdy sme si však neukázali čo obsahuje, čo je už na čase napraviť. Táto trieda je v skutočnosti veľmi primitívna, obsahuje len tri premenné a je serializovatelná.

[Serializable]
public class SaveState
{
    public int Score = 0;
    public int Lives = 0;
    public int Level = 0;
}

Jej premenné slúžia na uloženie nášho skóre, počtu životov a aktuálneho levelu.

Trieda LoadSelectScreen – Premenné a Konštruktor

Teraz sa konečne dostávame k hlavnej triede. Tá je podobná triede SaveSelectScreen, tak ju prejdeme len zbežne. Premenné obsahujú informáciu o výbere multiplayeru, aktuálne vybranom slote, poslednej scéne a rodičovskej triede.

private bool MP = false;
private int selectedItem = 0;
private Game Parent;
public Game.Scenes last;

Zatiaľ čo Konštruktor priraďuje rodičovskú triedu.

public LoadSelectScene(Game parent)
{
    Parent = parent;
}

Metóda Update

Metóda Update opäť obsahuje čítanie z klávesnice, kde šípky dole/hore vyberajú slot (premenná selectedItem), šípky doľava, doprava vyberajú multiplayer (premenná MP).

case ConsoleKey.LeftArrow:
case ConsoleKey.RightArrow:
case ConsoleKey.A:
case ConsoleKey.D: MP = !MP; break;
case ConsoleKey.UpArrow:
case ConsoleKey.W: if (selectedItem == 0) selectedItem = 2; else selectedItem--; break;
case ConsoleKey.DownArrow:
case ConsoleKey.S: if (selectedItem == 2) selectedItem = 0; else selectedItem++; break;

Ďalej obsahuje návrat do menu klávesou Escape.

case ConsoleKey.Escape:
    selectedItem = 0;
    Parent.currentScene = Game.Scenes.MainMenu;
    break;

A hlavne potvrdenie výberu Enterom. To skontroluje, či uložená hra existuje, a ak áno, deserializuje ju do SaveState objektu. Z neho následne presunie údaje a vyberie hernú scénu. Tej ešte nastaví multiplayer a slot uloženia a pripraví ju.

case ConsoleKey.Enter:
    if (FileController.Exist("Saves\\Save_" + ((!MP) ? "SP_" : "MP_") + (selectedItem + 1) + ".xml"))
    {
        SaveState state = FileController.Load<SaveState>("Saves\\Save_" + ((!MP) ? "SP_" : "MP_") + (selectedItem + 1) + ".xml");
        Parent.Level = state.Level;
        Parent.Lives = state.Lives;
        Parent.Score = state.Score;
        Parent.currentScene = Game.Scenes.InGame;
        Parent.inGame.MultiPlayer = MP;
        Parent.inGame.ResetScene();
        Parent.inGame.SaveFile = selectedItem + 1;
    }
    break;

Zobraziť celú metódu

public void Update()
{
    if (Console.KeyAvailable)
    {
        ConsoleKey key = Console.ReadKey(true).Key;
        switch (key)
        {
            case ConsoleKey.Escape:
                selectedItem = 0;
                Parent.currentScene = Game.Scenes.MainMenu;
                break;
            case ConsoleKey.LeftArrow:
            case ConsoleKey.RightArrow:
            case ConsoleKey.A:
            case ConsoleKey.D: MP = !MP; break;
            case ConsoleKey.UpArrow:
            case ConsoleKey.W: if (selectedItem == 0) selectedItem = 2; else selectedItem--; break;
            case ConsoleKey.DownArrow:
            case ConsoleKey.S: if (selectedItem == 2) selectedItem = 0; else selectedItem++; break;
            case ConsoleKey.Enter:
                if (FileController.Exist("Saves\\Save_" + ((!MP) ? "SP_" : "MP_") + (selectedItem + 1) + ".xml"))
                {
                    SaveState state = FileController.Load<SaveState>("Saves\\Save_" + ((!MP) ? "SP_" : "MP_") + (selectedItem + 1) + ".xml");
                    Parent.Level = state.Level;
                    Parent.Lives = state.Lives;
                    Parent.Score = state.Score;
                    Parent.currentScene = Game.Scenes.InGame;
                    Parent.inGame.MultiPlayer = MP;
                    Parent.inGame.ResetScene();
                    Parent.inGame.SaveFile = (selectedItem + 1);
                }
                break;
        }
    }
}

Metóda Draw

Metóda Draw je opäť na 99% rovnaká ako pri SaveSelectScene, a tak si ukážeme len to čo je nové. Jedná sa o tlačidlá na výber multiplayer/singleplayer hry na vrchu. Tie sú vykresľované týmto krátkym kódom.

if (!MP)
{
    Renderer.DrawRectangle(new Rectangle((Renderer.WindowSize.X - 33) / 2 + 2, (Renderer.WindowSize.Y - 26) / 2 + 1, 14, 3), ConsoleColor.Green);
    Renderer.DrawString("SINGLEPLAYER", new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 2), ConsoleColor.Black);
    Renderer.DrawRectangle(new Rectangle((Renderer.WindowSize.X - 33) / 2 + 17, (Renderer.WindowSize.Y - 26) / 2 + 1, 14, 3), ConsoleColor.Blue);
    Renderer.DrawString("MULTIPLAYER", new Vector2((Renderer.WindowSize.X - 33) / 2 + 18, (Renderer.WindowSize.Y - 26) / 2 + 2), ConsoleColor.White);
}
else
{
    Renderer.DrawRectangle(new Rectangle((Renderer.WindowSize.X - 33) / 2 + 2, (Renderer.WindowSize.Y - 26) / 2 + 1, 14, 3), ConsoleColor.Blue);
    Renderer.DrawString("SINGLEPLAYER", new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 2), ConsoleColor.White);
    Renderer.DrawRectangle(new Rectangle((Renderer.WindowSize.X - 33) / 2 + 17, (Renderer.WindowSize.Y - 26) / 2 + 1, 14, 3), ConsoleColor.Green);
    Renderer.DrawString("MULTIPLAYER", new Vector2((Renderer.WindowSize.X - 33) / 2 + 18, (Renderer.WindowSize.Y - 26) / 2 + 2), ConsoleColor.Black);
}

Celú metódu si môžete pozrieť tu :

Zobraziť celú metódu

public void Draw()
{
    Renderer.DrawRectangle(new Rectangle((Renderer.WindowSize.X - 33) / 2, (Renderer.WindowSize.Y - 28) / 2, 33, 28), ConsoleColor.DarkYellow);
    Renderer.DrawRectangle(new Rectangle((Renderer.WindowSize.X - 31) / 2, (Renderer.WindowSize.Y - 26) / 2, 31, 26), ConsoleColor.Yellow);
            
    Renderer.DrawString("SELECT SAVE", new Vector2((Renderer.WindowSize.X - "SELECT SAVE".Length) / 2, (Renderer.WindowSize.Y - 28) / 2), ConsoleColor.White);

    if (!MP)
    {
        Renderer.DrawRectangle(new Rectangle((Renderer.WindowSize.X - 33) / 2 + 2, (Renderer.WindowSize.Y - 26) / 2 + 1, 14, 3), ConsoleColor.Green);
        Renderer.DrawString("SINGLEPLAYER", new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 2), ConsoleColor.Black);
        Renderer.DrawRectangle(new Rectangle((Renderer.WindowSize.X - 33) / 2 + 17, (Renderer.WindowSize.Y - 26) / 2 + 1, 14, 3), ConsoleColor.Blue);
        Renderer.DrawString("MULTIPLAYER", new Vector2((Renderer.WindowSize.X - 33) / 2 + 18, (Renderer.WindowSize.Y - 26) / 2 + 2), ConsoleColor.White);
    }
    else
    {
        Renderer.DrawRectangle(new Rectangle((Renderer.WindowSize.X - 33) / 2 + 2, (Renderer.WindowSize.Y - 26) / 2 + 1, 14, 3), ConsoleColor.Blue);
        Renderer.DrawString("SINGLEPLAYER", new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 2), ConsoleColor.White);
        Renderer.DrawRectangle(new Rectangle((Renderer.WindowSize.X - 33) / 2 + 17, (Renderer.WindowSize.Y - 26) / 2 + 1, 14, 3), ConsoleColor.Green);
        Renderer.DrawString("MULTIPLAYER", new Vector2((Renderer.WindowSize.X - 33) / 2 + 18, (Renderer.WindowSize.Y - 26) / 2 + 2), ConsoleColor.Black);
    }


    string SAVE1 = "           SAVE 1";
    string SAVE2 = "┌─────────────────────────┐";
    string SAVE3 = "│           FREE          │";
    string SAVE4 = "└─────────────────────────┘";
    if (FileController.Exist("Saves\\Save_" + ((!MP) ? "SP_" : "MP_") + 1 + ".xml"))
    {
        SaveState state = FileController.Load<SaveState>("Saves\\Save_" + ((!MP) ? "SP_" : "MP_") + 1 + ".xml");
        SAVE2 = "SCORE: " + state.Score;
        SAVE3 = "LEVEL: " + state.Level;
        SAVE4 = "LIVES: " + state.Lives;
    }
    if (selectedItem == 0)
    {
        Renderer.DrawRectangle(new Rectangle((Renderer.WindowSize.X - 33) / 2 + 2, (Renderer.WindowSize.Y - 26) / 2 + 5, 29, 6), ConsoleColor.Green);
        Renderer.DrawString(SAVE1, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 6), ConsoleColor.Black);
        Renderer.DrawString(SAVE2, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 7), ConsoleColor.Black);
        Renderer.DrawString(SAVE3, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 8), ConsoleColor.Black);
        Renderer.DrawString(SAVE4, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 9), ConsoleColor.Black);
    }
    else
    {
        Renderer.DrawRectangle(new Rectangle((Renderer.WindowSize.X - 33) / 2 + 2, (Renderer.WindowSize.Y - 26) / 2 + 5, 29, 6), ConsoleColor.Blue);
        Renderer.DrawString(SAVE1, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 6), ConsoleColor.White);
        Renderer.DrawString(SAVE2, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 7), ConsoleColor.White);
        Renderer.DrawString(SAVE3, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 8), ConsoleColor.White);
        Renderer.DrawString(SAVE4, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 9), ConsoleColor.White);
    }

    SAVE1 = "           SAVE 2";
    SAVE2 = "┌─────────────────────────┐";
    SAVE3 = "│           FREE          │";
    SAVE4 = "└─────────────────────────┘";
    if (FileController.Exist("Saves\\Save_" + ((!MP) ? "SP_" : "MP_") + 2 + ".xml"))
    {
        SaveState state = FileController.Load<SaveState>("Saves\\Save_" + ((!MP) ? "SP_" : "MP_") + 2 + ".xml");
        SAVE2 = "SCORE: " + state.Score;
        SAVE3 = "LEVEL: " + state.Level;
        SAVE4 = "LIVES: " + state.Lives;
    }
    if (selectedItem == 1)
    {
        Renderer.DrawRectangle(new Rectangle((Renderer.WindowSize.X - 33) / 2 + 2, (Renderer.WindowSize.Y - 26) / 2 + 12, 29, 6), ConsoleColor.Green);
        Renderer.DrawString(SAVE1, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 13), ConsoleColor.Black);
        Renderer.DrawString(SAVE2, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 14), ConsoleColor.Black);
        Renderer.DrawString(SAVE3, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 15), ConsoleColor.Black);
        Renderer.DrawString(SAVE4, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 16), ConsoleColor.Black);
    }
    else
    {
        Renderer.DrawRectangle(new Rectangle((Renderer.WindowSize.X - 33) / 2 + 2, (Renderer.WindowSize.Y - 26) / 2 + 12, 29, 6), ConsoleColor.Blue);
        Renderer.DrawString(SAVE1, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 13), ConsoleColor.White);
        Renderer.DrawString(SAVE2, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 14), ConsoleColor.White);
        Renderer.DrawString(SAVE3, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 15), ConsoleColor.White);
        Renderer.DrawString(SAVE4, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 16), ConsoleColor.White);
    }

    SAVE1 = "           SAVE 3";
    SAVE2 = "┌─────────────────────────┐";
    SAVE3 = "│           FREE          │";
    SAVE4 = "└─────────────────────────┘";
    if (FileController.Exist("Saves\\Save_" + ((!MP) ? "SP_" : "MP_") + 3 + ".xml"))
    {
        SaveState state = FileController.Load<SaveState>("Saves\\Save_" + ((!MP) ? "SP_" : "MP_") + 3 + ".xml");
        SAVE2 = "SCORE: " + state.Score;
        SAVE3 = "LEVEL: " + state.Level;
        SAVE4 = "LIVES: " + state.Lives;
    }
    if (selectedItem == 2)
    {
        Renderer.DrawRectangle(new Rectangle((Renderer.WindowSize.X - 33) / 2 + 2, (Renderer.WindowSize.Y - 26) / 2 + 19, 29, 6), ConsoleColor.Green);
        Renderer.DrawString(SAVE1, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 20), ConsoleColor.Black);
        Renderer.DrawString(SAVE2, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 21), ConsoleColor.Black);
        Renderer.DrawString(SAVE3, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 22), ConsoleColor.Black);
        Renderer.DrawString(SAVE4, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 23), ConsoleColor.Black);
    }
    else
    {
        Renderer.DrawRectangle(new Rectangle((Renderer.WindowSize.X - 33) / 2 + 2, (Renderer.WindowSize.Y - 26) / 2 + 19, 29, 6), ConsoleColor.Blue);
        Renderer.DrawString(SAVE1, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 20), ConsoleColor.White);
        Renderer.DrawString(SAVE2, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 21), ConsoleColor.White);
        Renderer.DrawString(SAVE3, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 22), ConsoleColor.White);
        Renderer.DrawString(SAVE4, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 23), ConsoleColor.White);
    }
}

Tým sme prebrali triedu na načítanie hry a čo ďalej? To sa nechajte prekvapiť, no blížime sa do nášho cielu.

Zobraziť celú triedu

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Snake
{
public class LoadSelectScene
{
private bool MP = false;
private int selectedItem = 0;
private Game Parent;
public Game.Scenes last;    
public LoadSelectScene(Game parent)
{
Parent = parent;
}
public void Update()
{
if (Console.KeyAvailable)
{
ConsoleKey key = Console.ReadKey(true).Key;
switch (key)
{
case ConsoleKey.Escape:
selectedItem = 0;
Parent.currentScene = Game.Scenes.MainMenu;
break;
case ConsoleKey.LeftArrow:
case ConsoleKey.RightArrow:
case ConsoleKey.A:
case ConsoleKey.D: MP = !MP; break;
case ConsoleKey.UpArrow:
case ConsoleKey.W: if (selectedItem == 0) selectedItem = 2; else selectedItem--; break;
case ConsoleKey.DownArrow:
case ConsoleKey.S: if (selectedItem == 2) selectedItem = 0; else selectedItem++; break;
case ConsoleKey.Enter:
if (FileController.Exist("Saves\\Save_" + ((!MP) ? "SP_" : "MP_") + (selectedItem + 1) + ".xml"))
{
SaveState state = FileController.Load<SaveState>("Saves\\Save_" + ((!MP) ? "SP_" : "MP_") + (selectedItem + 1) + ".xml");
Parent.Level = state.Level;
Parent.Lives = state.Lives;
Parent.Score = state.Score;
Parent.currentScene = Game.Scenes.InGame;
Parent.inGame.MultiPlayer = MP;
Parent.inGame.ResetScene();
Parent.inGame.SaveFile = (selectedItem + 1);
}
break;
}
}
}
public void Draw()
{
Renderer.DrawRectangle(new Rectangle((Renderer.WindowSize.X - 33) / 2, (Renderer.WindowSize.Y - 28) / 2, 33, 28), ConsoleColor.DarkYellow);
Renderer.DrawRectangle(new Rectangle((Renderer.WindowSize.X - 31) / 2, (Renderer.WindowSize.Y - 26) / 2, 31, 26), ConsoleColor.Yellow);
Renderer.DrawString("SELECT SAVE", new Vector2((Renderer.WindowSize.X - "SELECT SAVE".Length) / 2, (Renderer.WindowSize.Y - 28) / 2), ConsoleColor.White);
if (!MP)
{
Renderer.DrawRectangle(new Rectangle((Renderer.WindowSize.X - 33) / 2 + 2, (Renderer.WindowSize.Y - 26) / 2 + 1, 14, 3), ConsoleColor.Green);
Renderer.DrawString("SINGLEPLAYER", new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 2), ConsoleColor.Black);
Renderer.DrawRectangle(new Rectangle((Renderer.WindowSize.X - 33) / 2 + 17, (Renderer.WindowSize.Y - 26) / 2 + 1, 14, 3), ConsoleColor.Blue);
Renderer.DrawString("MULTIPLAYER", new Vector2((Renderer.WindowSize.X - 33) / 2 + 18, (Renderer.WindowSize.Y - 26) / 2 + 2), ConsoleColor.White);
}
else
{
Renderer.DrawRectangle(new Rectangle((Renderer.WindowSize.X - 33) / 2 + 2, (Renderer.WindowSize.Y - 26) / 2 + 1, 14, 3), ConsoleColor.Blue);
Renderer.DrawString("SINGLEPLAYER", new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 2), ConsoleColor.White);
Renderer.DrawRectangle(new Rectangle((Renderer.WindowSize.X - 33) / 2 + 17, (Renderer.WindowSize.Y - 26) / 2 + 1, 14, 3), ConsoleColor.Green);
Renderer.DrawString("MULTIPLAYER", new Vector2((Renderer.WindowSize.X - 33) / 2 + 18, (Renderer.WindowSize.Y - 26) / 2 + 2), ConsoleColor.Black);
}
string SAVE1 = "           SAVE 1";
string SAVE2 = "┌─────────────────────────┐";
string SAVE3 = "│           FREE          │";
string SAVE4 = "└─────────────────────────┘";
if (FileController.Exist("Saves\\Save_" + ((!MP) ? "SP_" : "MP_") + 1 + ".xml"))
{
SaveState state = FileController.Load<SaveState>("Saves\\Save_" + ((!MP) ? "SP_" : "MP_") + 1 + ".xml");
SAVE2 = "SCORE: " + state.Score;
SAVE3 = "LEVEL: " + state.Level;
SAVE4 = "LIVES: " + state.Lives;
}
if (selectedItem == 0)
{
Renderer.DrawRectangle(new Rectangle((Renderer.WindowSize.X - 33) / 2 + 2, (Renderer.WindowSize.Y - 26) / 2 + 5, 29, 6), ConsoleColor.Green);
Renderer.DrawString(SAVE1, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 6), ConsoleColor.Black);
Renderer.DrawString(SAVE2, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 7), ConsoleColor.Black);
Renderer.DrawString(SAVE3, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 8), ConsoleColor.Black);
Renderer.DrawString(SAVE4, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 9), ConsoleColor.Black);
}
else
{
Renderer.DrawRectangle(new Rectangle((Renderer.WindowSize.X - 33) / 2 + 2, (Renderer.WindowSize.Y - 26) / 2 + 5, 29, 6), ConsoleColor.Blue);
Renderer.DrawString(SAVE1, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 6), ConsoleColor.White);
Renderer.DrawString(SAVE2, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 7), ConsoleColor.White);
Renderer.DrawString(SAVE3, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 8), ConsoleColor.White);
Renderer.DrawString(SAVE4, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 9), ConsoleColor.White);
}
SAVE1 = "           SAVE 2";
SAVE2 = "┌─────────────────────────┐";
SAVE3 = "│           FREE          │";
SAVE4 = "└─────────────────────────┘";
if (FileController.Exist("Saves\\Save_" + ((!MP) ? "SP_" : "MP_") + 2 + ".xml"))
{
SaveState state = FileController.Load<SaveState>("Saves\\Save_" + ((!MP) ? "SP_" : "MP_") + 2 + ".xml");
SAVE2 = "SCORE: " + state.Score;
SAVE3 = "LEVEL: " + state.Level;
SAVE4 = "LIVES: " + state.Lives;
}
if (selectedItem == 1)
{
Renderer.DrawRectangle(new Rectangle((Renderer.WindowSize.X - 33) / 2 + 2, (Renderer.WindowSize.Y - 26) / 2 + 12, 29, 6), ConsoleColor.Green);
Renderer.DrawString(SAVE1, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 13), ConsoleColor.Black);
Renderer.DrawString(SAVE2, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 14), ConsoleColor.Black);
Renderer.DrawString(SAVE3, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 15), ConsoleColor.Black);
Renderer.DrawString(SAVE4, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 16), ConsoleColor.Black);
}
else
{
Renderer.DrawRectangle(new Rectangle((Renderer.WindowSize.X - 33) / 2 + 2, (Renderer.WindowSize.Y - 26) / 2 + 12, 29, 6), ConsoleColor.Blue);
Renderer.DrawString(SAVE1, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 13), ConsoleColor.White);
Renderer.DrawString(SAVE2, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 14), ConsoleColor.White);
Renderer.DrawString(SAVE3, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 15), ConsoleColor.White);
Renderer.DrawString(SAVE4, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 16), ConsoleColor.White);
}
SAVE1 = "           SAVE 3";
SAVE2 = "┌─────────────────────────┐";
SAVE3 = "│           FREE          │";
SAVE4 = "└─────────────────────────┘";
if (FileController.Exist("Saves\\Save_" + ((!MP) ? "SP_" : "MP_") + 3 + ".xml"))
{
SaveState state = FileController.Load<SaveState>("Saves\\Save_" + ((!MP) ? "SP_" : "MP_") + 3 + ".xml");
SAVE2 = "SCORE: " + state.Score;
SAVE3 = "LEVEL: " + state.Level;
SAVE4 = "LIVES: " + state.Lives;
}
if (selectedItem == 2)
{
Renderer.DrawRectangle(new Rectangle((Renderer.WindowSize.X - 33) / 2 + 2, (Renderer.WindowSize.Y - 26) / 2 + 19, 29, 6), ConsoleColor.Green);
Renderer.DrawString(SAVE1, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 20), ConsoleColor.Black);
Renderer.DrawString(SAVE2, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 21), ConsoleColor.Black);
Renderer.DrawString(SAVE3, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 22), ConsoleColor.Black);
Renderer.DrawString(SAVE4, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 23), ConsoleColor.Black);
}
else
{
Renderer.DrawRectangle(new Rectangle((Renderer.WindowSize.X - 33) / 2 + 2, (Renderer.WindowSize.Y - 26) / 2 + 19, 29, 6), ConsoleColor.Blue);
Renderer.DrawString(SAVE1, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 20), ConsoleColor.White);
Renderer.DrawString(SAVE2, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 21), ConsoleColor.White);
Renderer.DrawString(SAVE3, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 22), ConsoleColor.White);
Renderer.DrawString(SAVE4, new Vector2((Renderer.WindowSize.X - 33) / 2 + 3, (Renderer.WindowSize.Y - 26) / 2 + 23), ConsoleColor.White);
}
}
}
}

1 názor na “Konzolový Had 10 – Načítanie Hry”

Pridajte Komentár

Vaša e-mailová adresa nebude zverejnená. Vyžadované polia sú označené *


The reCAPTCHA verification period has expired. Please reload the page.

Návrat hore