static bool IsTargetAcquired(Position player, Position target) { bool targetAcquired = false; if (player.X == target.X && player.Y == target.Y) { targetAcquired = true; SoundPlayer eatTarget = PlaySound("eattarget"); } return targetAcquired; }
static void DrawTarget(Position target) { Console.SetCursorPosition(target.Y, target.X); Console.ForegroundColor = ConsoleColor.Magenta; Console.Write((char)3); }
static bool CheckIfBotHitPlayer(List<Position> bots, Position player, int score) { bool gamerunning = true; for (int i = 0; i < bots.Count; i++) { if (bots[i].X == player.X && bots[i].Y == player.Y) { gamerunning = false; SoundPlayer gotCha = PlaySound("death"); return gamerunning; } } return gamerunning; }
static Position GenerateTarget(int[,] board) { Position target = new Position(); while (true) { target = new Position(randomIntGenerator.Next(5, matrixHeight - 5), randomIntGenerator.Next(4, matrixWidth - 4), 0); if (board[target.X, target.Y] == 0) { break; } } return target; }
static void DrawPlayer(Position player) { Console.SetCursorPosition(player.Y, player.X); Console.ForegroundColor = ConsoleColor.Red; Console.Write("" + (char)2); }
static Position[] GetDirections() { Position[] directions = new Position[] { new Position(0,1,0), //right new Position(0,-1,0), //left new Position(-1,0,0), //up new Position(1,0, 0) //down }; return directions; }
static List<Position> MoveBotsPosition(List<Position> bots, int[,] board) { int randomDirection = 0; int currCordinateX = 0; int currCordinateY = 0; int currDirection = 0; bool CorrectDirection = false; int nextPosX = 0; int nextPosY = 0; List<Position> CopyBots = new List<Position>(bots); bots.Clear(); for (int i = 0; i < botsCount; i++) { randomDirection = CopyBots[i].CurrentDirectionBot; nextPosX = CopyBots[i].X + directions[randomDirection].X; nextPosY = CopyBots[i].Y + directions[randomDirection].Y; currCordinateX = CopyBots[i].X; currCordinateY = CopyBots[i].Y; CorrectDirection = false; if (board[nextPosX, nextPosY] == 1) { CorrectDirection = false; while (CorrectDirection == false) { currDirection = randomIntGenerator.Next(0, 4); if (currDirection != randomDirection && board[currCordinateX + directions[currDirection].X, currCordinateY + directions[currDirection].Y] == 0) { CorrectDirection = true; CopyBots[i] = new Position(currCordinateX, currCordinateY, currDirection); } } } else { CorrectDirection = true; } } if (CorrectDirection) { for (int i = 0; i < botsCount; i++) { randomDirection = CopyBots[i].CurrentDirectionBot; bots.Add(new Position(CopyBots[i].X + directions[randomDirection].X, CopyBots[i].Y + directions[randomDirection].Y, randomDirection)); } } return bots; }
static Position MovePlayer(Position player, int[,] board) { int direction = 0; ConsoleKeyInfo userInput = Console.ReadKey(); if (userInput.Key == ConsoleKey.RightArrow) { direction = 0; } else if (userInput.Key == ConsoleKey.LeftArrow) { direction = 1; } else if (userInput.Key == ConsoleKey.UpArrow) { direction = 2; } else { direction = 3; } if (board[player.X + directions[direction].X, player.Y + directions[direction].Y] != 1) { player = new Position(player.X + directions[direction].X, player.Y + directions[direction].Y, 0); } return player; }
static Position InitializePlayer() { Position player = new Position(1, 1, 0); Console.SetCursorPosition(player.Y, player.X); Console.Write("" + (char)1); return player; }
static void ClearConsole(Position player, Position target, List<Position> bots) { Console.SetCursorPosition(player.Y, player.X); Console.Write(" "); Console.SetCursorPosition(50, 10); Console.Write(" "); Console.SetCursorPosition(target.Y, target.X); Console.Write(" "); Console.Clear(); }