Exemple #1
0
 public Ai(string name, InterfaceRules rules, Variant variant, List <Score> scores, GameType gameType)
     : base(name, scores, true)
 {
     this.rules   = rules;
     this.variant = variant;
     Strategy(gameType);
 }
Exemple #2
0
 public Ai(int id, InterfaceRules rules, Variant variant, GameType gameType)
     : base("AI" + id, true)
 {
     this.rules   = rules;
     this.variant = variant;
     Strategy(gameType);
 }
        private void StartGame()
        {
            gameSetup      = new GameSetup();
            diceCollection = gameSetup.diceCollection;
            gameType       = gameSetup.gameType;

            variant        = gameSetup.variant;
            rules          = gameSetup.rules;
            database       = gameSetup.database;
            viewController = new ViewController(variant, diceCollection);

            while (viewController.ViewHighscore())
            {
                viewController.GetFiles(rules, database, true);
            }

            if (viewController.ResumeGame())
            {
                viewController.GetFiles(rules, database, false);
                Date        = viewController.Date;
                RoundNumber = viewController.RoundNumber;
                players     = viewController.GetListOfPlayersFromFile();
            }
            else
            {
                Date        = DateTime.Now;
                RoundNumber = 0;
                gameSetup.PlayerSetup();
                players = gameSetup.addedplayers;
            }

            RunGame(players);
        }
Exemple #4
0
 public Database(Variant variant, InterfaceRules rules, GameType gameType)
 {
     this.variant         = variant;
     this.gameType        = gameType;
     this.rules           = rules;
     this.fileName        = gameType.ToString();
     this.playersfromfile = new List <Player>();
     Directory.CreateDirectory(path + fileName);
 }
Exemple #5
0
        public List <Player> GetPlayersFromFile(InterfaceRules rules, string fileName, out DateTime date, out int roundNumber)
        {
            string line;

            this.playersfromfile = new List <Player>();
            List <string> items           = new List <string>();
            var           savingDirectory = Path.Combine(path + "/" + gameType.ToString() + "/" + fileName);
            StreamReader  file            = new StreamReader(savingDirectory);

            while ((line = file.ReadLine()) != null)
            {
                items.Add(line);
            }

            file.Close();

            date        = Convert.ToDateTime(items[0]);
            roundNumber = int.Parse(items[1]);

            string name             = "";
            bool   isAI             = false;
            int    rowsForPlayer    = roundNumber + 2;
            int    noOfPlayers      = (items.Count - 2) / (roundNumber + 2);
            int    indexStartPlayer = 2;

            for (int i = 0; i < noOfPlayers; i++)
            {
                indexStartPlayer = 2 + i * rowsForPlayer;
                List <Score> scoreList = new List <Score>();
                name = items[indexStartPlayer];
                isAI = bool.Parse(items[indexStartPlayer + 1]);
                string[] scoreItems;

                for (int j = 0; j < roundNumber; j++)
                {
                    scoreItems = items[indexStartPlayer + 2 + j].Split('|');
                    int          point = Int32.Parse(scoreItems[0]);
                    Variant.Type vari  = (Variant.Type)Enum.Parse(typeof(Variant.Type), (scoreItems[1]));
                    Score        score = new Score(vari, point);
                    scoreList.Add(score);
                }
                if (isAI)
                {
                    Ai ai = new Ai(name, rules, variant, scoreList, gameType);
                    playersfromfile.Add(ai);
                }
                else
                {
                    Player player = new Player(name, scoreList);
                    playersfromfile.Add(player);
                }
            }
            return(playersfromfile);
        }
Exemple #6
0
        public GameSetup()
        {
            this.gameType       = new MainMenu().RenderStartMenu();
            this.manufactory    = new GameManufactory(gameType);
            this.diceCollection = new DiceCollection();
            this.database       = new Database(variant, rules, gameType);

            this.variant      = manufactory.GetVariant();
            this.rules        = manufactory.GetRules(diceCollection);
            this.renderer     = new Renderer(variant);
            settingsView      = new SettingsView();
            this.addedplayers = new List <Player>();
        }
Exemple #7
0
        public string GetFiles(InterfaceRules rules, Database database, bool selection)
        {
            string viewGameFile = "";

            FileInfo[] files = database.ListSavedGames();
            viewGameFile = SelectGame(files);

            if (viewGameFile != "")
            {
                DateTime date        = new DateTime();
                int      roundNumber = 0;
                playersfromfile = database.GetPlayersFromFile(rules, viewGameFile, out date, out roundNumber);
                Date            = date;
                RoundNumber     = roundNumber;

                if (selection == true)
                {
                    bool fullList = ViewShortHighscore();
                    renderer.RenderHighscore(playersfromfile, date.ToString(), fullList);
                }
            }

            return(viewGameFile);
        }