-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
141 lines (126 loc) · 2.94 KB
/
Program.cs
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading;
using System.Windows.Forms;
using System.Media;
namespace SnakeGame
{
class Program
{
static void Main(string[] args)
{
string name;
while (true)
{
Console.Write("Type your name: ");
name = Console.ReadLine();
if (name.Length < 3)
{
Console.Clear();
Console.WriteLine("Name will be longer than 3 symbols.");
continue;
}
else
{
Console.Clear();
break;
}
}
bool soundSwitch;
while (true)
{
Console.Write("Do you want to turn on sounds? (Y/N): ");
ConsoleKeyInfo answerkey = Console.ReadKey();
if (answerkey.Key == ConsoleKey.Y)
{
Console.Clear();
soundSwitch = true;
break;
}
else if (answerkey.Key == ConsoleKey.N)
{
Console.Clear();
soundSwitch = false;
break;
}
else
{
Console.WriteLine("\nPress \'Y\' or \'N\' key.");
continue;
}
}
Score score = new Score(9);
Level level = new Level(1);
Params settings = new Params();
Sounds sound = new Sounds(settings.GetResourceFolder());
Sounds pointsound = new Sounds(settings.GetResourceFolder());
if (soundSwitch == true)
{
sound.Play(level.level);
}
Console.SetWindowSize(80, 26);
Walls walls = new Walls(80, 25);
walls.Draw();
Point p = new Point(4, 5, '*');
Snake snake = new Snake(p, 4, Direction.RIGHT);
Console.ForegroundColor = ConsoleColor.Red;
snake.Draw();
Console.ForegroundColor = ConsoleColor.White;
FoodCreator foodCreator = new FoodCreator(80, 25, '$');
Point food = foodCreator.CreateFood();
Console.ForegroundColor = ConsoleColor.Yellow;
food.Draw();
Console.ForegroundColor = ConsoleColor.White;
while (true)
{
if (walls.IsHit(snake) || snake.IsHitTail())
{
break;
}
if (snake.Eat(food, score, level, sound, soundSwitch))
{
if (soundSwitch == true)
{
pointsound.Play("point");
}
food = foodCreator.CreateFood();
Console.ForegroundColor = ConsoleColor.Yellow;
food.Draw();
Console.ForegroundColor = ConsoleColor.White;
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
snake.Move();
Console.ForegroundColor = ConsoleColor.Yellow;
}
if (level.level == 1)
Thread.Sleep(100);
else if (level.level == 2)
Thread.Sleep(75);
else if (level.level == 3)
Thread.Sleep(50);
else
Thread.Sleep(40);
if (Console.KeyAvailable)
{
ConsoleKeyInfo key = Console.ReadKey();
snake.HandleKey(key.Key);
}
}
Messages gameover = new Messages();
gameover.WriteGameOver(name, score.score, level.level);
if (soundSwitch == true)
{
sound.Stop(level.level);
pointsound.Play("lose");
}
ConsoleKeyInfo _key = Console.ReadKey();
if (_key.Key == ConsoleKey.Enter)
Application.Restart();
}
}
}