コード例 #1
0
ファイル: Message.cs プロジェクト: BlackRebels/IQ-Champions
 public Message(DateTime time, User sender, string message)
 {
     Time = time;
     Sender = sender;
     Msg = message;
 }
コード例 #2
0
ファイル: IQService.cs プロジェクト: BlackRebels/IQ-Champions
        public bool Login(string user, string pass)
        {
            /*
            // Regisztráció debug
            database.dbUserSet.Add(new dbUserSet() { name = user, pass = pass, email = "", goodanswers = 0, played = 0, questions = 0, win = 0 });
            database.SaveChanges();
            */

            bool userfound = false;
            try
            {
                userfound = (from users in database.dbUserSet
                             where users.name.Equals(user) && users.pass.Equals(pass)
                             select users).Count().Equals(1);
            }
            catch (Exception)
            {
            }
            // debug, adminra belép
            if (onlineUsers.Exists(x => x.Name.Equals(user)))
            {
                Logger.log(Errorlevel.INFO, user + " tried to log in twice");
                return false;
            }
            else if (user.Length < 10 || userfound)
            {
                User login = new User(user);
                onlineUsers.Add(login);

                Logger.log(Errorlevel.INFO, user + " logged in");
                return true;
            }
            else
            {
                Logger.log(Errorlevel.INFO, (String.IsNullOrEmpty(user) ? "NULL OR EMPTY" : user) + " failed to log in");
                return false;
            }
        }
コード例 #3
0
ファイル: Room.cs プロジェクト: BlackRebels/IQ-Champions
 public bool Answer(User user, int id)
 {
     user.State = States.IDLE;
     if (id == 0)
     {
         user.AnswerResult = new AnswerResult() { Answer = true, Time = DateTime.Now };
         return true;
     }
     else
     {
         user.AnswerResult = new AnswerResult() { Answer = false, Time = DateTime.Now };
         return false;
     }
 }
コード例 #4
0
ファイル: Room.cs プロジェクト: BlackRebels/IQ-Champions
 public void addUser(User user)
 {
     if (Players.Count <= Room.MAXPLAYERS)
     {
         user.Color = playercolors[Players.Count];
         Players.Add(user);
     }
     else throw new OverflowException("Too much users in " + Name + " room!");
 }
コード例 #5
0
ファイル: Room.cs プロジェクト: BlackRebels/IQ-Champions
        private void turn(object sender, DoWorkEventArgs e)
        {
            int turn = 0;
            do
            {
                actualPlayer = null;
                actualCell = null;

                question = new Question(IQService.database.dbQuestionSet.OrderBy(r => Guid.NewGuid()).First());
                selectNextMove();

                Stopwatch stopper = new Stopwatch();
                stopper.Start();
                // Lépésre vár
                while (stopper.ElapsedMilliseconds < turnTimeout && actualCell == null) Thread.Sleep(IQService.Pingperiod);

                if (actualCell != null)
                {

                    actualCell.Owner.State = States.ANSWER;

                    stopper.Restart();
                    while (stopper.ElapsedMilliseconds < turnTimeout &&
                        (actualPlayer.State == States.ANSWER ||
                        (actualCell.Owner.State == States.ANSWER && actualCell.Owner.Name != null)))
                    {
                        Thread.Sleep(IQService.Pingperiod);
                    }

                    // Lejárt az idő: a válasz rossz
                    if (actualPlayer.AnswerResult == null)
                        actualPlayer.AnswerResult = new AnswerResult() { Answer = false, Time = DateTime.Now };
                    if (actualCell.Owner.AnswerResult == null)
                        actualCell.Owner.AnswerResult = new AnswerResult() { Answer = false, Time = DateTime.Now };

                    if (actualPlayer.AnswerResult.Answer == false || actualPlayer.AnswerResult.Time > actualCell.Owner.AnswerResult.Time)
                    {
                        // Védő nyert
                        actualCell.Owner.Point += 10;
                        actualPlayer.Point -= 10;
                    }
                    else
                    {
                        // Támadó nyert
                        actualCell.Owner.Point -= 10;
                        actualPlayer.Point += 10;
                        actualCell.Owner = actualPlayer;
                    }

                    actualCell.Owner.State = States.IDLE;
                    actualCell.Owner.AnswerResult = null;
                }
                actualPlayer.State = States.IDLE;
                actualPlayer.AnswerResult = null;
                turn++;
            } while (turn < maxturns);

            // Játék vége
            foreach (User u in Players)
            {
                u.State = States.FINISHED;
            }
            Thread.Sleep(IQService.Timeout);
            finished = true;
        }
コード例 #6
0
ファイル: Room.cs プロジェクト: BlackRebels/IQ-Champions
        public void selectNextMove()
        {
            foreach (User u in Players) u.State = States.IDLE;
            if (rollable == null || rollable.Count == 0)
            {
                rollable = new List<User>();
                rollable.AddRange(Players);
            }

            int r = IQService.rand.Next(rollable.Count);
            actualPlayer = rollable[r];
            rollable.RemoveAt(r);

            actualPlayer.State = States.MOVE;
        }
コード例 #7
0
ファイル: Room.cs プロジェクト: BlackRebels/IQ-Champions
        public void selectNextMove()
        {
            foreach (User u in Players) u.State = States.IDLE;
            if (rollable == null || rollable.Count == 0)
            {
                rollable = new List<User>();
                rollable.AddRange(Players);
            }

            int r = IQService.rand.Next(rollable.Count);

            if (IQService.Debug)
            {
                int debug = -1;
                debug = rollable.FindIndex(x => x.Name.Equals("debug"));
                if (debug != -1) r = debug;
            }

            actualPlayer = rollable[r];
            rollable.RemoveAt(r);

            actualPlayer.State = States.MOVE;
        }