Exemple #1
0
 /// <summary>
 /// Prints the team result.
 /// </summary>
 /// <param name="t">The t.</param>
 private void printTeamResult(team t)
 {
     foreach (MementoResults rounds in takerRez.Old)
         foreach (KeyValuePair<KeyValuePair<team, team>, int> k in rounds.round)
         {
             if (k.Key.Value == t || k.Key.Key == t)
             {
                 switch (k.Value)
                 {
                     case 0:
                         Console.WriteLine("{0,-20} - nerješeno -   {1, -20}", k.Key.Key.name, k.Key.Value.name);
                         break;
                     case 1:
                         Console.WriteLine("{0,-20} je pobijedio    {1, -20}", k.Key.Key.name, k.Key.Value.name);
                         break;
                     case 2:
                         Console.WriteLine("{1,-20} je pobijedio    {0, -20}", k.Key.Key.name, k.Key.Value.name);
                         break;
                 }
             }
         }
 }
Exemple #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PrintEfArg" /> class.
 /// </summary>
 /// <param name="t">The team</param>
 /// <param name="e">The efficiency</param>
 public PrintEfArg(team t, double e)
 {
     this.t = t;
     this.e = e;
 }
Exemple #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PrintEfArg" /> class.
 /// </summary>
 /// <param name="t">The team</param>
 /// <param name="e">The efficiency</param>
 public PrintEfArg(team t, double e)
 {
     this.t = t;
     this.e = e;
 }
Exemple #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="team" /> class.
 /// </summary>
 /// <param name="t">The team</param>
 public team(team t)
 {
     this.name = t.name;
     this.ID = t.ID;
     this.points = t.points;
     this.rank = t.rank;
     this.round_points = t.round_points;
     this.participated = t.participated;
     this.efficiency = t.efficiency;
     this.State = new Context(t.State.state);
     this.prag = t.prag;
 }
Exemple #5
0
        /// <summary>
        /// Play.
        /// </summary>
        /// <param name="obj">null</param>
        private void play(object obj)
        {
            //Used for Random
            System.Threading.Thread.Sleep(1);

            int    n    = teams.Count();
            Random rand = new Random();

            List <team>             temp  = new List <team>();
            Dictionary <team, team> games = new Dictionary <team, team>();

            this.round = new Dictionary <KeyValuePair <team, team>, int>();

            foreach (team tim in teams)
            {
                if (!(tim.State.state is thrown))
                {
                    temp.Add(tim);
                }
            }

            //Stops the timer if there are less than 3 players
            if (temp.Count < 3)
            {
                timer.Dispose();
                Console.WriteLine("Pritisnite 'p' za naredbe.");
                return;
            }

            //Randomizing teams, selecting teams for matches
            while (temp.Count > 1)
            {
                int id1 = rand.Next(0, teams.Count);
                id1 = id1 % temp.Count;
                team player1 = temp[id1];
                temp.Remove(player1);
                int id2 = rand.Next(0, teams.Count);
                id2 = id2 % temp.Count;
                team player2 = temp[id2];
                temp.Remove(player2);
                games.Add(player1, player2);
            }

            //"Playing" the game -> calculating winners using Random, adding points to teams
            Random rand2 = new Random();

            foreach (team player in games.Keys)
            {
                team player2 = games[player];
                player.round_points  = 0;
                player2.round_points = 0;
                int rez = rand2.Next(0, 3);
                switch (rez)
                {
                case 0:
                    player.round_points++;
                    player2.round_points++;
                    break;

                case 1:
                    player.round_points += 2;
                    break;

                case 2:
                    player2.round_points += 2;
                    break;
                }
                player.participated++;
                player2.participated++;
                player.points  += player.round_points;
                player2.points += player2.round_points;
                round.Add(new KeyValuePair <team, team>(player, player2), rez);
            }

            statistics();

            //Console.Clear();

            List <PrintEfArg> list = UpdateEfficiency();

            Console.WriteLine("=====================================================");

            this.n++;
            if (this.n_rounds == this.n)
            {
                updateStates();
                updateMemento();
                //Console.WriteLine("=====================================================");
                #if DEBUG
                printResults(takerTeam.Old.Count);
                #endif
                this.n = 0;
            }
            else
            {
                updateMemento();
            }

            //Event triggering for every change in efficiency
            foreach (PrintEfArg pr in list)
            {
                h(new object(), pr);
            }
        }