Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
using System; namespace FunctionsHW { internal class Program { static void Main(string[] args) { Console.CursorVisible = false; char[,] map = { { '╔', '═', '╦', '═', '═', '═', '═', '═', '═', '╗' }, { '║', ' ', '║', '*', '*', '*', '*', '*', '*', '║' }, { '║', '*', '║', '*', '║', '*', '╔', '═', '═', '╣' }, { '║', '*', '*', '*', '║', '*', '║', '*', '*', '║' }, { '║', '*', '║', '*', '║', '*', '║', '*', '╔', '╣' }, { '║', '*', '║', '*', '║', '*', '║', '*', '╚', '╣' }, { '║', '*', '║', '*', '║', '*', '║', '*', '*', '║' }, { '║', '*', '║', '*', '║', '*', '*', '*', '═', '╣' }, { '║', '*', '║', '*', '║', '*', '║', '*', '*', '║' }, { '╚', '═', '╩', '═', '╩', '═', '╩', '═', '═', '╝' } }; char player = '@'; char star = '*'; char road = ' '; int playerPositionX = 1; int playerPositionY = 1; int score = 0; ConsoleKeyInfo pressedKey; while (true) { Console.Clear(); Console.ForegroundColor = ConsoleColor.Blue; DrawMap(map); Console.ForegroundColor = ConsoleColor.Green; Console.SetCursorPosition(playerPositionX, playerPositionY); Console.Write(player); Console.ForegroundColor = ConsoleColor.Red; Console.SetCursorPosition(0, 11); Console.Write("Очки: " + score); pressedKey = Console.ReadKey(); int[] direction = GetDirection(pressedKey); int nextPlayerPositionX = playerPositionX + direction[0]; int nextPlayerPositionY = playerPositionY + direction[1]; char nextPosition = GetNextPositionChar(map, nextPlayerPositionX, nextPlayerPositionY); if (nextPosition == star) { CollectStar(nextPlayerPositionX, nextPlayerPositionY, road, ref score, ref map); Move(nextPlayerPositionX, nextPlayerPositionY, ref playerPositionX, ref playerPositionY); } if (nextPosition == road) { Move(nextPlayerPositionX, nextPlayerPositionY, ref playerPositionX, ref playerPositionY); } } } static void DrawMap(char[,] map) { for (int i = 0; i < map.GetLength(0); i++) { for (int j = 0; j < map.GetLength(1); j++) { Console.Write(map[i, j]); } Console.WriteLine(); } } static int[] GetDirection(ConsoleKeyInfo pressedKey) { ConsoleKeyInfo upArrow = new ConsoleKeyInfo('↑', ConsoleKey.UpArrow, false, false, false); ConsoleKeyInfo downArrow = new ConsoleKeyInfo('↓', ConsoleKey.DownArrow, false, false, false); ConsoleKeyInfo leftArrow = new ConsoleKeyInfo('←', ConsoleKey.LeftArrow, false, false, false); ConsoleKeyInfo rightArrow = new ConsoleKeyInfo('→', ConsoleKey.RightArrow, false, false, false); int[] direction = { 0, 0 }; if (pressedKey.Key == upArrow.Key) direction[1] = -1; else if (pressedKey.Key == downArrow.Key) direction[1] = 1; else if (pressedKey.Key == leftArrow.Key) direction[0] = -1; else if (pressedKey.Key == rightArrow.Key) direction[0] = 1; return direction; } static char GetNextPositionChar(char[,] map, int nextPositionX, int nextPositionY) { char nextPosition = map[nextPositionY, nextPositionX]; return nextPosition; } static void CollectStar(int positionX, int positionY, char road, ref int score, ref char[,] map) { score++; map[positionY, positionX] = road; } static void Move(int positionX, int positionY, ref int playerPositionX, ref int playerPositionY) { playerPositionX = positionX; playerPositionY = positionY; } } }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)