C# problema c# (application console) su cursori, matrici e ascii art "dinamiche"

gabrielesilinic

Utente Bronze
24 Febbraio 2019
48
11
8
37
Ultima modifica:
Buongiorno, sono un principiante, studente di informatica al terzo anno di itis, nella mia scuola si usa c# e così è diventato il mio linguaggio principale, nel tempo libero ho provato a realizzare un progetto che consisteva nel far aggiornare e poi visualizzare una ascii art posta in una matrice nei soli punti ove tra un "frame" e l'altro c'era una differenza, per evitare lo sgradevole effetto che porta un Console.Clear() e un Console.Writeline() in ciclo, inizialmente feci un codice più grande che comprendeva anche i colori (quelli della ConsoleColor) ma poiché notai che non funzionava a dovere provai a farne una versione ridotta partendo dall'inizio e notai che anch'essa non si comportava come sperato, così mi sono iscritto qui sperando che qualcuno trovi l'errore che io non riesco a trovare, detto questo, ecco il codice e grazie per l'attenzione e anche in anticipo per una possibile soluzione
problema: non si aggiorna affatto
tipo di errore: errore logico (
probabilmente)
cos'ho sbagliato?
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
namespace CsharpConsoleFrameEngine
{
    class Program
    {
        const char nullchar = '.';
        static int screenwidth = 30;
        static int screenheight = 30;
        static char[,] screenchar = new char[screenwidth, screenheight];
        static char[,] oldscreenchar = new char[screenwidth, screenheight];
        static void Main(string[] args)
        {
           
            fill2dchar(screenchar, nullchar);
            fill2dchar(oldscreenchar, ',');
            while (true)
            {
                Update();
                ScreenEdit();
                ScreenUpdate();
                oldscreenchar = screenchar;
                Thread.Sleep(100);
            }
        }
        static Random rnd = new Random();
        static int entityY;
        static int entityX;
        static void Update()
        {
            if (entityX < screenheight - 1)
                entityX++;
            else
                entityX = 0;
            if (entityY < screenwidth - 1)
                entityY++;
            else
                entityY = 0;
           


        }
        static int counter = 0;
        static void ScreenEdit()
        {
            counter++;
            //fill2dchar(screenchar,nullchar);
            screenchar[entityX, entityY] = '@';
           
        }

        static void ScreenUpdate()
        {
            int  ischanged = 0;
            for(int i=0;i<screenchar.GetUpperBound(0);i++)
            {
                for (int j = 0; j < screenchar.GetUpperBound(0); j++)
                {
                    if (!(screenchar[i,j]==oldscreenchar[i, j]))
                    {
                        Console.SetCursorPosition(i, j);
                        Console.Write(screenchar[i, j]);
                        ischanged++;
                    }
                }
            }
            Console.Title = string.Format("done {0}| x{1} y{2} |{3}", counter, entityX, entityY,ischanged);
        }
        static void fill2dchar(char[,] matrix,char mychar)
        {
            for (int i = 0; i < matrix.GetUpperBound(0); i++)
            {
                for (int j = 0; j < matrix.GetUpperBound(0); j++)
                {
                    matrix[i, j] = mychar;
                }
            }
        }

    }

}