Click here to Skip to main content
15,892,517 members
Home / Discussions / C#
   

C#

 
QuestionLoading a Data Table form a DataGrid view but still no joy. Pin
Ozzie Mozzie22-Oct-22 23:59
Ozzie Mozzie22-Oct-22 23:59 
AnswerRe: Loading a Data Table form a DataGrid view but still no joy. Pin
OriginalGriff23-Oct-22 0:51
mveOriginalGriff23-Oct-22 0:51 
GeneralRe: Loading a Data Table form a DataGrid view but still no joy. Pin
Ozzie Mozzie23-Oct-22 1:19
Ozzie Mozzie23-Oct-22 1:19 
GeneralRe: Loading a Data Table form a DataGrid view but still no joy. Pin
OriginalGriff23-Oct-22 1:46
mveOriginalGriff23-Oct-22 1:46 
GeneralRe: Loading a Data Table form a DataGrid view but still no joy. Pin
Ozzie Mozzie23-Oct-22 2:05
Ozzie Mozzie23-Oct-22 2:05 
GeneralRe: Loading a Data Table form a DataGrid view but still no joy. Pin
OriginalGriff23-Oct-22 2:37
mveOriginalGriff23-Oct-22 2:37 
GeneralRe: Loading a Data Table form a DataGrid view but still no joy. Pin
Ozzie Mozzie23-Oct-22 14:36
Ozzie Mozzie23-Oct-22 14:36 
GeneralRe: Loading a Data Table form a DataGrid view but still no joy. Pin
Ozzie Mozzie23-Oct-22 16:03
Ozzie Mozzie23-Oct-22 16:03 
GeneralRe: Loading a Data Table form a DataGrid view but still no joy. Pin
OriginalGriff23-Oct-22 21:35
mveOriginalGriff23-Oct-22 21:35 
QuestionC# Save DataGrid Only MultiSelected Rows to File Pin
CodaNV22-Oct-22 17:03
CodaNV22-Oct-22 17:03 
AnswerRe: C# Save DataGrid Only MultiSelected Rows to File Pin
Dave Kreskowiak22-Oct-22 17:50
mveDave Kreskowiak22-Oct-22 17:50 
GeneralRe: C# Save DataGrid Only MultiSelected Rows to File Pin
CodaNV22-Oct-22 18:11
CodaNV22-Oct-22 18:11 
GeneralRe: C# Save DataGrid Only MultiSelected Rows to File Pin
Dave Kreskowiak22-Oct-22 18:24
mveDave Kreskowiak22-Oct-22 18:24 
GeneralRe: C# Save DataGrid Only MultiSelected Rows to File Pin
CodaNV22-Oct-22 18:47
CodaNV22-Oct-22 18:47 
QuestionArduino canot control computer. Pin
Member 1549382322-Oct-22 10:38
Member 1549382322-Oct-22 10:38 
AnswerRe: Arduino canot control computer. Pin
OriginalGriff22-Oct-22 10:53
mveOriginalGriff22-Oct-22 10:53 
QuestionReliable COM Port Communication Pin
Member 1495533221-Oct-22 1:36
Member 1495533221-Oct-22 1:36 
QuestionSimple Snake Game - Snake Head is not moving after ReadKey() Pin
Programmable Physics20-Oct-22 0:12
Programmable Physics20-Oct-22 0:12 
The snake head ```
<pre lang="C#">
0``` does not move anywhere when ```
C#
Console.ReadKey()
``` happens.
Here is the full code:

```
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SimpleSnakeGame_ConsoleApp
{
    internal class Program
    {
        public bool gameOver = true;
        public int width = 20;
        public int height = 20;

        //HEAD POS
        public int x, y;

        //FRUIT POS
        public int fruitX, fruitY;

        public int score;

        //bir kere basinca oraya gitmeni saglayacak enum
        enum eDirection { STOP = 0, LEFT, RIGHT, UP, DOWN };
        eDirection dir; //enum class gibi çalisiyor enum'dan dir isimli bir object yarattik

        static void Main(string[] args)
        {

            Program oyun = new Program();

                oyun.Setup();

                oyun.Draw();
                oyun.Input();
                oyun.Logic();


            Console.ReadLine();
        }

        //Setting Up the MAP
        public void Setup()
        {
            gameOver = false;
            string a = "!!!!! SIMPLE SNAKE GAME !!!!!";
            Console.WriteLine(gameOver.ToString() + " " + a, "{0}" + "{1}");
            dir = eDirection.STOP;
            x = width / 2;
            y = height / 2;

            Random rnd = new Random();
            fruitX = rnd.Next(1, 19);
            fruitY = rnd.Next(1, 19);
            score = 0;

        }
        void Draw()
        {
            for (int j = 0; j < height; j++)
            {
                for (int i = 0; i < width; i++)
                {
                    if (i == y && j == x)
                    {
                        Console.Write("0");
                    }
                    else if (i == fruitY && j == fruitX)
                    {
                        Console.Write("F");
                    }
                    else if (j > 0 && j < height - 1 && i > 0 && i < width - 1)
                    {
                        Console.Write(" ");
                    }
                    else
                    {
                        Console.Write("#");
                    }

                }

                Console.WriteLine();
            }

            Console.WriteLine();
        }
        void Input()
        {
            ConsoleKey key;

            // Key is available - read it
            key = Console.ReadKey(true).Key;

            if (key == ConsoleKey.A)
            {
                dir = eDirection.LEFT;
            }
            else if (key == ConsoleKey.D)
            {
                dir = eDirection.RIGHT;
            }
            else if (key == ConsoleKey.W)
            {
                dir = eDirection.UP;
            }
            else if (key == ConsoleKey.S)
            {
                dir = eDirection.DOWN;
            }
            else if (key == ConsoleKey.X)
            {
                gameOver=true;
            }
        }
        void Logic()
        {
            switch (dir)
            {
                case eDirection.LEFT:
                    x--;
                    break;
                case eDirection.RIGHT:
                    x++;
                    break;
                case eDirection.UP:
                    y--;
                    break;
                case eDirection.DOWN:
                    y++;
                    break;
                default:
                    break;
            }
        }
    }

}

```

I guess the problem is ```
C#
Console.ReadKey()
``` function here:

```
C#
void Input()
        {
            ConsoleKey key;

            // Key is available - read it
            key = Console.ReadKey(true).Key;

            if (key == ConsoleKey.A)
            {
                dir = eDirection.LEFT;
            }
            else if (key == ConsoleKey.D)
            {
                dir = eDirection.RIGHT;
            }
            else if (key == ConsoleKey.W)
            {
                dir = eDirection.UP;
            }
            else if (key == ConsoleKey.S)
            {
                dir = eDirection.DOWN;
            }
            else if (key == ConsoleKey.X)
            {
                gameOver=true;
            }
        }

```
However I do not know what to replace ```
<pre lang="C#">
Console.ReadKey()``` with and how to do it.
AnswerRe: Simple Snake Game - Snake Head is not moving after ReadKey() Pin
jsc4220-Oct-22 0:23
professionaljsc4220-Oct-22 0:23 
Questionget string from if statement in c# Pin
Sycho AN19-Oct-22 11:04
Sycho AN19-Oct-22 11:04 
AnswerRe: get string from if statement in c# Pin
OriginalGriff19-Oct-22 11:32
mveOriginalGriff19-Oct-22 11:32 
GeneralRe: get string from if statement in c# Pin
Sycho AN19-Oct-22 12:24
Sycho AN19-Oct-22 12:24 
GeneralRe: get string from if statement in c# Pin
Dave Kreskowiak19-Oct-22 12:33
mveDave Kreskowiak19-Oct-22 12:33 
AnswerRe: get string from if statement in c# Pin
Gerry Schmitz19-Oct-22 14:10
mveGerry Schmitz19-Oct-22 14:10 
AnswerRe: get string from if statement in c# Pin
Pete O'Hanlon21-Oct-22 8:20
mvePete O'Hanlon21-Oct-22 8:20 

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.