Click here to Skip to main content
15,921,467 members
Home / Discussions / C#
   

C#

 
AnswerRe: open an exe file in panel Pin
Eddy Vluggen8-Apr-10 6:14
professionalEddy Vluggen8-Apr-10 6:14 
QuestionLimitations of windows forms Pin
QuinsUK8-Apr-10 0:17
QuinsUK8-Apr-10 0:17 
AnswerRe: Limitations of windows forms Pin
TheFoZ8-Apr-10 1:00
TheFoZ8-Apr-10 1:00 
AnswerRe: Limitations of windows forms Pin
kevinnicol8-Apr-10 4:39
kevinnicol8-Apr-10 4:39 
QuestionKeyDown event in console Pin
bolikej7-Apr-10 22:59
bolikej7-Apr-10 22:59 
AnswerRe: KeyDown event in console Pin
Mustafa Ismail Mustafa7-Apr-10 23:54
Mustafa Ismail Mustafa7-Apr-10 23:54 
GeneralRe: KeyDown event in console Pin
bolikej8-Apr-10 2:06
bolikej8-Apr-10 2:06 
GeneralRe: KeyDown event in console Pin
Mustafa Ismail Mustafa8-Apr-10 2:59
Mustafa Ismail Mustafa8-Apr-10 2:59 
Pffft!

You got me interested in writing the game myself now! Smile | :)

I'll probably post it as an article in a week or so.

But the way I'd do it is as follows:

C#
void RunGame()
{
    while (GameIsOn)
    {
        if (Console.KeyAvailable)
        {
            ConsoleKeyInfo key = Console.ReadKey(true);

            //handle key presses
            
            switch (key.Key)
            {
                case ConsoleKey.LeftArrow:
                    CharacterDirection = Direction.Left;
                    break;
                case ConsoleKey.RightArrow:
                    CharacterDirection = Direction.Right;
                    break;
                case ConsoleKey.UpArrow:
                    CharacterDirection = Direction.Up;
                    break;
                case ConsoleKey.DownArrow:
                    CharacterDirection = Direction.Down;
                    break;
                case ConsoleKey.Escape:
                    GameIsOn = false;
                    break;
                default:
                    break;
            }
                    #endregion

                }


                AdvanceStep();

                CheckCollision();

                Thread.Sleep(100);

        } //end of game loop
}


Now in the AdvanceStep() method you're going to have calculate the new position of the cursor and Console.Write() the new character placeholder. This will "tick" in the sense that you will see the character move in whatever direction you first choose, ten steps in 1 second. You can make that faster or slower based on the number of milliseconds you let that thread sleep.

There are things that you have to bear in mind. The Character's initial position [ (0,0) vs centre point ] the character's initial direction and so on. If for example you set the initial position at (0,0) and the initial direction is Right, then the character will move to the right (x-axis change only) until a button is pressed that will alter the direction.

If there are many attributes that you would like to add to your character, such as the length of the tail (we are talking about a snake-clone, right?), and also a history of the turns that were made (so that the tail will also turn at the correct locations) you might want to break into a class and if the list of positions can be lengthy (as can easily happen on a "big screen" with an expert player) then you might want to break that into its own vector class list.

If you have anymore questions, post some code as well, and we'll see how we can help you with where you are stuck Smile | :)
If the post was helpful, please vote, eh!

Current activities:
Book: Devils by Fyodor Dostoyevsky
Project: Hospital Automation, final stage
Learning: Image analysis, LINQ

Now and forever, defiant to the end.
What is Multiple Sclerosis[^]?

GeneralRe: KeyDown event in console Pin
bolikej8-Apr-10 10:03
bolikej8-Apr-10 10:03 
GeneralRe: KeyDown event in console Pin
Mustafa Ismail Mustafa8-Apr-10 10:17
Mustafa Ismail Mustafa8-Apr-10 10:17 
QuestionAn equivalent of -javaagent in C#? Or: ways to use a java framework in C# Pin
blackblizzard7-Apr-10 22:24
blackblizzard7-Apr-10 22:24 
Questionsetting focus on masked textbox control added in datagridview Pin
Nouman Bhatti7-Apr-10 20:57
Nouman Bhatti7-Apr-10 20:57 
AnswerRe: setting focus on masked textbox control added in datagridview Pin
yogesh_kumar_agarwal7-Apr-10 21:03
yogesh_kumar_agarwal7-Apr-10 21:03 
GeneralRe: setting focus on masked textbox control added in datagridview Pin
Nouman Bhatti7-Apr-10 21:09
Nouman Bhatti7-Apr-10 21:09 
GeneralRe: setting focus on masked textbox control added in datagridview Pin
yogesh_kumar_agarwal7-Apr-10 21:16
yogesh_kumar_agarwal7-Apr-10 21:16 
GeneralRe: setting focus on masked textbox control added in datagridview Pin
Nouman Bhatti7-Apr-10 21:22
Nouman Bhatti7-Apr-10 21:22 
GeneralRe: setting focus on masked textbox control added in datagridview Pin
yogesh_kumar_agarwal7-Apr-10 23:49
yogesh_kumar_agarwal7-Apr-10 23:49 
QuestionWhat OracleType to use for table of record output parameter Pin
whiteadi7-Apr-10 20:51
whiteadi7-Apr-10 20:51 
QuestionMessage Removed Pin
7-Apr-10 20:30
arun_pk7-Apr-10 20:30 
AnswerRe: xml reading Pin
SeMartens7-Apr-10 21:03
SeMartens7-Apr-10 21:03 
GeneralRe: xml reading Pin
arun_pk8-Apr-10 1:36
arun_pk8-Apr-10 1:36 
AnswerRe: xml reading Pin
Mirko19807-Apr-10 23:23
Mirko19807-Apr-10 23:23 
QuestionCSV files in C# Pin
i gr87-Apr-10 20:11
i gr87-Apr-10 20:11 
AnswerRe: CSV files in C# Pin
SeMartens7-Apr-10 21:05
SeMartens7-Apr-10 21:05 
AnswerRe: CSV files in C# Pin
yujianchi7-Apr-10 23:29
yujianchi7-Apr-10 23:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.