예제 #1
0
 public Model()
 {
     conf = new Configuration();
     playersWithPoints = conf.GetDictionnaryOfPlayersWithPoints();
     lib = new KaartenAdapter();
     calc = new PointCalculator();
     controller = new Controller(this);
     activeView = new OpstartMenu(this, controller);
     activeView.SetVisible(true);
 }
예제 #2
0
        public void StartUpDataWasEntered(string name, int totalpoints, string typeOfPoints, int pointsOnPoints, int pointsOnCards, string troef)
        {
            errormessage = "";
            //Check name
            Regex r = new Regex(@"[^a-zA-Z]");
            if (r.IsMatch(name)) {
                //Error met naam
                errormessage += "Your name contained illegal characters (most likely a space).";
            }
            if (name.Length == 0) {
                errormessage += " You filled in an empty name.";
            }

            bool possible = false;
            if (pointsOnPoints < 0 || pointsOnCards < 0 || totalpoints > 1000)
            {
                errormessage += " You typed an invalid amount.";
            }
            else {
                possible = calc.CalculateIfPointsArePossible(totalpoints, pointsOnPoints, pointsOnCards);
            }

            //Error
            if (!possible) {
                errormessage += " The points you enter must be (max) half of your total points and you cannot have negative points entered.";
            }

            //Check typeOfPoints
            PointTypes pt = PointTypes.POINTS;
                if (typeOfPoints != null && typeOfPoints.Length > 0)
                {
                    pt = (PointTypes)Enum.Parse(typeof(PointTypes), typeOfPoints);
                }
                else { //Error met PointTypesEnum
                errormessage += " Your type of pointdistributor was invalid.";
                }

            //Check Troef
            bool validTroef = false;
            if (troef != null && troef.Length > 0) {
                validTroef = lib.SetTroef(troef);
            }
            if (!validTroef) {
                //Error met troef
                errormessage += " Your troef was invalid.";
            }

            if (errormessage != "")
            {
                //Update view met errormessage
                UpdateViews(ViewCommunicationTypes.ERROR);
            }
            else {
                //Als playernaam nog niet bestaat, sla deze dan op met zijn punten via config
                if (!playersWithPoints.ContainsKey(name)) {
                    conf.SetPlayerAndPoints(name, totalpoints);
                }
                //Set soort spel in PointCalculator en geef ook de punten mee.
                calc.SoortSpel = pt;
                //Zet troef als troef...
                    //al gedaan hierboven ^
                calc.Troef = lib.GetTroef();
                calc.PointsOnPoints = pointsOnPoints;
                calc.PointsOnNumberOfCards = pointsOnCards;
                //Maak Kaartenspel aan
                    //Al gedaan via constructor...
                //Schud de kaarten
                lib.ShakeCards();
                //Maak human player
                List<KaartenLib.Kaart> kaartenspeler = new List<KaartenLib.Kaart>(10);
                for (int i = 0; i < 10; i++) {
                    kaartenspeler.Add(lib.PullTopCard());
                }
                lib.FlipCardsToFrontSide(ref kaartenspeler);
                humanPlayer = new Deelnemer(name, kaartenspeler, totalpoints);
                //Maak computer player
                List<KaartenLib.Kaart> kaartencomp = new List<KaartenLib.Kaart>(10);
                for (int i = 0; i < 10; i++)
                {
                    kaartencomp.Add(lib.PullTopCard());
                }
                computerPlayer = new Deelnemer("computer", kaartencomp, 1000);
                //Maak de computerbrain en geef jezelf en de computer mee
                brain = new ComputerBrain(lib.GetTroef(), computerPlayer, pt);
                //Maak nieuwe View aan.
                System.Windows.Forms.Form f = (System.Windows.Forms.Form)activeView;
                f.Close();
                f.Dispose();
                activeView = new Game(this, controller);
                activeView.SetVisible(true);
            }
        }