/// <summary>
    /// Toggles the value of a given mechanic.
    /// Remember to save!
    /// </summary>
    /// <param name="gameMechanic"></param>
    public void Toggle(GameMechanic gameMechanic)
    {
        var mechanic = (uint)gameMechanic;
        var value    = mechanics[mechanic];

        mechanics[mechanic] = (byte)(value == 0 ? 1 : 0);
    }
Esempio n. 2
0
        public void SetReady(bool Ready)
        {
            ConnectGamer gamer = Gamer();

            if (gamer != null)
            {
                GameMechanic game = gamer.Game.Game;

                gamer.Gamer.Ready = Ready;
                Clients.Clients(GamersId(gamer)).SetReady(new JsonGamer(gamer));

                if (gamer.Game.Gamers.All(x => x.Gamer.Ready))
                {
                    if (!game.isRun)
                    {
                        StartGame(gamer);
                    }
                    else if (game.IsAllAnswer)
                    {
                        SetTask(gamer);
                    }
                }
            }
            else
            {
                Clients.Caller.Reload();
            }
        }
Esempio n. 3
0
        public override Task OnDisconnected(bool stopCalled)
        {
            MutexGame.WaitOne();

            ConnectGamer gamer = Gamer();

            if (gamer != null)
            {
                Clients.Clients(GamersId(gamer)).DeleteGamer(gamer.GamerId);

                ConnectGame  connectGame = gamer.Game;
                GameMechanic game        = connectGame.Game;

                if (connectGame.Gamers.Count() == 1)
                {
                    Keys.Add(game.Id);
                    Games.Remove(connectGame);
                }
                else
                {
                    game.RemoveGamer(gamer.GamerId);
                    connectGame.Gamers.Remove(gamer);
                }
            }

            MutexGame.ReleaseMutex();

            return(base.OnDisconnected(stopCalled));
        }
Esempio n. 4
0
 // Use this for initialization
 void Start()
 {
     gameTextDisplay1.text = "";
     gameTextDisplay2.text = "";
     state      = States.Preparing;
     classifier = new GestureClassifier();
     mechanic   = new GameMechanic();
 }
 public MainHandler()
 {
     Settings       = new Settings();
     StorageService = new StorageService();
     AllPlayers     = StorageService.DeserializePlayers(Settings.SavesPath);
     InfoCommand    = new GameInformation(StorageService, Settings, AllPlayers);
     GameMechanic   = new GameMechanic(Settings, InfoCommand);
 }
    private GameMechanic RandomizeMechanic(List <GameMechanic> list)
    {
        GameMechanic mechanic = list[Random.Range(0, list.Count)];

        list.Remove(mechanic);

        return(mechanic);
    }
 private void ShowRandomResult(GameMechanic mechanic, Image icon, TextMeshProUGUI name, SpecialTargetScreen infoButton)
 {
     icon.sprite = mechanic.Icon;
     name.text   = mechanic.Name;
     icon.color  = mechanic.Color;
     name.color  = mechanic.Color;
     infoButton.NameOfInfoScreen = mechanic.NameOfInfoScreen;
 }
 /// <summary>
 /// Gets the value of a given mechanic.
 /// </summary>
 /// <param name="gameMechanic"></param>
 /// <returns></returns>
 public bool Get(GameMechanic gameMechanic)
 {
     if (mechanics == null)
     {
         Start();
     }
     return(mechanics[(uint)gameMechanic] != 0);
 }
Esempio n. 9
0
        private void SetResult(ConnectGamer gamer)
        {
            LanguageDictionary language = new LanguageDictionary();
            GameMechanic       game     = gamer.Game.Game;

            List <JsonResult> results = game.Results().Select(x => new JsonResult()
            {
                Feature = x.Feature.Value(language.GetLanguage()),
                Id      = x.Gamer.Id
            }).ToList();

            Clients.Clients(GamersId(gamer)).SetResult(results, language.Get("Result"));
        }
Esempio n. 10
0
        private void StartGame(ConnectGamer gamer)
        {
            GameMechanic game = gamer.Game.Game;

            game.isRun = true;

            foreach (Gamer g in game.Gamers)
            {
                g.Ready = false;
            }

            SetTask(gamer);
        }
        private BoardGameGeekGameMechanic GetOrCreateMechanic(GameMechanic gameMechanic)
        {
            var mechanic = _dataContext.GetQueryable <BoardGameGeekGameMechanic>()
                           .FirstOrDefault(
                c =>
                c.MechanicName.Equals(gameMechanic.Mechanic,
                                      StringComparison.InvariantCultureIgnoreCase));

            if (mechanic == null)
            {
                mechanic = new BoardGameGeekGameMechanic()
                {
                    BoardGameGeekGameMechanicId = gameMechanic.Id,
                    MechanicName = gameMechanic.Mechanic
                };
            }
            return(mechanic);
        }
    public void DiceRoll()
    {
        GameObject   gameManager  = GameObject.Find("GamePlay");
        GameMechanic gameMechanic = gameManager.GetComponent <GameMechanic>();

        int diceValue;

        diceValue = Random.Range(1, 7);
        if (diceValue > 2)
        {
            GameMechanic.currentState       = exitState;
            gameMechanic.textComponent.text = GameMechanic.currentState.GetStateStory();
        }
        else
        {
            GameMechanic.currentState = loseExitState;
            SceneManager.LoadScene(LoseScene);
        }
    }
Esempio n. 13
0
        private void SetTask(ConnectGamer gamer)
        {
            GameMechanic game = gamer.Game.Game;

            game.IndexTask++;

            if (game.IsAllTask)
            {
                SetResult(gamer);
            }
            else
            {
                Clients.Clients(GamersId(gamer)).SetTask(new JsonTask()
                {
                    Value = game.Tasks[game.IndexTask].Value(LanguageDictionary.GetLanguages())
                });
                Thread TimerThread = new Thread(new ParameterizedThreadStart(TimerStart));
                TimerThread.Start(gamer);
            }
        }
Esempio n. 14
0
        protected void TimerStart(object Object)
        {
            ConnectGamer gamer = (ConnectGamer)Object;
            GameMechanic game  = gamer.Game.Game;
            ConnectGame  cgame = gamer.Game;
            int          time  = 1;

            do
            {
                Clients.Clients(GamersId(gamer)).SetTimer(time--);
                Thread.Sleep(1000);
            } while (time > 0 && !game.IsAllAnswer);

            if (!game.IsAllAnswer)
            {
                foreach (Gamer item in game.Gamers.Where(x => !game.Answers.Any(z => z.SenderId == x.Id)))
                {
                    SetAnswer(item.Id, item.Id);
                }
            }
        }
Esempio n. 15
0
        private void SetAnswer(long SenderId, long RecipientId, ConnectGamer gamer = null)
        {
            gamer = gamer ?? GamerById(SenderId);
            GameMechanic game = gamer.Game.Game;

            IO_Answer answer = game.AddAnswer(SenderId, RecipientId);

            if (answer != null)
            {
                bool All = game.IsAllAnswer;

                if (!All)
                {
                    Clients.Caller.SetAnswers(new List <JsonAnswer>()
                    {
                        new JsonAnswer(answer)
                    });
                }
                else
                {
                    game.CalculatorCoints();
                    foreach (Gamer g in game.Gamers)
                    {
                        g.Ready = false;
                    }

                    Clients.Clients(GamersId(gamer))
                    .SetAnswers(game.Answers.Select(x => new JsonAnswer(x)).ToList());

                    Clients.Clients(GamersId(gamer))
                    .SetGamers(gamer.Game.Gamers.Select(x => new JsonGamer(x)).ToList());
                }
            }
            else
            {
                Clients.Caller.Reload();
            }
        }
Esempio n. 16
0
        private void Insert(List <Item> itemList)
        {
            foreach (Item item in itemList)
            {
                int highestVotes     = -1;
                int suggestedPlayers = 0;
                foreach (Results results in item.Poll.Where(poll => poll.Name.Contains("suggested_numplayers")).ToList().First().Results)
                {
                    foreach (Result result in results.Result)
                    {
                        if (result.Value.Contains("Best") && int.Parse(result.Numvotes) > highestVotes)
                        {
                            highestVotes     = int.Parse(result.Numvotes);
                            suggestedPlayers = int.Parse(results.Numplayers);
                        }
                    }
                }

                Games game = new Games
                {
                    Id          = int.Parse(item.Id),
                    GameName    = item.Name.First().Value,
                    MinPlayers  = int.Parse(item.Minplayers.Value),
                    MaxPlayers  = int.Parse(item.Maxplayers.Value),
                    SugPlayers  = suggestedPlayers,
                    GameDesc    = item.Description,
                    PlaytimeMin = int.Parse(item.Minplaytime.Value),
                    PlaytimeMax = int.Parse(item.Maxplaytime.Value),
                    ReviewScore = double.Parse(item.Statistics.Ratings.Average.Value),
                    NumReviews  = int.Parse(item.Statistics.Ratings.Usersrated.Value),
                    Complexity  = double.Parse(item.Statistics.Ratings.Averageweight.Value),
                    AgeMin      = int.Parse(item.Minage.Value),
                    AgeMax      = 99,
                    PictureUrl  = item.Thumbnail
                };

                foreach (Link link in item.Link)
                {
                    if (link.Type.Contains("category"))
                    {
                        Category category = new Category
                        {
                            Id        = int.Parse(link.Id),
                            Category1 = link.Value
                        };
                        GameCategory gameCategory = new GameCategory
                        {
                            GameId     = game.Id,
                            CategoryId = category.Id
                        };

                        if (!_dbContext.GameCategory.Contains(gameCategory))
                        {
                            _dbContext.Add(gameCategory);
                        }

                        if (!_dbContext.Category.Contains(category))
                        {
                            _dbContext.Add(category);
                        }
                    }
                    else if (link.Type.Contains("mechanic"))
                    {
                        Mechanic mechanic = new Mechanic
                        {
                            Id        = int.Parse(link.Id),
                            Mechanic1 = link.Value
                        };
                        GameMechanic gameMechanic = new GameMechanic
                        {
                            GameId     = game.Id,
                            MechanicId = mechanic.Id
                        };

                        if (!_dbContext.GameMechanic.Contains(gameMechanic))
                        {
                            _dbContext.Add(gameMechanic);
                        }

                        if (!_dbContext.Mechanic.Contains(mechanic))
                        {
                            _dbContext.Add(mechanic);
                        }
                    }
                    else if (link.Type.Contains("publish"))
                    {
                        Publisher publisher = new Publisher
                        {
                            Id         = int.Parse(link.Id),
                            Publisher1 = link.Value
                        };

                        GamePublisher gamePublisher = new GamePublisher
                        {
                            GameId      = game.Id,
                            PublisherId = publisher.Id
                        };
                        if (!_dbContext.GamePublisher.Contains(gamePublisher))
                        {
                            _dbContext.Add(gamePublisher);
                        }

                        if (!_dbContext.Publisher.Contains(publisher))
                        {
                            _dbContext.Add(publisher);
                        }
                    }
                    else if (link.Type.Contains("design"))
                    {
                        Designer designer = new Designer
                        {
                            Id        = int.Parse(link.Id),
                            Designer1 = link.Value
                        };
                        GameDesigner gameDesigner = new GameDesigner
                        {
                            GameId     = game.Id,
                            DesignerId = designer.Id
                        };

                        if (!_dbContext.GameDesigner.Contains(gameDesigner))
                        {
                            _dbContext.Add(gameDesigner);
                        }

                        if (!_dbContext.Designer.Contains(designer))
                        {
                            _dbContext.Add(designer);
                        }
                    }
                    else if (link.Type.Contains("artist"))
                    {
                        Artist artist = new Artist
                        {
                            Id      = int.Parse(link.Id),
                            Artist1 = link.Value
                        };
                        GameArtist gameArtist = new GameArtist
                        {
                            GameId   = game.Id,
                            ArtistId = artist.Id
                        };
                        if (!_dbContext.GameArtist.Contains(gameArtist))
                        {
                            _dbContext.Add(gameArtist);
                        }
                        if (!_dbContext.Artist.Contains(artist))
                        {
                            _dbContext.Add(artist);
                        }
                    }
                }
                if (!_dbContext.Games.Contains(game))
                {
                    _dbContext.Add(game);
                }
                _dbContext.SaveChanges();
            }
        }
Esempio n. 17
0
 public ConnectGame(long Id)
 {
     Game = new GameMechanic(Id);
 }
 /// <summary>
 /// Sets the value of a given mechanic.
 /// Remember to save!
 /// </summary>
 /// <param name="gameMechanic"></param>
 /// <param name="value"></param>
 public void Set(GameMechanic gameMechanic, bool value)
 {
     mechanics[(uint)gameMechanic] = (byte)(value ? 1 : 0);
 }