Beispiel #1
0
 public bool neighbor(Cell cell)
 {
     if (this.Col == cell.Col && this.Row == cell.Row) return false; // saját maga
     else if (this.Owner == cell.Owner) return false; // saját cellára kattintott
     else if (Math.Abs(this.Col - cell.Col) <= 1 && Math.Abs(this.Row - cell.Row) <= 1) return true; // szomszédos
     else return false; //bármi más
 }
Beispiel #2
0
        public GameTable(int x, int y)
        {
            Table = new List<Cell>();
            for (int i = 0; i < x; i++) for (int j = 0; j < y; j++)
                {
                    if ((i == 0 && j == 0) || (i == 0 && j == y-1) || (i == x-1 && j == 0) || (i == x-1 && j == y-1))
                    {
                        Cell cella = new Cell(i, j);
                        cella.isBase = true;
                        Table.Add(cella);
                    }
                    else
                    {
                        Table.Add(new Cell(i, j));

                    }
                }
        }
Beispiel #3
0
 public bool neighbor(Cell cell)
 {
     if (this.Col == cell.Col && this.Row == cell.Row) return false;
     if (Math.Abs(this.Col - cell.Col) <= 1 && Math.Abs(this.Row - cell.Row) <= 1) return true;
     return false;
 }
Beispiel #4
0
        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;
        }
Beispiel #5
0
 public bool Move(int col, int row)
 {
     actualCell = Table.Table.Find(c => c.Row == col && c.Col == row);
        /* bool ok = false;
     foreach (Cell c in Table.Table)
     {
         if (c.Owner == actualPlayer)
             if (c.neighbor(actualCell))
             {
                 ok = true;
                 break;
             }
     }*/
     // vizsgálat nincs megvalósítva
     if (true)
     {
         // Támad
         actualPlayer.State = States.ANSWER;
         actualCell.Owner.State = States.ANSWER;
         return true;
     }
     else
     {
         // Rossz mező
         actualCell = null;
         return false;
     }
 }