Exemplo n.º 1
0
 // C'tor for global items
 internal Player(GameDef g)
 {
     SharedDef globalDef = g.GlobalDefinition;
     // Register the lPlayer
     all.Add(this);
     // Init fields
     _name = "Global";
     Id = 0;
     PublicKey = 0;
     if (GlobalVariables == null)
     {
         // Create global variables
         GlobalVariables = new Dictionary<string, string>();
         foreach (GlobalVariableDef varD in g.PlayerDefinition.GlobalVariables)
             GlobalVariables.Add(varD.Name, varD.Value);
     }
     // Create counters
     _counters = new Counter[globalDef.Counters != null ? globalDef.Counters.Length : 0];
     for (int i = 0; i < Counters.Length; i++)
         if (globalDef.Counters != null) Counters[i] = new Counter(this, globalDef.Counters[i]);
     // Create global's lPlayer groups
     // TODO: This could fail with a run-time exception on write, make it safe
     _groups = new Pile[globalDef.Groups != null ? g.GlobalDefinition.Groups.Length + 1 : 0];
     for (int i = 1; i < IndexedGroups.Length; i++)
         if (globalDef.Groups != null) _groups[i] = new Pile(this, globalDef.Groups[i - 1]);
 }
Exemplo n.º 2
0
 // C'tor
 internal Player(GameDef g, string name, byte id, ulong pkey)
 {
     // Init fields
     _name = name;
     Id = id;
     PublicKey = pkey;
     // Register the lPlayer
     all.Add(this);
     //Create the color brushes
     SetPlayerColor(id);
     // Create counters
     _counters = new Counter[g.PlayerDefinition.Counters != null ? g.PlayerDefinition.Counters.Length : 0];
     for (int i = 0; i < Counters.Length; i++)
         if (g.PlayerDefinition.Counters != null)
             Counters[i] = new Counter(this, g.PlayerDefinition.Counters[i]);
     // Create variables
     Variables = new Dictionary<string, int>();
     foreach (VariableDef varDef in g.Variables.Where(v => !v.Global))
         Variables.Add(varDef.Name, varDef.DefaultValue);
     // Create global variables
     GlobalVariables = new Dictionary<string, string>();
     foreach (GlobalVariableDef varD in g.PlayerDefinition.GlobalVariables)
         GlobalVariables.Add(varD.Name, varD.Value);
     // Create a hand, if any
     if (g.PlayerDefinition.Hand != null)
         _hand = new Hand(this, g.PlayerDefinition.Hand);
     // Create groups
     _groups = new Group[g.PlayerDefinition.Groups != null ? g.PlayerDefinition.Groups.Length + 1 : 1];
     _groups[0] = _hand;
     for (int i = 1; i < IndexedGroups.Length; i++)
         if (g.PlayerDefinition.Groups != null) _groups[i] = new Pile(this, g.PlayerDefinition.Groups[i - 1]);
     // Raise the event
     if (PlayerAdded != null) PlayerAdded(null, new PlayerEventArgs(this));
 }
Exemplo n.º 3
0
 public Game(GameDef def)
 {
     _definition = def;
       _table = new Table(def.TableDefinition);
       Variables = new Dictionary<string, int>();
       foreach (var varDef in def.Variables.Where(v => v.Global))
     Variables.Add(varDef.Name, varDef.DefaultValue);
 }
Exemplo n.º 4
0
 public static bool CheckGameDef(GameDef game)
 {
     Program.Game = new Game(game);
     Program.Game.TestBegin();
     var engine = new Engine(true);
     string[] terr = engine.TestScripts(Program.Game);
     Program.Game.End();
     if (terr.Length > 0)
     {
         String ewe = terr.Aggregate("",
                                     (current, s) =>
                                     current +
                                     (s + Environment.NewLine));
         var er = new Windows.ErrorWindow(ewe);
         er.ShowDialog();
     }
     return terr.Length == 0;
 }
Exemplo n.º 5
0
 public static void Open(GameDef game, bool readOnly)
 {
     OpenedGame = Program.GamesRepository.Games.First(g => g.Id == game.Id);
 }
Exemplo n.º 6
0
 public static void Open(GameDef game, bool readOnly)
 {
     OpenedGame = GameManager.Get().GetById(game.Id);
     //OpenedGame = Program.GamesRepository.Games.First(g => g.Id == game.Id);
 }
Exemplo n.º 7
0
        public bool Install()
        {
            //Fix def filename
            String newFilename = Uri.UnescapeDataString(FileName);

            if (!newFilename.ToLower().Equals(FileName.ToLower()))
            {
                try
                {
                    File.Move(FileName, newFilename);
                }
                catch (Exception)
                {
                    MessageBox.Show(
                        "This file is currently in use. Please close whatever application is using it and try again.");
                    return(false);
                }
            }

            try
            {
                GameDef game = GameDef.FromO8G(newFilename);
                //Move the definition file to a new location, so that the old one can be deleted
                string path = Path.Combine(Prefs.DataDirectory, "Games", game.Id.ToString(), "Defs");
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                var    fi     = new FileInfo(newFilename);
                string copyto = Path.Combine(path, fi.Name);
                try
                {
                    if (newFilename.ToLower() != copyto.ToLower())
                    {
                        File.Copy(newFilename, copyto, true);
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show(
                        "File in use. You shouldn't install games or sets when in the deck editor or when playing a game.");
                    return(false);
                }
                newFilename = copyto;
                // Open the archive
                game = GameDef.FromO8G(newFilename);
                if (!game.CheckVersion())
                {
                    return(false);
                }

                //Check game scripts
                if (!Windows.UpdateChecker.CheckGameDef(game))
                {
                    return(false);
                }

                // Check if the game already exists
                if (Program.GamesRepository.Games.Any(g => g.Id == game.Id))
                {
                    if (
                        MessageBox.Show("This game already exists.\r\nDo you want to overwrite it?", "Confirmation",
                                        MessageBoxButton.YesNo, MessageBoxImage.Exclamation) != MessageBoxResult.Yes)
                    {
                        return(false);
                    }
                }

                if (Fonts.Count > 0)
                {
                    InstallFonts();
                }

                var gameData = new Data.Game
                {
                    Id                 = game.Id,
                    Name               = game.Name,
                    Filename           = new FileInfo(newFilename).Name,
                    Version            = game.Version,
                    CardWidth          = game.CardDefinition.Width,
                    CardHeight         = game.CardDefinition.Height,
                    CardBack           = game.CardDefinition.Back,
                    DeckSections       = game.DeckDefinition.Sections.Keys,
                    SharedDeckSections =
                        game.SharedDeckDefinition == null
                                               ? null
                                               : game.SharedDeckDefinition.Sections.Keys,
                    Repository = Program.GamesRepository,
                    FileHash   = game.FileHash
                };
                var rootDir = Path.Combine(Prefs.DataDirectory, "Games", game.Id.ToString()) + "\\";
                using (Package package = Package.Open(copyto, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    foreach (var p in package.GetParts())
                    {
                        this.ExtractPart(p, rootDir);
                    }
                }

                Program.GamesRepository.InstallGame(gameData, game.CardDefinition.Properties.Values);
                return(true);
            }
            catch (FileFormatException)
            {
                //Removed ex.Message. The user doesn't need to see the exception
                MessageBox.Show("Your game definition file is corrupt. Please redownload it.", "Error",
                                MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
        }