public int AddPlayer(DTOPlayer player, int?teamID, int?leagueID)
        {
            var parameters = new List <SqlParameter>();

            if (!string.IsNullOrEmpty(player.Name))
            {
                parameters.Add(CreateSqlParameter("@Name", SqlDbType.VarChar, player.Name));
            }
            parameters.Add(CreateSqlParameter("@Number", SqlDbType.Int, player.Number));
            if (teamID.HasValue)
            {
                parameters.Add(CreateSqlParameter("@TeamID", SqlDbType.Int, teamID.Value));
            }
            if (leagueID.HasValue)
            {
                parameters.Add(CreateSqlParameter("@LeagueID", SqlDbType.Int, leagueID.Value));
            }
            var outputParam = new SqlParameter();

            if (player.ID > 0)
            {
                outputParam = CreateSqlParameter("@PlayerID", SqlDbType.Int, player.ID);
            }
            else
            {
                outputParam = CreateSqlParameter("@PlayerID", SqlDbType.Int);
            }
            outputParam.Direction = ParameterDirection.InputOutput;
            parameters.Add(outputParam);
            SQLExecuteCommandParam("AddPlayer", parameters);
            return(Convert.ToInt32(outputParam.Value));
        }
Beispiel #2
0
        public DTOPlayer PatchPlayer(DTOPlayer player)
        {
            logger.LogTrace($"{nameof(this.PatchPlayer)} called");

            var result = playerService.UpdateEntity(mapper.Map <DomainPlayerUpdateModel>(player));

            return(mapper.Map <DTOPlayer>(result));
        }
        public void SavePlayer(DTOPlayer player)
        {
            var parameters = new List <SqlParameter>();

            parameters.Add(CreateSqlParameter("@Name", SqlDbType.VarChar, player.Name));
            parameters.Add(CreateSqlParameter("@PlayerID", SqlDbType.Int, player.ID));
            SQLExecuteCommandParam("SavePlayer", parameters);
        }
        public void SaveTeamPlayer(DTOPlayer player)
        {
            var parameters = new List <SqlParameter>();

            parameters.Add(CreateSqlParameter("@TeamID", SqlDbType.Int, player.TeamID));
            parameters.Add(CreateSqlParameter("@PlayerID", SqlDbType.Int, player.ID));
            parameters.Add(CreateSqlParameter("@PlayerNumber", SqlDbType.Int, player.Number));
            SQLExecuteCommandParam("SaveTeamPlayer", parameters);
        }
Beispiel #5
0
        public List <Player> GetPlayers(int?teamID = null, int?gameID = null, int?leagueID = null, DataCache dataCache = null)
        {
            var players = PlayerDataProvider.GetInstance().GetPlayers(teamID: teamID, gameID: gameID, leagueID: leagueID, dataCache: dataCache);

            if (gameID.HasValue)
            {
                var dtoGame    = GameDataProvider.GetInstance().GetGames(gameID: gameID, dataCache: dataCache).First();
                var game       = ConvertObjects.ConvertType(dtoGame);
                var validTeams = new List <int>()
                {
                    game.Team1ID, game.Team2ID
                };
                if (!players.Exists(p => p.TeamID == game.Team1ID))
                {
                    //ADD TEAM PLAYER
                    var dtoPlayer = new DTOPlayer()
                    {
                        Name   = "Team 1 Player",
                        TeamID = game.Team1ID
                    };
                    players.Add(dtoPlayer);
                }

                if (!players.Exists(p => p.TeamID == game.Team2ID))
                {
                    //ADD TEAM PLAYER
                    var dtoPlayer = new DTOPlayer()
                    {
                        Name   = "Team 2 Player",
                        TeamID = game.Team2ID
                    };
                    players.Add(dtoPlayer);
                }
            }

            return(players
                   .Where(p => UserHelper.HasGetPermissions(playerID: p.ID, gameID: gameID))
                   .Select(p => new Player()
            {
                ID = p.ID,
                Name = p.Name,
                Number = p.Number,
                TeamID = p.TeamID
            })
                   .ToList());
        }
Beispiel #6
0
        private void main_loop()
        {
            //MessageBox.Show(running.ToString());
            Boolean sent = false;

            while (true)
            {
                while (pmc.getFrozen())
                {
                    while (gameStates.Count > 0)
                    {
                        gameStates.Dequeue();
                    }
                }
                if (sent)
                {
                    Thread.Sleep(Int32.Parse(round_timer));
                }
                #region Ask for input and send it to the server

                if (!sent && running && (goleft || goright || goup || godown) && traceMoves.Count == 0)
                {
                    List <String> dirs = new List <String>();
                    if (goleft)
                    {
                        dirs.Add("LEFT");
                    }
                    if (goright)
                    {
                        dirs.Add("RIGHT");
                    }
                    if (goup)
                    {
                        dirs.Add("UP");
                    }
                    if (godown)
                    {
                        dirs.Add("DOWN");
                    }

                    reqObj.RequestMove(PlayersID.FirstOrDefault(x => x.Value == 1).Key, dirs, round);
                    sent = true;
                }
                else if (!sent && traceMoves.Count != 0 && running == true)
                {
                    List <String> dirs = new List <String>();
                    dirs.Add(traceMoves[round]);
                    //traceMoves.Remove(round);
                    reqObj.RequestMove(PlayersID.FirstOrDefault(x => x.Value == 1).Key, dirs, round);
                    sent = true;
                }

                #endregion


                #region update game State
                //while (gameStates.Count <= 0) Thread.Sleep(1); //WAIT FOR UPDATES FROM THE SEVER
                if (gameStates.Count > 0)
                { //WAIT FOR UPDATES FROM THE SEVER
                    sent = false;
                    GameState gm = gameStates.Dequeue();

                    foreach (DTOPlayer player in gm.players) //Update Players Positions
                    {
                        PictureBox p = (PictureBox)this.Controls.Find("pacman" + PlayersID[player.name], true)[0];

                        changeControlPosition(this, new PacEventArgs(player.posX, player.posY, p));
                        changePacDir(this, new PacEventArgs(p, player.faceDirection));
                    }

                    foreach (DTOGhost ghost in gm.ghosts) // Update Ghosts Positions
                    {
                        PictureBox g = (PictureBox)this.Controls.Find("Ghost" + ghost.color, true)[0];
                        changeControlPosition(this, new PacEventArgs(ghost.posX, ghost.posY, g));
                    }

                    foreach (DTOCoin c in gm.coins)     //  Update Coins Visibility
                    {
                        if (c.taken)
                        {
                            Point      pos  = new Point(c.posX, c.posY);
                            PictureBox coin = (PictureBox)GetControlByPosAndType(pos, new PictureBox().GetType());
                            changeCoinVisibility(this, new PacEventArgs(coin, "Doesn't matter"));
                        }
                    }
                    String    myName = PlayersID.FirstOrDefault(x => x.Value == 1).Key;
                    DTOPlayer play   = gm.players.FirstOrDefault(x => x.name == myName);
                    int       score  = 0;
                    foreach (DTOPlayer pl in gm.players)
                    {
                        if (pl.Equals(play))
                        {
                            score = pl.score; break;
                        }
                    }
                    changeTxtText(this, new PacEventArgs(this.Controls.Find("label1", true)[0], "Score: " + score.ToString()));

                    // Do something with the walls, maybe next delivery

                    //update round
                    round = gm.round;

                    if (endgame)
                    {
                        changeTxtText(this,
                                      new PacEventArgs((this.Controls.Find("label2", true)[0]), (play.won) ? "WON" : "GAME OVER!")
                                      );
                        break;
                    }
                }
                #endregion
            }
        }