/// <summary> /// Finds number of players for each team at a coordinate at rolls to find a winner /// /// </summary> public void RollForEngagement(Coordinate coordinate, Match match) { List<Player> homePlayersAtCoordinate = new List<Player>(); List<Player> awayPlayerAtCoordinate = new List<Player>(); foreach (Player somePlayer in match.GetPlayersAtCoordinate(coordinate, match)) { if (somePlayer.Team.TeamName == match.HomeTeam.TeamName) { homePlayersAtCoordinate.Add(somePlayer); } else { awayPlayerAtCoordinate.Add(somePlayer); } } Console.WriteLine(match.HomeTeam.TeamName + " has " + homePlayersAtCoordinate.Count + " players at coordinate 2,2"); Console.WriteLine(match.AwayTeam.TeamName + " has " + awayPlayerAtCoordinate.Count + " players at coordinate 2,2"); //roll for greek players at coordinate Random rnd = new Random(); int rollHome = rnd.Next(1, 7); int rollAway = rnd.Next(1, 7); Console.WriteLine(match.HomeTeam.TeamName + " rolls " + rollHome); Console.WriteLine(match.AwayTeam.TeamName + " rolls " + rollAway); //+2 til roll pr. player at coordinate. int modifiedGreekRoll = rollHome + homePlayersAtCoordinate.Count * 2; int modifiedOlsenRoll = rollAway + awayPlayerAtCoordinate.Count * 2; Console.WriteLine("greek modified roll is" + modifiedGreekRoll); Console.WriteLine("Olsen modified roll is" + modifiedOlsenRoll); ResultOfEngagement engagementResult = FindWinner(match, modifiedGreekRoll, modifiedOlsenRoll); var downedPlayer = new Player(); //add effect (down player, equals half a player next round and can't move. if (engagementResult != ResultOfEngagement.Tie) { downedPlayer = EffectOfEngangement(engagementResult, homePlayersAtCoordinate, awayPlayerAtCoordinate); } else { Console.WriteLine("Its was a tie, no player downed"); } if (downedPlayer != null) { if (match.MatchBall.PlayerWithBall == downedPlayer) { //give player to another player at that coordinate } Console.WriteLine(downedPlayer.Name + " " + downedPlayer.State); } Console.WriteLine(engagementResult.ToString()); }
public void ExecuteMoveOrderTest(Player.Orders order, int end_x, int end_y) { //Arrange Team firsteTeam = new Team() { TeamName = "The greeks" }; Team secondTeam = new Team() { TeamName = "Olsen banden" }; Match thisMatch = new Match() { HomeTeam = firsteTeam, AwayTeam = secondTeam }; Player alfred = new Player() { Name = "Alfred", Position = new Coordinate(1, 1), PlayerOrder = order, Team = firsteTeam }; firsteTeam.PlayersOnTeam.Add(alfred); firsteTeam.PlayersOnTeam.Add(new Player() { ShirtNumber = 1, Name = "Alpha", Position = new Coordinate(2, 1), Team = firsteTeam }); firsteTeam.PlayersOnTeam.Add(new Player() { ShirtNumber = 2, Name = "Beta", Position = new Coordinate(1, 1), Team = firsteTeam }); secondTeam.PlayersOnTeam.Add(new Player() { ShirtNumber = 10, Name = "Egon", Position = new Coordinate(1, 1), Team = secondTeam }); secondTeam.PlayersOnTeam.Add(new Player() { ShirtNumber = 11, Name = "Benny", Position = new Coordinate(1, 1), Team = secondTeam }); Player player = new Player(); //act player.ExecuteOrders(thisMatch); //Assert Assert.Equal(end_x, alfred.Position.X); Assert.Equal(end_y, alfred.Position.Y); }
public void compairePlayerPostionTest2Coordinate() { //Arrange Team firsteTeam = new Team() { TeamName = "The greeks" }; Team secondTeam = new Team() { TeamName = "Olsen banden" }; Match thisMatch = new Match() { HomeTeam = firsteTeam, AwayTeam = secondTeam }; firsteTeam.PlayersOnTeam.Add(new Player() { ShirtNumber = 1, Name = "Alpha", Position = new Coordinate(5, 5), Team = firsteTeam }); firsteTeam.PlayersOnTeam.Add(new Player() { ShirtNumber = 2, Name = "Beta", Position = new Coordinate(3, 2), Team = firsteTeam }); secondTeam.PlayersOnTeam.Add(new Player() { ShirtNumber = 10, Name = "Egon", Position = new Coordinate(5, 5), Team = secondTeam }); secondTeam.PlayersOnTeam.Add(new Player() { ShirtNumber = 11, Name = "Benny", Position = new Coordinate(3, 2), Team = secondTeam }); //Act List<Coordinate> result = thisMatch.CompairePlayersCoordinates(thisMatch); //Assert Assert.Equal(new Coordinate(5, 5), result[0]); Assert.Equal(new Coordinate(3, 2), result[1]); Assert.Equal(2, result.Count); }
public List<Player> PlayersInMatch(Match match) { //Add all HomeTeam players to Players In Match List List<Player> playersInMatch = match.HomeTeam.PlayersOnTeam.ToList(); //Add all away team players to list. playersInMatch.AddRange(match.AwayTeam.PlayersOnTeam); return playersInMatch; }
public List<Player> GetPlayersAtCoordinate(Coordinate coordinate, Match match) { List<Player> playersAtCoordinate = new List<Player> { }; //Check all players coordinate foreach (Player somePlayer in match.PlayersInMatch(match)) { if (somePlayer.Position.X == coordinate.X) if (somePlayer.Position.Y == coordinate.Y) { playersAtCoordinate.Add(somePlayer); } } return playersAtCoordinate; }
static void Main(string[] args) { Match newMatch = new Match(); Match thisMatch = newMatch.SetupMatch(); Board gameBoard = new Board(); Player players = new Player(); var homeTeamHand = thisMatch.HomeTeam.Hand(); var awayTeamHand = thisMatch.AwayTeam.Hand(); gameBoard.DrawBoard(thisMatch); //Turn loop for (int turn = 1; turn <= 9; turn++) { Console.WriteLine(); Console.WriteLine("Start of turn {0}", turn); //Assign orders to all players in the Home match players.GiveOrders(thisMatch.HomeTeam, homeTeamHand); //Assign orders to all players in the away team players.GiveOrders(thisMatch.AwayTeam, awayTeamHand); //Execute Orders players.ExecuteOrders(thisMatch); //Find encounters - doesn't seem to work List<Coordinate> engagements = thisMatch.CompairePlayersCoordinates(thisMatch); Rolls roll = new Rolls(); //Roll for all engagements foreach (Coordinate coordinate in engagements) { Console.WriteLine("Engagement at {0},{1}", coordinate.X, coordinate.Y); roll.RollForEngagement(coordinate, thisMatch); } Console.WriteLine("!-----New Turn------!"); gameBoard.DrawBoard(thisMatch); } }
public ResultOfEngagement FindWinner(Match match, int homeTeamRoll, int awayTeamRoll) { if (homeTeamRoll > awayTeamRoll) { Console.WriteLine(match.HomeTeam.TeamName + " is the winner"); return ResultOfEngagement.HomeTeam; } else if (homeTeamRoll < awayTeamRoll) { Console.WriteLine(match.AwayTeam.TeamName + " is the winner"); return ResultOfEngagement.AwayTeam; } else { Console.WriteLine("its a tie"); return ResultOfEngagement.Tie; } }
//GetPlayers on homeTeam //Add position to a list of coordinates that has players from the home team //GetPlayers on AwayTeam //Add positon to a list of coordinates that has players from away team. //Compaire the 2 lists to find coordinates with conflicts public List<Coordinate> CompairePlayersCoordinates(Match match) { List<Coordinate> result = new List<Coordinate>(); List<Coordinate> awayTeamCoordinates = new List<Coordinate>(); List<Coordinate> homeTeamCoordinates = match.HomeTeam.PlayersOnTeam.Select(player => player.Position).ToList(); IEnumerable<Coordinate> homeTeamCoordinatesNoDublicates = homeTeamCoordinates.DistinctBy(x => x.X).DistinctBy(y => y.Y); foreach(Player player in match.AwayTeam.PlayersOnTeam) { awayTeamCoordinates.Add(player.Position); } //Compaire list result.AddRange(homeTeamCoordinatesNoDublicates.Where(coordinate => awayTeamCoordinates.Contains(coordinate))); //Remove dublicates return result; }
public Match SetupMatch() { Team homeTeam = new Team() { TeamName = "The greeks" }; Team awayTeam = new Team() { TeamName = "Olsen banden" }; Ball ball = new Ball() {}; Match thisMatch = new Match() { HomeTeam = homeTeam, AwayTeam = awayTeam, MatchBall = ball }; homeTeam.PlayersOnTeam.Add(new Player() { ShirtNumber = 1, Name = "Alpha", Position = new Coordinate(1, 1), Team = homeTeam }); homeTeam.PlayersOnTeam.Add(new Player() { ShirtNumber = 2, Name = "Beta", Position = new Coordinate(1, 3), Team = homeTeam }); homeTeam.PlayersOnTeam.Add(new Player() {ShirtNumber = 3, Name = "Gamma", Position = new Coordinate(1,3), Team = homeTeam}); awayTeam.PlayersOnTeam.Add(new Player() { ShirtNumber = 10, Name = "Egon", Position = new Coordinate(1, 5), Team = awayTeam }); awayTeam.PlayersOnTeam.Add(new Player() { ShirtNumber = 11, Name = "Benny", Position = new Coordinate(1, 5), Team = awayTeam }); awayTeam.PlayersOnTeam.Add(new Player() {ShirtNumber = 13, Name = "Kjeld", Position = new Coordinate(1,3), Team = awayTeam}); Console.WriteLine("--PRESENTING THE HOME TEAM: {0}", homeTeam.TeamName); foreach (Player player in homeTeam.PlayersOnTeam) { Console.WriteLine("For {0} first player is #{1} {2}", homeTeam.TeamName, player.ShirtNumber, player.Name); } Console.WriteLine("--PRESENTING THE AWAY TEAM: {0}", awayTeam.TeamName); foreach(Player player in awayTeam.PlayersOnTeam) { Console.WriteLine("For {0} first player is #{1} {2}", awayTeam.TeamName, player.ShirtNumber, player.Name); } thisMatch.MatchBall.PlayerWithBall = homeTeam.PlayersOnTeam[0]; Console.WriteLine("{0} startes with the ball", homeTeam.PlayersOnTeam[0]); return thisMatch; }
public void rollForEngagementTest() { //Arrange Team firsteTeam = new Team() { TeamName = "The greeks" }; Team secondTeam = new Team() { TeamName = "Olsen banden" }; Ball ball = new Ball(); Match thisMatch = new Match() { HomeTeam = firsteTeam, AwayTeam = secondTeam, MatchBall = ball }; firsteTeam.PlayersOnTeam.Add(new Player() { ShirtNumber = 1, Name = "Alpha", Position = new Coordinate(2, 1), Team = firsteTeam }); firsteTeam.PlayersOnTeam.Add(new Player() { ShirtNumber = 2, Name = "Beta", Position = new Coordinate(1, 1), Team = firsteTeam }); secondTeam.PlayersOnTeam.Add(new Player() { ShirtNumber = 10, Name = "Egon", Position = new Coordinate(1, 1), Team = secondTeam }); secondTeam.PlayersOnTeam.Add(new Player() { ShirtNumber = 11, Name = "Benny", Position = new Coordinate(1, 1), Team = secondTeam }); //Act Rolls roll = new Rolls(); roll.RollForEngagement(new Coordinate(1, 1), thisMatch); //Assert }
public void GetPlayersAtCoordinateTest() { //Arrange Team firsteTeam = new Team() { TeamName = "The greeks" }; Team secondTeam = new Team() { TeamName = "Olsen banden" }; Match thisMatch = new Match() { HomeTeam = firsteTeam, AwayTeam = secondTeam }; firsteTeam.PlayersOnTeam.Add(new Player() { ShirtNumber = 1, Name = "Alpha", Position = new Coordinate(2, 1), Team = firsteTeam }); firsteTeam.PlayersOnTeam.Add(new Player() { ShirtNumber = 2, Name = "Beta", Position = new Coordinate(1, 1), Team = firsteTeam }); secondTeam.PlayersOnTeam.Add(new Player() { ShirtNumber = 10, Name = "Egon", Position = new Coordinate(1, 1), Team = secondTeam }); secondTeam.PlayersOnTeam.Add(new Player() { ShirtNumber = 11, Name = "Benny", Position = new Coordinate(1, 1), Team = secondTeam }); //Act var playersToFind = thisMatch.GetPlayersAtCoordinate(new Coordinate(1, 1), thisMatch); //Assert Assert.NotEmpty(playersToFind); Assert.Equal(3, playersToFind.Count); Assert.Equal("Beta", playersToFind[0].Name); Assert.Equal("The greeks", playersToFind[0].Team.TeamName); Assert.Equal("Egon", playersToFind[1].Name); Assert.Equal("Olsen banden", playersToFind[1].Team.TeamName); Assert.Equal("Benny", playersToFind[2].Name); Assert.Equal("Olsen banden", playersToFind[2].Team.TeamName); }
public void findWinnerTest(int a, int b, Rolls.ResultOfEngagement expectedResult) { Rolls roll = new Rolls(); Match match = new Match { HomeTeam = new Team() { TeamName = "The greeks" }, AwayTeam = new Team() { TeamName = "Olsen banden" } }; //ACT var result = roll.FindWinner(match, a, b); //ASSERT Assert.Equal(expectedResult, result); }
public void ExecuteOrders(Match match) { foreach (Player player in match.PlayersInMatch(match)) { if (player.PlayerOrder == Orders.MoveUp) { ExecuteMoveUp(player); } if (player.PlayerOrder == Orders.MoveDown) { ExecuteMoveDown(player); } if (player.PlayerOrder == Orders.MoveLeft) { executeMoveLeft(player); } if (player.PlayerOrder == Orders.MoveRigth) { executeMoveRigth(player); } if (player.PlayerOrder == Orders.Protect) { executeProtection(player); } if (player.PlayerOrder == Orders.DobbelMove) { ExecuteDobbleMove(player); } } }