Beispiel #1
0
        public void PaperBeatsRock()
        {
            //Arrange
            IPlayer       player1      = new PaperPlayer();
            IPlayer       player2      = new RockPlayer();
            IGameResolver gameResolver = new GameResolver();

            //Act
            int winner = gameResolver.GetWinner(player1, player2);

            //Assert
            Assert.AreEqual(1, winner);
        }
        public async Task DoThing()
        {
            var clientApiFactory = new CfbApiClientFactory();

            var driveResolver = new DriveResolver(clientApiFactory);
            var gameResolver  = new GameResolver(clientApiFactory);
            var teamResolver  = new TeamResolver(clientApiFactory);

            var ranker = new Ranker(driveResolver, gameResolver, teamResolver);

            var rank = await ranker.Rank();

            Assert.True(rank.Length > 100);
        }
        public ActionResult <String> Post(PostRequestData post)
        {
            GameResolver gameResolver = new GameResolver();
            Colors       color        = gameResolver.GetCurrentRule(post.Canvas);

            switch (color)
            {
            case (Colors.RED):
                return(gameResolver.GetWinner(post.Players));

            case (Colors.ORANGE):
                return(gameResolver.SameNumbers(post.Players));

            default:
                throw new ArgumentException();
            }
        }
        public async Task MakeStep(int rowIndex, int colIndex, int gameId)
        {
            try
            {
                Game game;
                var  context  = Context.Request.GetHttpContext().GetOwinContext().Get <GameContext>();
                var  userName = Context.User.Identity.Name;
                Debug.WriteLine($"{userName} made a step in [{rowIndex},{colIndex}].");
                var opponent = await AddStepToGame(rowIndex, colIndex, gameId, userName);

                var gameResolver = new GameResolver(context);
                var result       = await gameResolver.CheckGameState(gameId, userName);

                if (result)
                {
                    game = context.Games.Find(gameId);
                    game.WinnerUserName = userName;
                    game.GameEndingDate = DateTime.Now;
                    await context.SaveChangesAsync();
                }

                game = context.Games.Find(gameId);

                // plain method of determing
                //todo: remake it later
                var stepsNumber = game.GameSteps.Count;
                if (!result && stepsNumber == game.FieldSize * game.FieldSize)
                {
                    game.WinnerUserName = ConstantStrings.NobodyWon;
                    game.GameEndingDate = DateTime.Now;
                    await context.SaveChangesAsync();
                }
                Clients.Client(opponent.ConnectionId).userMadeStep(new { RowIndex = rowIndex, ColumnIndex = colIndex });
            }
            catch (Exception e)
            {
                Clients.Caller.handleException(new { MethodName = nameof(MakeStep), Exception = e.ToString() });
            }
        }
Beispiel #5
0
 public Server(int port) : base(port)
 {
     clientEndPoints = new HashSet <IPEndPoint> ();
     MessageMulticaster.Instance.AddListener(this);
     gameResolver = new GameResolver();
 }
        private void initResolver(bool autoStart = false)
        {
            if (core != null)
            {
                core.StateChanged -= onCoreStateChanged;
                core.Dispose();
                core = null;
            }
            joinName  = "Join";
            hostToken = string.Empty;
            joinToken = string.Empty;
            myBoard   = chessboard;
            switch (GameMode)
            {
            case GameMode.PvE:
                var type = getSelectedLevel(0);
                core     = GameResolver.BuildEVP(myBoard, type);
                joinName = getAIName(type);
                break;

            case GameMode.PvP:
                core = GameResolver.BuildPVP(myBoard);
                break;

            case GameMode.PvPOnline:
                if (isHost)
                {
                    core = GameResolver.BuildOnlineHost(myBoard, ip, port, inport);
                }
                else
                {
                    core = GameResolver.BuildOnline(myBoard, ip, port, inport);
                }
                break;
            }
            if (core != null)
            {
                hostToken = core.HostToken;
                joinToken = core.JoinToken;
                updateNames();
                core.StateChanged += onCoreStateChanged;
                if (GameMode == GameMode.PvPOnline)
                {
                    readyBtn.Visibility = Visibility.Visible;
                }
                else
                {
                    readyBtn.Visibility = Visibility.Collapsed;
                    core.Ready();
                }
                if (autoStart)
                {
                    core.SetFirst(FirstIndex == 0 ? hostToken : joinToken);
                    core.Start();
                }
                else
                {
                    showFirstOption();
                }
            }
        }
Beispiel #7
0
        public GameResolverTests()
        {
            this.clientFactory = new Mock <ICfbApiClientFactory>();

            this.resolver = new GameResolver(new CfbApiClientFactory());
        }