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 ConsoleApplication4
- {
- class Program
- {
- static string n;
- static int x = 1, y = 2, d=15;
- static int cookieX, cookieY, enemyX, enemyY, enemyX1, enemyY1, enemyX2, enemyY2, enemyX3, enemyY3, enemyX4, enemyY4;
- static string hero = "o", hero1, hero2;
- static string enemy, enemy1, enemy2, enemy3, enemy4;
- static Random rand = new Random();
- static void GenerateCookie()
- {
- cookieX = 5 + rand.Next(34);
- cookieY = 5 + rand.Next(14);
- return ;
- }
- static void GenerateEnemy()
- {
- enemyX = 5 + rand.Next(34);
- enemyY = 5 + rand.Next(14);
- enemyX1 = 5 + rand.Next(34);
- enemyY1 = 5 + rand.Next(14);
- enemyX2 = 5 + rand.Next(34);
- enemyY2 = 5 + rand.Next(14);
- enemyX3 = 5 + rand.Next(34);
- enemyY3 = 5 + rand.Next(14);
- enemyX4 = 5 + rand.Next(34);
- enemyY4 = 5 + rand.Next(14);
- return;
- }
- static void Main(string[] args)
- {
- StartScreen();
- GameScreen();
- Console.ReadKey();
- }
- static void StartScreen()
- {
- Console.WriteLine("Введите свое имя: ");
- n = Console.ReadLine();
- }
- static void GameScreen()
- {
- GenerateEnemy();
- Console.CursorVisible = false;
- bool isEnd = false;
- GenerateCookie();
- while (!isEnd)
- { // isEnd - переменная-признак конца игры
- DrawWorld();
- ReadInputs();
- }
- }
- static void DrawWorld()
- {
- Console.Clear();
- int i = 0, j = 0;
- Console.Clear();
- Console.Clear();
- Console.WriteLine($"Name: {n} | Score: {d}");
- for (i = 0; i < 20; i++)
- {
- for (j = 0; j < 40; j++)
- {
- if (i == 0 || i == 19)
- {
- Console.Write("-");
- }
- else if (j == 0 || j == 39)
- {
- Console.Write("|");
- }
- else Console.Write(" ");
- }
- Console.WriteLine();
- }
- Console.SetCursorPosition(cookieX, cookieY);
- Console.Write("P");
- Console.SetCursorPosition(x, y);
- Console.WriteLine(hero);
- Console.SetCursorPosition(x, y + 1);
- Console.WriteLine(hero1);
- Console.SetCursorPosition(x, y + 2);
- Console.WriteLine(hero2);
- Console.SetCursorPosition(enemyX, enemyY);
- Console.WriteLine(enemy);
- Console.SetCursorPosition(enemyX1, enemyY1);
- Console.WriteLine(enemy1);
- Console.SetCursorPosition(enemyX2, enemyY2);
- Console.WriteLine(enemy2);
- Console.SetCursorPosition(enemyX3, enemyY3);
- Console.WriteLine(enemy3);
- Console.SetCursorPosition(enemyX4, enemyY4);
- Console.WriteLine(enemy4);
- if (d >= 3 && d < 6)
- {
- hero = "0";
- enemy = "X";
- if (x == cookieX && y == cookieY)
- {
- GenerateCookie();
- d++;
- }
- } else if (d >= 6 && d < 9)
- {
- hero = "/\\";
- hero1 = "\\/";
- if (x <= cookieX && y <= cookieY && x + 2 > cookieX && y + 2 > cookieY)
- {
- GenerateCookie();
- d++;
- }
- enemy1 = "X";
- } else if (d >=9 && d < 12)
- {
- hero = "/-\\";
- hero1 = "\\-/";
- if (x <= cookieX && y <= cookieY && x + 3 > cookieX && y + 2 > cookieY)
- {
- GenerateCookie();
- d++;
- }
- enemy2 = "X";
- } else if (d >= 12 && d < 15)
- {
- hero = "/-\\";
- hero1 = "|*|";
- hero2 = "\\-/";
- if (x <= cookieX && y <= cookieY && x + 2 > cookieX && y + 2 > cookieY)
- {
- GenerateCookie();
- d++;
- }
- enemy3 = "X";
- } else if (d >=15 && d < 18)
- {
- hero = "/--\\";
- hero1 = "|**|";
- hero2 = "\\--/";
- if (x <= cookieX && y <= cookieY && x + 4 > cookieX && y + 3 > cookieY)
- {
- GenerateCookie();
- d++;
- }
- enemy4 = "X";
- } else if (d >= 18)
- {
- hero = "/---\\";
- hero1 = "|***|";
- hero2 = "\\---/";
- enemy = "X";
- if (x <= cookieX && y <= cookieY && x + 5 > cookieX && y + 3 > cookieY)
- {
- GenerateCookie();
- d++;
- }
- } else
- {
- if (x == cookieX && y == cookieY)
- {
- GenerateCookie();
- d++;
- }
- }
- }
- static void ReadInputs()
- {
- var key = Console.ReadKey();
- switch (key.Key)
- {
- case ConsoleKey.LeftArrow:
- if (x > 1) x--;
- else x = 38;
- break;
- case ConsoleKey.RightArrow:
- if (x < 38) x++;
- else x = 1;
- break;
- case ConsoleKey.UpArrow:
- if (y > 2) y--;
- else y = 19;
- break;
- case ConsoleKey.DownArrow:
- if (y < 19) y++;
- else y = 2;
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement