Hallo liebe Forengemeinde,
ich habe mir vorgenommen ein einfaches SnakeGame auf der Konsole zu programmieren.
Leider hänge ich schon jetzt bei der Bewegung des Spielers (dem "O") fest.
Vielleicht kann mir ja einer von euch meinen Denkfehler erklären.
Das wäre sehr nett.
|
C#-Quelltext
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
public class Snake
{
int sx = 5; // x und y Position der Spielers
int sy = 5;
public void Draw()
{
Console.SetCursorPosition(sx, sy);
Console.Write("O");
}
public void Move()
{
var key = Console.ReadKey();
Console.SetCursorPosition(sx, sy);
Console.Write(" ");
switch (key.Key)
{
case ConsoleKey.W:
if (sy >= 1) { sy = sy - 1;}
Draw();
break;
case ConsoleKey.A:
break;
case ConsoleKey.S:
break;
case ConsoleKey.D:
break;
default:
break;
}
}
}
public class Spielfeld
{
}
public class Food
{
}
class Program
{
static void Main(string[] args)
{
Snake schlange = new Snake();
Console.CursorVisible = false;
schlange.Draw();
schlange.Move();
Console.ReadKey();
}
}
}
|
Also das eigentlich Problem ist das die Konsole immer ein "w" schreibt sobald ich das O nach oben bewegen will.
Vielen dank schon mal im voraus.