0
\$\begingroup\$

Using Visual Studio with C#, I am trying to have another room redrawn after the player walks into a door. What I'm finding is it creates more than one room and the walls don't line up. The code is supposed to clear the screen first then redraw the room and randomly position the player, but it does this more than once.

class ScreenRectangle : MapProperites
{
    // the Height and width and edge of the screen inside the console window
    public int ScreenHeight { get; private set; }
    public int ScreenWidth { get; private set; }
    public int Edge { get; private set; }
   
    private char[,] m_buffer; // currently is not being used 

    /// <summary>
    /// a function that sets up the parameters of the rectangle 
    /// </summary>
    /// <param name="Height"></param>
    /// <param name="Width"></param>
    public ScreenRectangle(int Height, int Width)
    {
        ScreenHeight = Height;
        ScreenWidth = Width;
        Edge = ScreenWidth - 1;
    }
    /// <summary>
    /// a public function that makes up the display for the player to move around in
    /// </summary>
    public void TestDisplay()
    {
        Console.Clear();
        Console.CursorVisible = false;
        Console.SetCursorPosition(0, 0);
        StringBuilder mapDisplay = new StringBuilder();

        for (int y = 0; y < ScreenHeight; y++)
        {
            for (int x = 0; x < ScreenWidth; x++)
            {
                switch (x)
                {
                    case 0:
                        if (y == 0) // top left corner 
                        {
                            mapDisplay.Append((char)9484);
                        }
                        else if (y == 29)// bottom left corner 
                        {
                            mapDisplay.Append((char)9492);
                        }
                        else // the left veritcal edge
                        {
                            mapDisplay.Append((char)9474);
                        }
                        break;
                    case 99:
                        if (y == 0) // the top right corner 
                        {
                            mapDisplay.Append((char)9488);
                        }
                        else if (y == 29) // the bottom right corner 
                        {
                            mapDisplay.Append((char)9496);
                        }
                        else // right vertical edge 
                        {
                            mapDisplay.Append((char)9474);
                        }
                        break;
                    default:
                        if (y == 0)// the top horizontal edge 
                        {
                            mapDisplay.Append((char)9472);
                        }
                        else if (y == 29)// the bottom horizontal edge 
                        {
                            mapDisplay.Append((char)9472);
                        }
                        else// a empty space within the overall zone 
                        {
                            mapDisplay.Append(" ");
                        }
                        break;
                }
            }
            mapDisplay.Append("\n");
             
        }
        Console.WriteLine(mapDisplay.ToString());
        Interactables generatePickups = new Interactables();
        generatePickups.Item();
       
        Doors generateDoors = new Doors("D");
        Display display = new Display();
        display.DrawDoor();

    }
}

The next set of code shows the door as a pickup where the player walks into the door and clears the screen before redrawing

void CheckPlayerOnPickup()
    {
        foreach (Pickups pickup in displayedPickups)
        {
            if (playerOne.X == pickup.x && playerOne.Y == pickup.y)
            {
                if (pickup.mychar == 'O')
                {
                    playerOne.Score += 1;
                    displayedPickups.Remove(pickup);
                }
                if (pickup.mychar == 'L')
                {
                    playerOne.Inventory.Add(new Item(1, " 1 LaserSword           "));
                    playerOne.Score += 2;
                    displayedPickups.Remove(pickup);
                    OpenInventory();
                }
                if (pickup.mychar == 'G')
                {
                    playerOne.Inventory.Add(new Item(1, " 1 laserGun           "));
                    playerOne.Score += 3;
                    displayedPickups.Remove(pickup);
                    OpenInventory();
                }
                if (pickup.mychar == 'K')
                {
                    playerOne.Inventory.Add(new Item(1, " 1 KeyCard           "));
                    displayedPickups.Remove(pickup);
                    OpenInventory();
                }
                if (pickup.mychar == 'D')
                {
                    ScreenRectangle generateScreenRectangle = new ScreenRectangle(ScreenHeight, ScreenWidth);
                    Console.Clear();
                    generateScreenRectangle.TestDisplay();
                    Playerone(); 


                }
                break;
\$\endgroup\$
0

0

You must log in to answer this question.

Browse other questions tagged .