public void Render(Player Cont) { //Info Coordinate up = new Coordinate(Xco, Yco); up.MoveUp(); Coordinate right = new Coordinate(Xco, Yco); right.MoveRight(); Coordinate down = new Coordinate(Xco, Yco); down.MoveDown(); Coordinate left = new Coordinate(Xco, Yco); left.MoveLeft(); Analytics.Cardinal(Cont, Pos); //Cursor if (CursorMode == Mode.free) { System.Console.ForegroundColor = ConsoleColor.Green; } else { System.Console.ForegroundColor = ConsoleColor.DarkGreen; } int x = (int)Pos.X; int y = (int)Pos.Y; x = x * 4; Console.SetCursorPosition(x, y + 2); Console.WriteLine("["); Console.SetCursorPosition(x + 2, y + 2); Console.WriteLine("] "); Console.ResetColor(); Console.SetCursorPosition(0, 13); }
public bool Move(Player ConPlayer, string input) { bool End = false; Coordinate CursorCoord = new Coordinate(Pos.X, Pos.Y); if ((input == "_") || ((input == " ") && (SpaceEnds == true))) { End = true; } else if (input == "W") { CursorCoord.MoveUp(); } else if (input == "A") { CursorCoord.MoveLeft(); } else if (input == "S") { CursorCoord.MoveDown(); } else if (input == "D") { CursorCoord.MoveRight(); } else if (input == " ") { //free if (mode == Mode.free) { //can only be done on a friendly Unit if (Land(CursorCoord, ConPlayer) == true) { mode = Mode.locked; } } //locked else if (mode == Mode.locked) { //can be done anytime mode = Mode.free; } } else if (input == "Q") { //buy barracks End = GameMaster.Instance.BuyBarracks(CursorCoord, ConPlayer, StishBoard.Instance); } else if (input == "E") { //buy unit End = GameMaster.Instance.BuyUnit(CursorCoord, ConPlayer, StishBoard.Instance); } if (GameMaster.Instance.OnBoard(CursorCoord, StishBoard.Instance) == true) { //free if (CursorMode == Mode.free) { Pos.X = CursorCoord.X; Pos.Y = CursorCoord.Y; } //locked if (CursorMode == Mode.locked) { //action is true if the cursor moved. this helps distinguish if the cursor should move after attacking. if (GameMaster.Instance.Action(Pos, CursorCoord, ConPlayer, StishBoard.Instance) == true) { Pos.X = CursorCoord.X; Pos.Y = CursorCoord.Y; SpaceEnds = true; } } } else { //move was not valid } Console.Clear(); StishBoard.Instance.Render(); Render(ConPlayer); return(End); //at the end of a turn the cursor is set to free so that the other player cannot control enemy units }
//this is purely cosmetic and helps describe the squares surrounding the cursor public static void Cardinal(Player Cont, Coordinate Pos) { Coordinate up = new Coordinate(Pos.X, Pos.Y); up.MoveUp(); Coordinate right = new Coordinate(Pos.X, Pos.Y); right.MoveRight(); Coordinate down = new Coordinate(Pos.X, Pos.Y); down.MoveDown(); Coordinate left = new Coordinate(Pos.X, Pos.Y); left.MoveLeft(); System.Console.ForegroundColor = Cont.GetRenderColour(); Console.SetCursorPosition(0, 12); Console.WriteLine("{0}'s Turn", Cont.GetPlayerNum); Console.ResetColor(); Console.SetCursorPosition(0, 0); List <string> CardinalString = new List <string>() { "Centre", "Up", "Right", "Down", "Left" }; List <Coordinate> Direction = new List <Coordinate>() { Pos, up, right, down, left }; for (int card = 0; card < 5; card++) { //Square Check = StishBoard.Instance.getSquare(Coord[card,0], Coord[card, 1]); Square Check = StishBoard.Instance.getSquare(Direction[card]); if (Check != null) { string CheckType; if (Check.Dep.DepType == null) { CheckType = "Nothing"; } else { CheckType = Check.Dep.DepType; } string CheckOwner; if (Check.Owner == null) { CheckOwner = "No One"; } else { CheckOwner = Check.Owner.GetPlayerNum; } Console.SetCursorPosition(4 * 6, (card + 3)); Console.WriteLine("{0} has: {1} Health, contains: {2} , belongs to: {3} , Movement Points: {4}", CardinalString[card], Check.Dep.Health.ToString(), CheckType, CheckOwner, Check.Dep.MP.ToString()); } } }
//not void! returns a list of Pathnodes public List <Coordinate> FindPath(Coordinate UnitPos, Coordinate To, BoardState board) { //lists as we dont want a limit that would be given by an array List <Coordinate> Path = new List <Coordinate>(); List <PathNode> ToCheck = new List <PathNode>(); List <PathNode> Checked = new List <PathNode>(); Coordinate Invest = new Coordinate(); Coordinate Twitch = new Coordinate(); uint MoveCost; uint MoveHealth = board.getSquare(UnitPos).Dep.Health; Player Cont = board.getSquare(UnitPos).Dep.OwnedBy; //MoveHealth must remain above 0 and MoveCost must remain below the maximum unit move distance //Start at To and end at UnitPos Invest.X = To.X; Invest.Y = To.Y; MoveCost = 0; //has to be cast here as the parent has to be given as null //adds this node to the list ToCheck CreatePathNode(ToCheck, null, MoveCost, MoveHealth, board, Invest); //Spreading from Invest while (ToCheck.Count != 0) { for (int dir = 0; dir < 4; dir++) { Invest = ToCheck[0].Position; MoveCost = ToCheck[0].Cost; MoveHealth = ToCheck[0].Health; Twitch.X = Invest.X; Twitch.Y = Invest.Y; if (dir == 0) { //up Twitch.MoveUp(); } else if (dir == 1) { //right Twitch.MoveRight(); } else if (dir == 2) { //down Twitch.MoveDown(); } else if (dir == 3) { //left Twitch.MoveLeft(); } if (board.getSquare(Twitch) != null) { //the 2d distance this way around makes a lot of sense and is nicely restricting if (UnitPos.Get2DDistance(Twitch) <= StishBoard.Instance.GameMP) { //tests to see if twitch is ontop of a friendly deployment but gives an exception for the destination which is the moving unit if (((Twitch.X == UnitPos.X) && (Twitch.Y == UnitPos.Y)) || !(board.getSquare(Twitch).Owner == board.getSquare(UnitPos).Owner&& board.getSquare(Twitch).Dep.DepType != "Empty")) { Coordinate SolidPos = new Coordinate(Twitch); //make changes to Movecost and MoveHealth here //trained equals true if this node is suitable and lands at the destination List <Coordinate> Trained = TrainPath(board, UnitPos, SolidPos, MoveCost, MoveHealth, Cont, ToCheck, Checked, Path); if (Trained != null) { return(Trained); } } } } } Checked.Add(ToCheck[0]); ToCheck.Remove(ToCheck[0]); } //there is no connection return(null); }