Пример #1
0
		public async Task MatchMakeGame( TokenViewModel Token )
		{
			try
			{
				var User = await this.VerifyToken( Token );
				if ( User != null )
				{
					//See if Any Games Are Available before making a new one
					var games = db.Games.Where( c => c.PrivateMatch == false && c.CanAddPlayer == true );
					Game game;
					if(games.Count() == 0)
					{
						//There are no available games.
						//Create New Game
						game = new Game();
						//Add Current User to Game
						game.AddPlayer( new Player( User.Profile ) );
						//Save Game
						db.Games.Add( game );
						await db.SaveChangesAsync();
						Clients.Caller.newGame(game);
					}
					else
					{
						//Add Current Player to oldest game.
						game = games.First();
						game.AddPlayer(new Player(User.Profile));
						//Save Changes
						await db.SaveChangesAsync();

						//Get a list of all connections for the Game
						ICollection<String> connections = new Collection<String>();
						//For Every Player:
						foreach( var player in game.Players)
						{
							//For Every Connection:
							foreach( var connection in player.Value.Profile.User.Connections)
							{
								//Add to ID Connection List
								connections.Add(connection.Id.ToString());
							}
						}
						//Notify All clients about new Player Joining.
						Clients.Clients(connections as IList<String>).playerJoined(game);
					}
				}
				else
				{
					Clients.Caller.error( "Unauthorized Access." );
				}
			}
			catch ( Exception error )
			{
				Clients.Caller.error( "Exception Occurred: " + error.Message );
			}
		}
Пример #2
0
        public void ConstructorTest()
        {
            Game Game = new Game();
            var width = 5;
            var height = 5;
            var expectedBoxes = ( width )*( height );

            Assert.IsNotNull(Game);

            Assert.AreEqual( width, Game.width );
            Assert.AreEqual( height, Game.height );
            Assert.AreEqual( expectedBoxes, Game.Boxes.Count );
        }
Пример #3
0
        public void CustomConstructorTest()
        {
            var width = 10;
            var height = 5;
            var expectedBoxes = (width)*(height);
            Game Game = new Game( width, height );

            Assert.IsNotNull( Game );

            Assert.AreEqual( width, Game.width );
            Assert.AreEqual( height, Game.height );
            Assert.AreEqual( expectedBoxes, Game.Boxes.Count );

            var box = new Box( new Coordinate( 0, 0 ) );
            Assert.AreEqual(box, Game.Boxes.ElementAt( 0 ) );
        }
Пример #4
0
        public void PlayGame()
        {
            var width = 2;
            var height = 2;
            var expectedBoxes = ( width )*( height );

            Game Game = new Game( width, height );
            var player1 = new Player();
            var player2 = new Player();

            player1.Profile = new Profile();
            player1.Color = Color.Blue.ToArgb();
            player2.Profile = new Profile();
            player2.Color = Color.Red.ToArgb();

            Game.AddPlayer( player1 );
            Game.AddPlayer( player2 );

            Assert.AreEqual(2, Game.Players.Count);

            Assert.AreEqual( 12, Game.TotalTurns );
            Assert.AreEqual( true, Game.GameStartable );
            Assert.AreEqual( false, Game.GameStarted );
            Assert.AreEqual( false, Game.GameFinished );

            Game.AddTurn( new Turn( new Line( new Coordinate( 0, 0 ), new Coordinate( 1, 0 ) ), player1 ) );
            Game.AddTurn( new Turn( new Line( new Coordinate( 0, 0 ), new Coordinate( 0, 1 ) ), player2 ) );
            Game.AddTurn( new Turn( new Line( new Coordinate( 1, 0 ), new Coordinate( 1, 1 ) ), player1 ) );
            Game.AddTurn( new Turn( new Line( new Coordinate( 1, 1 ), new Coordinate( 0, 1 ) ), player2 ) );

            int boxCount = 0;
            foreach(var box in Game.Boxes)
            {
                if(box.Completed())
                {
                    boxCount++;
                }
            }

            Assert.AreEqual( 4, Game.Turns.Count );
            Assert.AreEqual( 1, boxCount );
            Assert.AreEqual( 1, Game.CurrentPlayer );
            Game.AddTurn( new Turn( new Line( new Coordinate( 1, 1 ), new Coordinate( 2, 1 ) ), player2 ) );
            Assert.AreEqual( 0, Game.CurrentPlayer );
        }
Пример #5
0
		public async Task CreateNewCustomGame( TokenViewModel Token, GameViewModel Game )
		{
			try
			{
				var User = await this.VerifyToken( Token );
				if ( User != null )
				{
					//Create New Game
					Game game = new Game(Game);
					//Add Current User to Game
					game.AddPlayer(new Player(User.Profile));
					//Save Game
					db.Games.Add(game);
					await db.SaveChangesAsync();
					//Send Game back to client.
					Clients.Caller.newGame(game);
				}
				else
				{
					Clients.Caller.error( "Unauthorized Access." );
				}
			}
			catch ( Exception error )
			{
				Clients.Caller.error( "Exception Occurred: " + error.Message );
			}
		}