Im not sure what the problem is but here is my code
but when i run it instead of clearing the console and then printing the next frame it just prints the next frame 🙁
I tried chaning to internal terminal but still no good
using System;
using System.Globalization;
using System.Security.Cryptography.X509Certificates;
using System.Windows.Input;
using System.Threading;
using System.Net.NetworkInformation;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
string createMap(string[] map, int pyPos, int pxPos){
return map[0]+"n"+map[1]+"n"+map[2]+"n"+map[3]+"n"+map[4]+"n"+map[5]+"n"+map[6]+"n"+map[7]+"n"+map[8]+"n"+map[9]+"n"+map[10]+"n"+map[11]+"n"+map[12]+"n"+map[13]+"n"+map[14]+"n"+map[15]+"n"+map[16]+"n"+map[17]+"n"+map[18]+"n"+map[19]+"n"+map[20]+"n"+map[21]+"n"+map[22]+"n"+map[23]+"n"+map[24]+"n"+map[25]+"n"+map[26]+"n"+map[27]+"n"+map[28]+"n"+map[29]+" X: "+pxPos+"; Y: "+pyPos+"n";
}
string[] RefreshMap(string [][] layerVar, int pyPos, int pxPos, string player){
string[] layers = new string[]{"","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""};
layerVar[pyPos][pxPos] = player; //intergrate play into map
for (int i = 0; i < 30; i++)
{
layers[i] = layerVar[i][0]+layerVar[i][1]+layerVar[i][2]+layerVar[i][3]+layerVar[i][4]+layerVar[i][5]+layerVar[i][6]+layerVar[i][7]+layerVar[i][8]+layerVar[i][9]+layerVar[i][10]+layerVar[i][11]+layerVar[i][12]+layerVar[i][13]+layerVar[i][14]+layerVar[i][15]+layerVar[i][16]+layerVar[i][17]+layerVar[i][18]+layerVar[i][19]+layerVar[i][20]+layerVar[i][21]+layerVar[i][22]+layerVar[i][23]+layerVar[i][24]+layerVar[i][25]+layerVar[i][26]+layerVar[i][27]+layerVar[i][28]+layerVar[i][29];
}
string [] temp = new string[] {
layers[0],
layers[1],
layers[2],
layers[3],
layers[4],
layers[5],
layers[6],
layers[7],
layers[8],
layers[9],
layers[10],
layers[11],
layers[12],
layers[13],
layers[14],
layers[15],
layers[16],
layers[17],
layers[18],
layers[19],
layers[20],
layers[21],
layers[22],
layers[23],
layers[24],
layers[25],
layers[26],
layers[27],
layers[28],
layers[29]
};
return temp;
}
string floor = "¯¯";
string roof = "__";
string wallR = "▐▌";
string wallL = "▐▌";
string player = "╞╡";
int mapsizeX = 30;
int mapsizeY = 30;
int pyPos = 0;// work on player movement; done - no colloision; done with collision?;
int pxPos = 1;// work on gravity and collision
bool holder = true;
Console.Title = "PathToRedemption";// work on game line
string[][] layers = new string[30][]{// work on increasing map size; 10 => 30;
new string[30]{wallL," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ",wallR},
new string[30]{wallL," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ",wallR},
new string[30]{wallL," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ",wallR},
new string[30]{wallL," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ",wallR},
new string[30]{wallL," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ",wallR},
new string[30]{wallL," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ",wallR},
new string[30]{wallL," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ",wallR},
new string[30]{wallL," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ",wallR},
new string[30]{wallL," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ",wallR},
new string[30]{wallL," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ",wallR},
new string[30]{wallL," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ",wallR},
new string[30]{wallL," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ",wallR},
new string[30]{wallL," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ",wallR},
new string[30]{wallL," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ",wallR},
new string[30]{wallL," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ",wallR},
new string[30]{wallL," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ",wallR},
new string[30]{wallL," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ",wallR},
new string[30]{wallL," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ",wallR},
new string[30]{wallL," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ",wallR},
new string[30]{wallL," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ",wallR},
new string[30]{wallL," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ",wallR},
new string[30]{wallL," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ",wallR},
new string[30]{wallL," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ",wallR},
new string[30]{wallL," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ",wallR},
new string[30]{wallL," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ",wallR},
new string[30]{wallL," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ",wallR},
new string[30]{wallL," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ",wallR},
new string[30]{wallL," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ",wallR},
new string[30]{wallL," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ",wallR},
new string[30]{floor,floor,floor,floor,floor,floor,floor,floor,floor,floor,floor,floor,floor,floor,floor,floor,floor,floor,floor,floor,floor,floor,floor,floor,floor,floor,floor,floor,floor,floor},
};
int[][] mapCollision = new int[30][]{// work on increasing map size; 10 => 30;
new int[30]{1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
new int[30]{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
new int[30]{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
new int[30]{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
new int[30]{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
new int[30]{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
new int[30]{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
new int[30]{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
new int[30]{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
new int[30]{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
new int[30]{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
new int[30]{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
new int[30]{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
new int[30]{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
new int[30]{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
new int[30]{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
new int[30]{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
new int[30]{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
new int[30]{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
new int[30]{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
new int[30]{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
new int[30]{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
new int[30]{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
new int[30]{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
new int[30]{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
new int[30]{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
new int[30]{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
new int[30]{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
new int[30]{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
new int[30]{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
};
//console.keyavalaibale(key.space) === keyboard replacement
while(holder){
while(Console.KeyAvailable==false){// game tick
Console.Write(createMap(RefreshMap(layers, pyPos, pxPos, player),pyPos,pxPos));
Thread.Sleep(1000);
Console.Clear();
}
while(Console.KeyAvailable){// player tick
var pInput = Console.ReadKey(true);
if (pInput.Key == ConsoleKey.Escape){
holder = false;
}
if (pInput.Key == ConsoleKey.DownArrow){
pyPos++;
if (pxPos>mapsizeY){
pyPos--;
}
else if (mapCollision[pyPos][pxPos]!=0){
pyPos--;
}
}
if (pInput.Key == ConsoleKey.UpArrow){
pyPos--;
if (pxPos<0){
pyPos++;
}
else if (mapCollision[pyPos][pxPos]!=0){
pyPos++;
}
}
if (pInput.Key == ConsoleKey.RightArrow){
pxPos++;
if (pxPos>mapsizeX){
pxPos--;
}
else if (mapCollision[pyPos][pxPos]!=0){
pxPos--;
}
}
if (pInput.Key == ConsoleKey.LeftArrow){
pxPos--;
if (pxPos<0){
pxPos++;
}
else if (mapCollision[pyPos][pxPos]!=0){
pxPos++;
}
}
}
}
Console.Read();
}
}
}
it dosent work at all and i dont how why,
try it out
——————————————————————————————————————————
Tilak Rao is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.