Пример #1
0
        public void TestChangeMeeplePositive()
        {
            GameTable       gameTable  = _hub.GetGeneratedGameTable(TableId);
            PlayerFieldArea greenArea  = gameTable.PlayerFieldAreas.Find(area => area.ColorCode == ColorCode.Green);
            PlayerFieldArea blueArea   = gameTable.PlayerFieldAreas.Find(area => area.ColorCode == ColorCode.Blue);
            StandardField   startField = greenArea.Fields[10] as StandardField;
            StandardField   endField   = greenArea.Fields[14] as StandardField;
            Meeple          meeple1    = greenArea.Meeples[0];
            Meeple          meeple2    = blueArea.Meeples[0];

            startField.CurrentMeeple = meeple1;
            endField.CurrentMeeple   = meeple2;
            MeepleMove meepleMove = new MeepleMove()
            {
                Meeple          = meeple1,
                MoveDestination = endField
            };
            CardMove cardMove = new CardMove()
            {
                Card = _cardJoker,
                SelectedAttribute = CardAttributeChangePlace
            };

            Assert.AreEqual(true, Validation.ValidateMove(meepleMove, cardMove));
        }
Пример #2
0
        public async override Task OnDisconnectedAsync(Exception exception)
        {
            var userMetadata = this.GetUserMetadata();

            Log.Logger.LogError($"The client {JsonConvert.SerializeObject(userMetadata)} disconnected!");

            if (userMetadata == null)
            {
                // Nothing to do here
                return;
            }

            //await Groups.RemoveFromGroupAsync(Context.ConnectionId, userMetadata.GameId);
            GameTableEntity game = GameTable.GetGameObject(userMetadata.GameId);

            if (game == null)
            {
                // Nothing to do here
                return;
            }

            // Notify everyone user left
            await GameTable.RemoveUserFromGame(userMetadata.UserId, game);

            await Clients.Group(userMetadata.GameId).SendAsync("GameMetadataUpdate", JsonConvert.SerializeObject(game));
        }
Пример #3
0
        public async Task StartGame()
        {
            var userMetadata = this.GetUserMetadata();

            if (userMetadata == null)
            {
                throw new Exception("Game metadata is null");
            }

            GameTableEntity game = GameTable.GetGameObject(userMetadata.GameId);

            if (game == null)
            {
                throw new Exception("Game is null!");
            }

            if (userMetadata.UserId != game.LeaderUserId)
            {
                throw new Exception("Only leader can end!");
            }

            await GameTable.StartGame(game);

            await Clients.Group(userMetadata.GameId).SendAsync("GameMetadataUpdate", JsonConvert.SerializeObject(game));

            await Clients.Group(userMetadata.GameId).SendAsync("GameStarted");
        }
Пример #4
0
        public async Task CreateOrJoinGame(string gameId, string userId, string userName)
        {
            if (string.IsNullOrEmpty(gameId) || string.IsNullOrEmpty(userId))
            {
                throw new Exception("GroupId or user is empty");
            }

            Log.Logger.LogInformation($"User {userId} requesting to join game {gameId}");

            GameTableEntity game = GameTable.GetGameObject(gameId);

            if (game == null)
            {
                // Join game as admin
                game = await GameTable.CreateGame(gameId, userId, userName);
            }
            else
            {
                // If game has ended or started, there's no join (spectator mode)
                if (!game.GameEnded && !game.GameStarted)
                {
                    await GameTable.AddUserToGame(userId, userName, game);
                }
            }

            this.SetGameMetadata(userId, gameId);

            // Add to group and update game metadata for everyone and send notification
            await Groups.AddToGroupAsync(Context.ConnectionId, gameId);

            await Clients.Group(gameId).SendAsync("GameMetadataUpdate", JsonConvert.SerializeObject(game));

            await Clients.Group(gameId).SendAsync("PlayerJoined", userId);
        }
Пример #5
0
        public void TestChangeMeepleNegativeStartField()
        {
            GameTable       gameTable  = _hub.GetGeneratedGameTable(TableId);
            PlayerFieldArea greenArea  = gameTable.PlayerFieldAreas.Find(area => area.ColorCode == ColorCode.Green);
            PlayerFieldArea blueArea   = gameTable.PlayerFieldAreas.Find(area => area.ColorCode == ColorCode.Blue);
            StandardField   startField = greenArea.Fields[10] as StandardField;
            StartField      endField   = greenArea.Fields.Find(field => field.FieldType.Contains("StartField")) as StartField;
            Meeple          meeple1    = greenArea.Meeples[0];
            Meeple          meeple2    = blueArea.Meeples[0];

            meeple2.IsStartFieldBlocked = true;
            startField.CurrentMeeple    = meeple1;
            endField.CurrentMeeple      = meeple2;
            MeepleMove meepleMove = new MeepleMove()
            {
                Meeple          = meeple1,
                MoveDestination = endField
            };
            CardMove cardMove = new CardMove()
            {
                Card = _cardChange,
                SelectedAttribute = CardAttributeChangePlace
            };

            Assert.AreEqual(false, Validation.ValidateMove(meepleMove, cardMove));
        }
Пример #6
0
        private bool GameOver(Label label)
        {
            if (remainingCells.Count == 0)
            {
                return(true);
            }
            var cell = GameTable.GetCellPosition(label);

            ResetLabel.Text = String.Format("{0}, {1}\n{2}", cell.Row % 2, cell.Column % 2, IsCorner(cell.Row, cell.Column));

            // Corner cell case.
            if (IsCorner(cell.Row, cell.Column))
            {
                return(CornerCase(cell));
            }
            // Edge non-corner cell case.
            else if (IsEdge(cell.Row, cell.Column))
            {
                return(EdgeCase(cell));
            }
            // Centre case.
            else
            {
                CenterCase();
            }

            return(false);
        }
Пример #7
0
 public void Remove(GameTable deleteGameTable)
 {
     lock (_gameTables)
     {
         _gameTables.Remove(deleteGameTable);
     }
 }
Пример #8
0
        public void DisplayGameTable()
        {
            Console.Write("|   |");
            for (int ord = 0; ord < Ordonnee; ord++)
            {
                Console.Write(" " + ord + "|");
            }
            Console.WriteLine();

            for (int j = 0; j < Ordonnee; j++)
            {
                Console.Write("| " + j + " |");
                for (int i = 0; i < Abscisse; i++)
                {
                    Case currentCase = GameTable.First(myCase => myCase.X == i && myCase.Y == j);

                    if (currentCase.isAlive)
                    {
                        Console.Write(" * ");
                    }
                    else
                    {
                        Console.Write(" . ");
                    }
                }
                Console.WriteLine();
            }
            Console.WriteLine("_____________________________");
            Console.WriteLine("Generation : " + GenerationId);
        }
Пример #9
0
        public static MoveDestinationField GetFieldById(GameTable actualTable, int fieldId)
        {
            MoveDestinationField moveDestinationField = null;
            PlayerFieldArea      playerFieldArea      = actualTable.PlayerFieldAreas.Find(area => area.Fields.Find(field =>
            {
                if (field.Identifier != fieldId)
                {
                    return(false);
                }
                moveDestinationField = field;
                return(true);
            }) != null);

            if (moveDestinationField == null)
            {
                PlayerFieldArea playerFieldAreaKennel = actualTable.PlayerFieldAreas.Find(area => area.KennelFields.Find(field =>
                {
                    if (field.Identifier != fieldId)
                    {
                        return(false);
                    }
                    moveDestinationField = field;
                    return(true);
                }) != null);
            }
            return(moveDestinationField);
        }
Пример #10
0
        public List <HandCard> ProveCards(List <HandCard> actualHandCards, GameTable actualGameTable, User actualUser)
        {
            if (actualHandCards == null || actualGameTable == null || actualUser == null)
            {
                return(null);
            }
            PlayerFieldArea actualArea = actualGameTable.PlayerFieldAreas.Find(
                area => area.Participation.Participant.Identifier == actualUser.Identifier);
            List <Meeple> myMeeples = actualArea.Meeples;

            ProveCardsCount++;

            List <HandCard> validCards = (from card in actualHandCards
                                          let validAttribute = card.Attributes.Find(attribute =>
            {
                if (attribute.Attribute == CardFeature.LeaveKennel)
                {
                    return(ProveLeaveKennel(myMeeples));
                }
                return(attribute.Attribute == CardFeature.ChangePlace
                        ? ProveChangePlace(myMeeples, GameTableService.GetOtherMeeples(actualGameTable, myMeeples))
                        : ProveValueCard(myMeeples, (int)attribute.Attribute));
            })
                                                               where validAttribute != null
                                                               select card).ToList();

            SetCardValid(actualHandCards, false);
            SetCardValid(validCards, true);
            return(actualHandCards);
        }
Пример #11
0
        public void TestGetOpenMeeplesNoAvailable()
        {
            GameTable     actualGameTable = MakeInitialGameTable;
            List <Meeple> openMeeples     = GameTableService.GetOpenMeeples(actualGameTable.PlayerFieldAreas.Find(area => area.ColorCode == ColorCode.Blue).Meeples);

            Assert.AreEqual(0, openMeeples.Count);
        }
Пример #12
0
        public ActionResult JoinTable(string gameTableID)
        {
            GameTable foundGt   = null;
            bool      userFound = false;
            GameTableServiceAccess gameTableServiceAcces = new GameTableServiceAccess();

            if (gameTableID != null)
            {
                string userId  = User.Identity.GetUserId();
                int    tableId = Int32.Parse(gameTableID);
                foundGt = gameTableServiceAcces.GetGameTable(tableId);
                foreach (var user in foundGt.Users)
                {
                    if (user.Id == userId)
                    {
                        userFound = true;
                    }
                }
                if (foundGt.Users.Count == 4 && !userFound)
                {
                    return(View("JoinTable"));
                }
                try {
                    foundGt = gameTableServiceAcces.JoinGameTable(userId, tableId);
                } catch (Exception e) {
                    return(RedirectToAction("Error", "ErrorHandler", new { id = 3 }));
                }
            }
            List <GameTable> tables = new List <GameTable>()
            {
                foundGt
            };

            return(RedirectToAction("Lobby", new { tableId = foundGt.Id }));
        }
Пример #13
0
 private void FillGameTable(GameTable gameTable)
 {
     while (!gameTable.IsFull)
     {
         gameTable.Join(new Player(Guid.NewGuid(), "Test"));
     }
 }
Пример #14
0
        private static GameTable GenerateNewGameTable(int gameId, string gameName)
        {
            List <PlayerFieldArea> areas = new List <PlayerFieldArea>();

            int id = 0;

            const int       fieldId    = 0;
            PlayerFieldArea areaTop    = new PlayerFieldArea(++id, ColorCode.Blue, fieldId);
            PlayerFieldArea areaLeft   = new PlayerFieldArea(++id, ColorCode.Red, areaTop.FieldId);
            PlayerFieldArea areaBottom = new PlayerFieldArea(++id, ColorCode.Green, areaLeft.FieldId);
            PlayerFieldArea areaRight  = new PlayerFieldArea(++id, ColorCode.Yellow, areaBottom.FieldId);

            // Connection between PlayFieldAreas
            areaTop.Next        = areaLeft;
            areaTop.Previous    = areaRight;
            areaRight.Next      = areaTop;
            areaRight.Previous  = areaBottom;
            areaLeft.Next       = areaBottom;
            areaLeft.Previous   = areaTop;
            areaBottom.Next     = areaRight;
            areaBottom.Previous = areaLeft;

            areas.Add(areaTop);
            areas.Add(areaLeft);
            areas.Add(areaBottom);
            areas.Add(areaRight);

            GameTable table = new GameTable(areas, gameId, gameName);

            return(table);
        }
Пример #15
0
        public void JoinToGameTable(GameTable gameTable)
        {
            if (_stateService.AlreadyPlaying)
            {
                throw new Exception("Пользователь уже находится в игровой комнате");
            }

            _blockUIService.StartBlocking();
            _mainHubClient.JoinToGameTable(new JoinToGameTableParams()
            {
                GameTableId = gameTable.Id
            })
            .Then((response) =>
            {
                if (response.Succeeded)
                {
                    _dispatcher.Invoke(() =>
                    {
                        _blockUIService.StopBlocking();

                        _stateService.SetGameTable(gameTable);
                        Navigate <GameTableViewModel>();
                    });
                }
            });
        }
Пример #16
0
        public AutoPlayerLogic(GameTable gameTable, GameLogic gameLogic, DiceLogic diceLogic, bool white)
        {
            firstMove      = true;
            rand           = new Random();
            this.gameTable = gameTable;

            Timer = new DispatcherTimer
            {
                Interval = TimeSpan.FromSeconds(2)
            };
            //Timer.Tick += ComputerTurn;

            if (white)
            {
                MyCheckerColor = gameTable.White;
                firstMove      = true;
            }
            else
            {
                MyCheckerColor = gameTable.Black;
                firstMove      = false;
            }

            this.gameLogic = gameLogic;
            this.diceLogic = diceLogic;

            if (white)
            {
                BarColl = gameTable.WhiteBar;
            }
            else
            {
                BarColl = gameTable.BlackBar;
            }
        }
Пример #17
0
    private bool LoadTable(string tablename, Type type)
    {
        if (gameTable.ContainsKey(tablename) == true)
        {
            Debug.Log("Load table is error!!! Had a file! Name=" + tablename);
            return(false);
        }

        TextAsset o = Resources.Load("Configs/" + tablename) as TextAsset;

        if (o == null)
        {
            Debug.Log("Load table is error!!!Read File is error! File=" + tablename);
            return(false);
        }

        GameTable tab = GameTable.Clone(type);

        tab.name = o.name;

        ReadTable(o.bytes, ref tab);

        gameTable.Add(tab.name, tab);
        return(true);
    }
Пример #18
0
        public static void TableState(ICallback to, GameTable table)
        {
            var conns = GetUsers(to);
            if (conns == null) return;

            Hub.Clients.Clients(conns).TableState(table);
        }
Пример #19
0
        /// <summary>
        /// Játék betöltése.
        /// </summary>
        /// <param name="path">Elérési útvonal.</param>
        public async Task LoadGameAsync(String path)
        {
            if (_dataAccess == null)
            {
                throw new InvalidOperationException("No data access is provided.");
            }

            _table = await _dataAccess.LoadAsync(path);

            _gameStepCount = 0;

            switch (_gameDifficulty) // játékidő beállítása
            {
            case GameDifficulty.Easy:
                _gameTime = GameTimeEasy;
                break;

            case GameDifficulty.Medium:
                _gameTime = GameTimeMedium;
                break;

            case GameDifficulty.Hard:
                _gameTime = GameTimeHard;
                break;
            }
        }
Пример #20
0
    public GameTable GetTable(string strName)
    {
        GameTable tab = null;

        gameTable.TryGetValue(strName, out tab);
        return(tab);
    }
Пример #21
0
 public UIPlayer(GameTable gameTable, MonoPlayer player)
     : base(gameTable)
 {
     unityPlayer  = player;
     biddingPopup = GameObject.FindGameObjectWithTag("MENUS").transform.FindChild("BiddingPopup").GetComponent <BiddingPopup>();
     uiDeck       = GameObject.FindGameObjectWithTag("DECK").GetComponent <UIDeck>();
 }
Пример #22
0
 public void NewGame()
 {
     gameTable = new GameTable();
     gameTime  = 0;
     fuel      = 20;
     playerPos = gameTable.Size / 2;
 }
Пример #23
0
        public void TestGetNextPlayerNonExistentUser()
        {
            GameTable table = MakeInitialGameTable;
            string    user  = ParticipationService.GetNextPlayer(table, "user5");

            Assert.AreEqual(true, user == null);
        }
Пример #24
0
    public GameTable GetTable(string name)
    {
        GameTable table = null;

        mTableMap.TryGetValue(name, out table);
        return(table);
    }
Пример #25
0
        private void DoInit()
        {
            Env = new LuaEnv();
            ScriptLoader scriptLoader;

#if UNITY_EDITOR
            scriptLoader = new FileScriptLoader();
#else
#endif
            Env.AddLoader(scriptLoader.LoadScript);

#if DEBUG
            Global.Set("isDebug", true);
#endif
            Env.AddBuildin("rapidjson", XLua.LuaDLL.Lua.LoadRapidJson);
            Global.Set("isUsingRapidjson", true);

            Env.AddBuildin("pb", XLua.LuaDLL.Lua.LoadLuaProfobuf);

            OOPTable         = RequireAndGetLocalTable(LUA_OOP_PATH);
            usingFunc        = OOPTable.Get <Func <string, LuaTable> >("using");
            instanceFunc     = OOPTable.Get <Func <string, LuaTable> >("instance");
            instanceWithFunc = OOPTable.Get <LuaFunction>("instancewith");

            Require(LUA_INIT_PATH);
            GameTable        = Global.Get <LuaTable>(LUA_GLOBAL_NAME);
            updateAction     = GameTable.Get <Action <float, float> >(LuaUtility.UPDATE_FUNCTION_NAME);
            lateUpdateAction = GameTable.Get <Action>(LuaUtility.LATEUPDATE_FUNCTION_NAME);

            Action initAction = GameTable.Get <Action>(LuaUtility.INIT_FUNCTION_NAME);
            initAction?.Invoke();
        }
Пример #26
0
 public GameObject(GameTable gameTable, GameEndingCondition gameEndingCondition)
 {
     this.gameTable           = gameTable;
     this.gameEndingCondition = gameEndingCondition;
     this.playedRoundCount    = 0;
     ScoreBoard.ResetScores();
 }
Пример #27
0
        public static bool AddParticipation(GameTable table, string curUser)
        {
            if (table.IsFull())
            {
                return(false);
            }
            Participation newParticipation;

            if (table.Participations.Count % 2 == 1)
            {
                User actualUser = UserRepository.Instance.Get()
                                  .First(user => user.Value.Nickname == curUser).Value;
                newParticipation =
                    new Participation(actualUser)
                {
                    Partner = table.Participations.Last().Participant
                };
                table.Participations.Last().Partner = actualUser;
            }
            else
            {
                newParticipation = new Participation(UserRepository.Instance.Get().First(user => user.Value.Nickname == curUser).Value);
            }
            table.PlayerFieldAreas.Find(area => area.Identifier == table.Participations.Count + 1).Participation = newParticipation;
            table.Participations.Add(newParticipation);
            return(true);
        }
Пример #28
0
        public void AddGameTable(GameTable gameTable)
        {
            var id = _gameTables.Max(x => x.Id) + 1;

            gameTable.Id = id;
            _gameTables.Add(gameTable);
        }
Пример #29
0
    private bool LoadTable(string tablename, Type type)
    {
        if (mTableMap.ContainsKey(tablename) == true)
        {
            Debug.Log("Load table is error!!! Had a file! Name=" + tablename);
            return(false);
        }

        TextAsset o = ResourcesManager.GetInstance().LoadLocalAsset("Tables/" + tablename) as TextAsset;

        if (o == null)
        {
            Debug.Log("Load table is error!!!Read File is error! File=" + tablename);
            return(false);
        }

        GameTable tab = GameTable.Clone(type);

        tab.name = o.name;

        ReadTable(o.text, ref tab);

        mTableMap.Add(tab.name, tab);
        return(true);
    }
Пример #30
0
 public void Add(GameTable newGameTable)
 {
     lock (_gameTables)
     {
         _gameTables.Add(newGameTable);
     }
 }
Пример #31
0
        public void TestGetNextPlayerNotInitalizedGameTable()
        {
            GameTable table = MakeInitialGameTable;
            string    user  = ParticipationService.GetNextPlayer(null, "user1");

            Assert.AreEqual(true, user == null);
        }
Пример #32
0
        public void TestDealingNewDeck()
        {
            // Create a new table. This will internally create and shuffle cards
            var table = new GameTable();

            // Retrieve private fields
            PrivateObject accessor = new PrivateObject(table);
            Stack<Card> deck = (Stack<Card>)accessor.Invoke("getShuffledDeck", null);

            // Set a breakpoint below to examine deck
            Assert.AreEqual(52, deck.Count());
            bool allUnique = deck.Distinct().Count() == deck.Count();
            Assert.AreEqual(true, allUnique);
        }
Пример #33
0
 public void Collision()
 {
     GameBitmap bitmap1 = new GameBitmap(new bool[][]{
         new bool[] { true, true, true },
         new bool[] { false, true, false }
     });
     GameBitmap bitmap2 = new GameBitmap(new bool[][]{
         new bool[] { false, true, false },
         new bool[] { true, true, true }
     });
     GameTable gt = new GameTable(30, 60);
     GameObject go1bm1 = new GameObject(bitmap1);
     GameObject go1bm2 = new GameObject(bitmap2);
     gt.AddObject(go1bm1, 0, 0);
     gt.AddObject(go1bm2, 0, 3);
     Assert.AreEqual(CanMoveResult.TableBoundsCollision, gt.TryMoveObjectHere(go1bm2, 0, -1));
     Assert.AreEqual(CanMoveResult.ObjectCollision, gt.TryMoveObjectHere(go1bm2, 0, 0));
     Assert.AreEqual(CanMoveResult.ObjectCollision, gt.TryMoveObjectHere(go1bm2, 0, 1));
     Assert.AreEqual(CanMoveResult.Success, gt.TryMoveObjectHere(go1bm2, 0, 2));
     Assert.AreEqual(CanMoveResult.Success, gt.TryMoveObjectHere(go1bm2, 0, 3));
 }