public void unserializeGameThread() { working = true; String saveFileLocation = Reference.executablePath + "save.bin"; FileStream fs = null; try { fs = new FileStream(saveFileLocation, FileMode.Open); BinaryFormatter formatter = new BinaryFormatter(); Object[] objects = (Object[])formatter.Deserialize(fs); world = (World)objects[0]; entities = (List <Entity>)objects[1]; inventories = (List <Inventory>)objects[2]; foreach (Entity entity in entities) { if (entity is Player) //It's the player! { player = (Player)entity; } } player.registerHandlers(); LightingEngine.fullLightingUpdateEventDispatcher.handlers.Clear(); foreach (Block b in world.blockList) { b.setEmittedLightLevel(b.emittedLightLevel); } LightingEngine.doFullLightingUpdate(); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.ToString()); } finally { fs.Close(); } working = false; }
public MainForm() { random = new Random(); damageIndicators = new List <DamageIndicator>(); entities = new List <Entity>(); inventories = new List <Inventory>(); instance = this; cursor = Reference.getImage("cursor.png"); viewOffset = new Point(0, 0); player = new Player(new Point(9000, 0)); Zombie zombie = new Zombie(Util.addPoints(player.location, new Point(50, 0))); Zombie zombie2 = new Zombie(Util.addPoints(player.location, new Point(100, 0))); Zombie zombie3 = new Zombie(Util.addPoints(player.location, new Point(150, 0))); //An attempt to fix Wine compatability. My theory as to why not: Using the Windows cursor position method on linux before messagebox is done. //Get cursor position, and ask whether or not they use a Unix-like. if (false) //MessageBox.Show("Are you running the game on a non-Windows system using the Wine compatibility layer?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes) { { linux = true; MessageBox.Show("So that the game knows where your mouse cursor is, please click the top-left of the INSIDE of the window when the game starts. For example, if the following was the window, you would click where the ^ is." + "\n+========+" + "\n|X |" + "\n| |" + "\n| |" + "\n| |" + "\n| |" + "\n| |" + "\n+========+", "Locate your cursor"); waitingForInitialClick = true; } //Windows Forms stuff InitializeComponent(); //Generate World world = World.createWorld(500, 500); //Initialize Recipies List <Recepie> recepies = new List <Recepie>(); Dictionary <InventoryItem, int> input = new Dictionary <InventoryItem, int>(); input.Add(BlockPrototype.log, 1); recepies.Add(new Recepie(input, new KeyValuePair <InventoryItem, int>(BlockPrototype.planks, 5))); Dictionary <InventoryItem, int> input2 = new Dictionary <InventoryItem, int>(); input2.Add(BlockPrototype.planks, 1); recepies.Add(new Recepie(input2, new KeyValuePair <InventoryItem, int>(ItemTemplate.stick.createNew(), 2))); Dictionary <InventoryItem, int> input3 = new Dictionary <InventoryItem, int>(); input3.Add(ItemTemplate.stick.createNew(), 6); input3.Add(ItemTemplate.wool.createNew(), 2); recepies.Add(new Recepie(input3, new KeyValuePair <InventoryItem, int>(new ItemBow(), 1))); Dictionary <InventoryItem, int> input4 = new Dictionary <InventoryItem, int>(); input4.Add(ItemTemplate.stick.createNew(), 4); input4.Add(BlockPrototype.oreCoal, 1); recepies.Add(new Recepie(input4, new KeyValuePair <InventoryItem, int>(BlockPrototype.torch, 4))); Dictionary <InventoryItem, int> input5 = new Dictionary <InventoryItem, int>(); input5.Add(ItemTemplate.stick.createNew(), 2); input5.Add(ItemTemplate.ironBar.createNew(), 4); recepies.Add(new Recepie(input5, new KeyValuePair <InventoryItem, int>(ItemTool.createPickaxe(PickaxeType.PICKAXE_IRON), 1))); inventoryCraftingManager = new CraftingManager(recepies); this.FormClosing += new FormClosingEventHandler(MainForm_FormClosing); //this.Paint += new PaintEventHandler(MainForm_Paint); this.Resize += new EventHandler(MainForm_Resize); this.KeyDown += new KeyEventHandler(MainForm_KeyDown); this.KeyPress += new KeyPressEventHandler(MainForm_KeyPress); this.MouseClick += new MouseEventHandler(MainForm_MouseClick); this.MouseWheel += new MouseEventHandler(MainForm_MouseWheel); this.MouseDown += new MouseEventHandler(MainForm_MouseDown); this.MouseUp += new MouseEventHandler(MainForm_MouseUp); LightingEngine.doFullLightingUpdate(true); }