How to make text flash different colors in a C# console application? -


i have program http://pastebin.com/uhni15pw

i want code flash of colors avalible

console.writeline("welcome tic tac toe!"); 

how go this?

to this, need know position of text on console (because console.writeline write @ current cursor position). can this:

public async task showtextincolors(string text, int x, int y, int delay, cancellationtoken token) {     consolecolor[] colors = enum.getvalues(typeof(consolecolor)).oftype<consolecolor>().toarray();      int color = -1;     while (!token.iscancellationrequested)     {         color += 1;         if (color >= colors.length) color = 0;         console.cursorleft = x;         console.cursortop = y;         console.foregroundcolor = colors[color];         console.write(text);         await task.delay(delay, token);     } } 

x , y determine cursor position on console @ want display text.

you can call that:

cancellationtokensource source = new cancellationtokensource(); showtextincolors("welcome tic tac toe!", 0, 10, 1000, source.token); 

and stop calling

source.cancel(); 

note interfer other calls console.* methods in other threads. , since question looks want display tic tac toe game below line, may need synchronize console.* calls. synchronization new question , surely find lot of them on stackoverflow (try lock keyword).


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -