Keep enemy position in console game

  • Thread starter Thread starter DiabolicalGremlin
  • Start date Start date
D

DiabolicalGremlin

Guest
I'm developing a small console game, similar to "a dark room". and I have just created a way to spawn enemies, problem is I cant figure out how to make them stay.

Here's the code

using System;

namespace Field_of_Beasts
{
class MainClass
{
public static Random rndm = new Random();

public static float posY = vertical;
public static float posX = horizontal;

public static int vertical = 10;
public static int horizontal = 20;

public static void Main(string[] args)
{
Console.CursorVisible = false;
Map();
EnemySpawn();
Move();
}





public static void Map()
{


Console.WriteLine(",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,");
Console.WriteLine(",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,");
Console.WriteLine(",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,");
Console.WriteLine(",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,");
Console.WriteLine(",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,");
Console.WriteLine(",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,");
Console.WriteLine(",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,");
Console.WriteLine(",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,");
Console.WriteLine(",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,");
Console.WriteLine(",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,");
Console.WriteLine(",,,,,,,,,,,,,,,,,,,,M,,,,,,,,,,,,,,,,,,,,");
Console.WriteLine(",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,");
Console.WriteLine(",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,");
Console.WriteLine(",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,");
Console.WriteLine(",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,");
Console.WriteLine(",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,");
Console.WriteLine(",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,");
Console.WriteLine(",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,");
Console.WriteLine(",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,");
Console.WriteLine(",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,");
}

// Method For Movement
public static void Move()
{
bool running = true;


ConsoleKeyInfo keyInfo;
do
{
keyInfo = Console.ReadKey(true);
Console.Clear();
Map();

switch (keyInfo.Key)
{
//Movement to the right
case ConsoleKey.RightArrow:
horizontal++;
Console.SetCursorPosition(horizontal, vertical);
if (horizontal >= 39)
{
horizontal = 39;
}

posX = horizontal / 40;
Console.Write("@");
break;

//Movement to the left
case ConsoleKey.LeftArrow:
horizontal--;
Console.SetCursorPosition(horizontal, vertical);
if (horizontal <= 1)
{
horizontal = 1;
}

posX = horizontal / 40;
Console.Write("@");
break;

//Movement up
case ConsoleKey.UpArrow:
vertical--;
Console.SetCursorPosition(horizontal, vertical);
if (vertical <= 1)
{
vertical = 1;
}

posY = vertical / 20;
Console.Write("@");
break;

//Movement down
case ConsoleKey.DownArrow:
vertical++;
Console.SetCursorPosition(horizontal, vertical);
if (vertical >= 19)
{
vertical--;
}

posY = vertical / 20;
Console.Write("@");
break;
}
EnemySpawn();
} while (running == true);

}
public static void EnemySpawn()
{
int ePosX = rndm.Next(1, 40);
int ePosY = rndm.Next(1, 20);
int spawnChanse = rndm.Next(1, 5);

if (spawnChanse == 1)
{
Console.SetCursorPosition(ePosX, ePosY);
Console.WriteLine("#");

}
}
}
}



I didn't know what code would be important to the answer, so i posted it all. Thanks on beforehand

Continue reading...
 
Back
Top