Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp8
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.CursorVisible = false;
- bool isPlaying = true;
- int HeroX, HeroY;
- int HeroDX = 0, HeroDY = 1;
- int collectBerries = 0;
- int ollBerries = 0;
- char[,] Map = {
- {'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#'},
- {'#','@','.','.','.','.','.','.','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','.','.','.','.','.','.','.','#'},
- {'#','.','#','.','.','.','.','.','#','.','.','.','.','.','.','.','.','#','.','.','.','.','.','.','.','.','#','.','.','.','.','.','#','.','#'},
- {'#','.','#','.','.','.','.','.','#','.','.','.','.','.','.','.','.','#','.','.','.','.','.','.','.','.','#','.','.','.','.','.','#','.','#'},
- {'#','.','#','#','#','#','#','#','#','.','.','.','.','.','.','.','.','#','.','.','.','.','.','.','.','.','#','#','#','#','#','#','#','.','#'},
- {'#','.','.','.','.','.','.','.','#','.','#','#','#','#','#','#','.','#','.','#','#','#','#','#','#','.','#','.','.','.','.','.','.','.','#'},
- {'#','.','.','.','.','.','.','.','#','.','#','.','.','.','.','.','.','#','.','.','.','.','.','.','#','.','#','.','.','.','.','.','.','.','#'},
- {'#','.','.','.','.','.','.','.','#','.','#','.','.','.','.','.','.','#','.','.','.','.','.','.','#','.','#','.','.','.','.','.','.','.','#'},
- {'#','.','#','#','#','#','#','#','#','.','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','.','#','#','#','#','#','#','#','.','#'},
- {'#','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','#','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','#'},
- {'#','.','#','.','.','.','.','.','.','.','.','.','.','.','.','.','.','#','.','.','.','.','.','.','.','.','.','.','.','.','.','.','#','.','#'},
- {'#','.','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','.','#'},
- {'#','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','#'},
- {'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#'} };
- DrawMap(Map, out HeroX, out HeroY, ref ollBerries);
- while (isPlaying)
- {
- Console.SetCursorPosition(0, 15);
- Console.WriteLine($"Собрано: {collectBerries}/{ollBerries}");
- if (Console.KeyAvailable)
- {
- ConsoleKeyInfo key = Console.ReadKey(true);
- changeDirection(key, ref HeroDX, ref HeroDY);
- }
- if (Map[HeroX + HeroDX, HeroY + HeroDY] != '#')
- {
- Move(ref HeroX, ref HeroY, HeroDX, HeroDY);
- if (Map[HeroX, HeroY] == '.')
- {
- collectBerries++;
- Map[HeroX, HeroY] = ' ';
- }
- }
- if (collectBerries == ollBerries)
- {
- Console.SetCursorPosition(0, 16);
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine("ВЫ ПОБЕДИЛИ!!!");
- isPlaying = false;
- }
- System.Threading.Thread.Sleep(250);
- }
- }
- static void DrawMap(char[,] map, out int HeroX, out int HeroY, ref int ollBerries)
- {
- HeroX = 0;
- HeroY = 0;
- for (int i = 0; i < map.GetLength(0); i++)
- {
- for (int j = 0; j < map.GetLength(1); j++)
- {
- Console.Write(map[i, j]);
- if (map[i, j] == '@')
- {
- HeroX = i;
- HeroY = j;
- }
- else if (map[i,j] == '.')
- {
- ollBerries++;
- }
- }
- Console.WriteLine();
- }
- }
- static void Move (ref int x, ref int y, int DX, int DY)
- {
- Console.SetCursorPosition(y, x);
- Console.Write(' ');
- x += DX;
- y += DY;
- Console.SetCursorPosition(y, x);
- Console.Write('@');
- }
- static void changeDirection (ConsoleKeyInfo key, ref int DX, ref int DY)
- {
- switch (key.Key)
- {
- case ConsoleKey.UpArrow:
- DX = -1; DY = 0;
- break;
- case ConsoleKey.LeftArrow:
- DX = 0; DY = -1;
- break;
- case ConsoleKey.DownArrow:
- DX = 1; DY = 0;
- break;
- case ConsoleKey.RightArrow:
- DX = 0; DY = 1;
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement