System.Collections.Generic.IEnumerable.Contains(Tile)

Here are the examples of the csharp api System.Collections.Generic.IEnumerable.Contains(Tile) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1 Examples 7

19 Source : Program.cs
with MIT License
from ZacharyPatten

void Play()
{
	IEnumerable<Tile> AdjacentTiles()
	{
		int x = PlayerLocation.X;
		int y = PlayerLocation.Y;
		if (x > 0) yield return Map[x - 1, y];
		if (x < Map.GetLength(0) - 1) yield return Map[x + 1, y];
		if (y > 0) yield return Map[x, y - 1];
		if (y < Map.GetLength(1) - 1) yield return Map[x, y + 1];
	}

	bool AdjacentToWumpus() => AdjacentTiles().Contains(Tile.Wumpus);
	bool AdjacentToPit() => AdjacentTiles().Contains(Tile.Pit);

	bool InvalidInput = false;
	string move = null;
Play:
	Clear();
	WriteLine("Wumpus World...");
	WriteLine();
	WriteLine("Play:");
	WriteLine();
	if (!(move is null))
	{
		WriteLine(move);
		WriteLine();
	}
	Write("You are inside the cave of the Wumpus.");
	if (AdjacentToWumpus())
	{
		Write(" You smell a foul odor from something nearby.");
	}
	if (AdjacentToPit())
	{
		Write(" You feel a breeze. Watch your step.");
	}
	WriteLine();
	WriteLine();
	WriteLine("up:    move up");
	WriteLine("down:  move down");
	WriteLine("left:  move left");
	WriteLine("right: move right");
	WriteLine("quit:  exit Wumpus World");
	WriteLine("info:  view info");
	WriteLine();
	if (InvalidInput)
	{
		WriteLine("Invalid Input. Try again...");
		InvalidInput = false;
	}
	Write(">");
	Direction movement;
	switch (ReadLine())
	{
		case "quit": Quit(); goto Play;
		case "info": Info(); goto Play;
		case "up": movement = Direction.Up; break;
		case "down": movement = Direction.Down; break;
		case "left": movement = Direction.Left; break;
		case "right": movement = Direction.Right; break;
		default: InvalidInput = true; goto Play;
	};
	bool insideMap = movement switch
	{
		Direction.Up => PlayerLocation.Y < Map.GetLength(1) - 1,
		Direction.Down => PlayerLocation.Y > 0,
		Direction.Left => PlayerLocation.X > 0,
		Direction.Right => PlayerLocation.X < Map.GetLength(0) - 1,
		_ => throw new Exception(),
	};