Exemplo n.º 1
0
        public void TotalDifficulty()
        {
            BlockMetadata a = BlockMetadata1.Copy();

            a.TotalDifficulty = BlockMetadata1.TotalDifficulty + 10;
            Assert.Equal(BlockMetadata1.TotalDifficulty + 10, a.TotalDifficulty);
            Assert.Equal(BlockMetadata1.Difficulty, a.Difficulty);

            BlockMetadata b = Block1.Copy();
            InvalidBlockTotalDifficultyException e =
                Assert.Throws <InvalidBlockTotalDifficultyException>(() => b.TotalDifficulty = -1);

            Assert.Equal(BlockMetadata1.TotalDifficulty, b.TotalDifficulty);
            Assert.Equal(BlockMetadata1.Difficulty, b.Difficulty);
            Assert.Equal(b.Difficulty, e.Difficulty);
            Assert.Equal(-1, e.TotalDifficulty);

            e = Assert.Throws <InvalidBlockTotalDifficultyException>(
                () => b.TotalDifficulty = b.Difficulty - 1L
                );
            Assert.Equal(BlockMetadata1.TotalDifficulty, b.TotalDifficulty);
            Assert.Equal(BlockMetadata1.Difficulty, b.Difficulty);
            Assert.Equal(b.Difficulty, e.Difficulty);
            Assert.Equal(b.Difficulty - 1L, e.TotalDifficulty);
        }
Exemplo n.º 2
0
        void showBlock(int level)
        {
            switch (level)
            {
            case 1:
                Block1.Show();
                Block1.Location = block.Location;
                break;

            case 2:
                Block2.Show();
                Block2.Location = block.Location;
                if (Block2.Left != Block1.Left)
                {
                    block.Hide();
                    Timer_Game3.Start();
                    fail();
                }
                break;

            case 3:
                Block3.Show();
                Block3.Location = block.Location;
                if (Block3.Left != Block2.Left)
                {
                    block.Hide();
                    Timer_Game3.Start();
                    fail();
                }
                break;
            }
        }
Exemplo n.º 3
0
        public void TransactionsWithMissingNonce()
        {
            var dupTx1 = new Transaction <Arithmetic>(
                nonce: 3L,
                signer: Tx1InBlock1.Signer,
                publicKey: Tx1InBlock1.PublicKey,
                genesisHash: GenesisHash,
                updatedAddresses: ImmutableHashSet <Address> .Empty.Add(Tx1InBlock1.Signer),
                timestamp: Tx1InBlock1.Timestamp,
                actions: Array.Empty <Arithmetic>(),
                signature: ByteUtil.ParseHex(
                    "3045022100bfdf79427028efea9449ad46fbf46d5a806694aa5bbab1a01f4c76b21acd" +
                    "cb16022057c851a01dd74797121385ccfc81e7b33842941189154b4d46d05e891a28e3eb"
                    )
                );
            var block = Block1.Copy();
            InvalidTxNonceException e = Assert.Throws <InvalidTxNonceException>(
                () => block.Transactions = new[] { Tx0InBlock1, Tx1InBlock1, dupTx1 }
                );

            Assert.Equal(dupTx1.Id, e.TxId);
            Assert.Equal(2L, e.ExpectedNonce);
            Assert.Equal(dupTx1.Nonce, e.ImproperNonce);
            Assert.Equal(Block1.Transactions, block.Transactions);
        }
Exemplo n.º 4
0
        public void TransactionsWithDuplicateNonce()
        {
            var dupTx1 = new Transaction <Arithmetic>(
                nonce: 1L,
                signer: Tx1InBlock1.Signer,
                publicKey: Tx1InBlock1.PublicKey,
                genesisHash: GenesisHash,
                updatedAddresses: ImmutableHashSet <Address> .Empty.Add(Tx1InBlock1.Signer),
                timestamp: Tx1InBlock1.Timestamp,
                actions: Array.Empty <Arithmetic>(),
                signature: ByteUtil.ParseHex(
                    "304502210099e580e8599acf0b26ad0a80315f2d488703ffde01e9449b4bf399593b8cc" +
                    "e63022002feb21bf0e4d76d25d17c8c1c4fbb3dfbda986e0693f984fbb302183ab7ece1"
                    )
                );
            var block = Block1.Copy();
            InvalidTxNonceException e = Assert.Throws <InvalidTxNonceException>(
                () => block.Transactions = new[] { Tx0InBlock1, Tx1InBlock1, dupTx1 }
                );

            Assert.Equal(dupTx1.Id, e.TxId);
            Assert.Equal(2L, e.ExpectedNonce);
            Assert.Equal(dupTx1.Nonce, e.ImproperNonce);
            Assert.Equal(Block1.Transactions, block.Transactions);
        }
Exemplo n.º 5
0
        public void TransactionsWithInconsistentGenesisHashes()
        {
            var key = PrivateKey.FromString(
                "2ed05de0b35d93e4ae801ae40c8bb4257a771ff67c1e5d1754562e4191953710"
                );
            var differentGenesisHash = BlockHash.FromString(
                "76942b42f99c28da02ed916ebd2fadb189415e8288a4bd87f9ae3594127b79e6"
                );
            var txWithDifferentGenesis = new Transaction <Arithmetic>(
                nonce: 0L,
                signer: key.ToAddress(),
                publicKey: key.PublicKey,
                genesisHash: differentGenesisHash,
                updatedAddresses: ImmutableHashSet <Address> .Empty,
                timestamp: new DateTimeOffset(2021, 9, 7, 12, 1, 12, 345, TimeSpan.FromHours(9)),
                actions: Array.Empty <Arithmetic>(),
                signature: ByteUtil.ParseHex(
                    "304402202027a31e4298c685daaa944b1d120b4e6894f3bfffa13563331c0a7071a04b" +
                    "310220167507575e982d47d7c6753b782a5f1beb6415af96e7db3ccaf83b516d5133d1"
                    )
                );
            BlockContent <Arithmetic> block = Block1.Copy();

            Transaction <Arithmetic>[] inconsistentTxs =
                block.Transactions.Append(txWithDifferentGenesis).ToArray();
            InvalidTxGenesisHashException e = Assert.Throws <InvalidTxGenesisHashException>(
                () => block.Transactions = inconsistentTxs
                );

            Assert.Equal(Block1.Transactions[0].GenesisHash, e.ExpectedGenesisHash);
            Assert.Equal(differentGenesisHash, e.ImproperGenesisHash);
            Assert.Equal(Block1.Transactions, block.Transactions);
        }
Exemplo n.º 6
0
        public void CancelMine()
        {
            using (CancellationTokenSource source = new CancellationTokenSource())
            {
                HashAlgorithmType sha512 = HashAlgorithmType.Of <SHA512>();
                Block1.Difficulty = long.MaxValue;

                Exception exception = null;
                Task      task      = Task.Run(() =>
                {
                    try
                    {
                        Block1.Mine(sha512, source.Token);
                    }
                    catch (OperationCanceledException ce)
                    {
                        exception = ce;
                    }
                });

                source.Cancel();
                bool taskEnded = task.Wait(TimeSpan.FromSeconds(10));
                Assert.True(taskEnded);
                Assert.NotNull(exception);
                Assert.IsAssignableFrom <OperationCanceledException>(exception);
            }
        }
Exemplo n.º 7
0
    public GameWorld(int width, int height, ContentManager Content)
    {
        screenWidth = width;
        screenHeight = height;
        random = new Random();
        gameState = GameState.Menu;
        inputHelper = new InputHelper();
        block = Content.Load<Texture2D>("block");
        reset = Content.Load<Texture2D>("reset");
        font = Content.Load<SpriteFont>("SpelFont");
        font2 = Content.Load<SpriteFont>("SpriteFont1");
        font3 = Content.Load<SpriteFont>("SpriteFont2");
        playButton = Content.Load<Texture2D>("Play");
        optionsButton = Content.Load<Texture2D>("Options");
        backButton = Content.Load<Texture2D>("Back");
        polytris = Content.Load<Texture2D>("Polytris");
        grid = new TetrisGrid(block);
        level = 1;
        levelspeed = 1;
        score = 0;
        i = (int)random.Next(7) + 1;
        i2 = (int)random.Next(7) + 1;
        blockcounter = 1;

        blocks = new BlockList(block, Content);          //Voegen de verschillende blockobjecten toe aan de lijst
        block1 = new Block1(block, Content);
        blocks.Add(block1, 1);
        block2 = new Block2(block, Content);
        blocks.Add(block2, 2);
        block3 = new Block3(block, Content);
        blocks.Add(block3, 3);
        block4 = new Block4(block, Content);
        blocks.Add(block4, 4);
        block5 = new Block5(block, Content);
        blocks.Add(block5, 5);
        block6 = new Block6(block, Content);
        blocks.Add(block6, 6);
        block7 = new Block7(block, Content);
        blocks.Add(block7, 7);

        //Voegen de verschillende blockobjecten toe aan een tweede lijst voor het tekenen van het volgende blokje
        block1res = new Block1(block, Content);
        blocks.AddToReserve(block1res, 1);
        block2res = new Block2(block, Content);
        blocks.AddToReserve(block2res, 2);
        block3res = new Block3(block, Content);
        blocks.AddToReserve(block3res, 3);
        block4res = new Block4(block, Content);
        blocks.AddToReserve(block4res, 4);
        block5res = new Block5(block, Content);
        blocks.AddToReserve(block5res, 5);
        block6res = new Block6(block, Content);
        blocks.AddToReserve(block6res, 6);
        block7res = new Block7(block, Content);
        blocks.AddToReserve(block7res, 7);

        options = new Options(block, reset, backButton, width, height, font, blocks);
        menu = new Menu(playButton, optionsButton, polytris, width, height);
        gameOver = new GameOver(backButton, width, height);
    }
 protected void Page_Load(object sender, EventArgs e)
 {
     Block1.DataBind();
     if (!this.IsPostBack)
     {
         ViewState["LoginErrors"] = 0;
     }
 }
Exemplo n.º 9
0
 public CharacterInfo()
 {
     Block1  = new Block1();
     Block2  = new Block2();
     Block3  = new Block3();
     XAdjust = 0;
     YAdjust = 0;
     Trailer = 0xFFFF;
 }
Exemplo n.º 10
0
 void HideBlock()
 {
     Block1.Hide();
     Block2.Hide();
     Block3.Hide();
     Block4.Hide();
     Block5.Hide();
     Block6.Hide();
     Block7.Hide();
     Block8.Hide();
     Block9.Hide();
     Block10.Hide();
 }
Exemplo n.º 11
0
    public GameObject CreateBlock(int x, int y, int z, Block1 b)
    {
        GameObject go = Instantiate(blockPrefab) as GameObject;

        go.GetComponent <Renderer>().material = blockMaterials[(int)b.color];
        go.transform.localScale = Vector3.one * blocksize;

        b.blockTransform = go.transform;
        blocks[x, y, z]  = b;

        PositionBlock(b.blockTransform, new Vector3(x, y, z));
        return(go);
    }
Exemplo n.º 12
0
 public int[,] createBlock()
 {
     if (r.Next(7) == 0)
     {
         Block1 newArray = new Block1();
         currentBlock = newArray.getArray();
         currentColor = Color.Cyan;
     }
     else if (r.Next(7) == 1)
     {
         Block2 newArray = new Block2();
         currentBlock = newArray.getArray();
         currentColor = Color.CornflowerBlue;
     }
     else if (r.Next(7) == 2)
     {
         Block3 newArray = new Block3();
         currentBlock = newArray.getArray();
         currentColor = Color.Orange;
     }
     else if (r.Next(7) == 3)
     {
         Block4 newArray = new Block4();
         currentBlock = newArray.getArray();
         currentColor = Color.Yellow;
     }
     else if (r.Next(7) == 4)
     {
         Block5 newArray = new Block5();
         currentBlock = newArray.getArray();
         currentColor = Color.LimeGreen;
     }
     else if (r.Next(7) == 5)
     {
         Block6 newArray = new Block6();
         currentBlock = newArray.getArray();
         currentColor = Color.Purple;
     }
     else
     {
         Block7 newArray = new Block7();
         currentBlock = newArray.getArray();
         currentColor = Color.Red;
     }
     return(currentBlock);
 }
Exemplo n.º 13
0
        public void Mine()
        {
            var codec = new Codec();

            HashAlgorithmType sha256 = HashAlgorithmType.Of <SHA256>();
            PreEvaluationBlock <Arithmetic> preEvalBlock = Genesis.Mine(sha256);

            Assert.True(ByteUtil.Satisfies(preEvalBlock.PreEvaluationHash, Genesis.Difficulty));
            AssertBytesEqual(
                sha256.Digest(codec.Encode(Genesis.MakeCandidateData(preEvalBlock.Nonce))),
                preEvalBlock.PreEvaluationHash.ToArray()
                );

            HashAlgorithmType sha512 = HashAlgorithmType.Of <SHA512>();

            preEvalBlock = Block1.Mine(sha512);
            Assert.True(ByteUtil.Satisfies(preEvalBlock.PreEvaluationHash, Block1.Difficulty));
            AssertBytesEqual(
                sha512.Digest(codec.Encode(Block1.MakeCandidateData(preEvalBlock.Nonce))),
                preEvalBlock.PreEvaluationHash.ToArray()
                );
        }
Exemplo n.º 14
0
        public static async Task Validate(Transaction transaction)
        {
            var transactionStrings = JsonConvert.SerializeObject(transaction, Formatting.Indented);

            Console.WriteLine($"New Transaction : {transactionStrings} \n");

            float moneyLeft = 999999999.00f;
            User  fromUser  = new User();

            if (!IsDonatable)
            {
                fromUser  = _dbContext.Users.FirstOrDefault(x => x.Username == transaction.FromAddress);
                moneyLeft = fromUser.RemainingMoney;
            }

            if (moneyLeft < transaction.Amount)
            {
                Console.WriteLine("Money Not Enough!");
            }
            else
            {
                if (!IsDonatable)
                {
                    Console.WriteLine("User's Money : " + JsonConvert.SerializeObject(fromUser));
                    fromUser.RemainingMoney -= transaction.Amount;
                }

                transaction.HashedTransactionId = _hash.HashTransaction(transaction);
                var serializedTransaction = JsonConvert.SerializeObject(transaction);
                Client.Broadcast($"Verify : {serializedTransaction}");

                while (ConfirmedNumber < RequiredNumber() && ConfirmedNumber + RejectedNumber < NumNode)
                {
                    await Task.Delay(1000);
                }

                if (ConfirmedNumber < RequiredNumber())
                {
                    Console.WriteLine("Rejected Transaction.....");
                    ConfirmedNumber = 1;
                    RejectedNumber  = 0;
                }
                else
                {
                    var blockCharName = _dbContext.Foundations.OrderBy(x => x.NameEn).LastOrDefault()?.NameEn;

                    if (transaction.ToAddress == blockCharName)
                    {
                        var foundations         = _dbContext.Foundations.FirstOrDefault(x => x.NameEn == transaction.ToAddress);
                        var donatedTransactions = _dbContext.Transactions
                                                  .Where(x => x.IntendedFoundation == blockCharName)
                                                  .ToList();

                        foundations.TotalDonate  += foundations.TotalUnDonate;
                        foundations.TotalUnDonate = 0;

                        donatedTransactions.ForEach(x => x.IsDonated = true);
                        transaction.IsDonated = true;
                    }
                    else
                    {
                        var foundations = _dbContext.Foundations.FirstOrDefault(x => x.NameEn == transaction.IntendedFoundation);
                        foundations.TotalUnDonate += transaction.Amount;
                        transaction.FromAddress    = _hash.CalculateHash(transaction.FromAddress);
                    }

                    // foundations.TotalDonate += transaction.Amount;
                    _dbContext.Transactions.Add(transaction);
                    _dbContext.SaveChanges();

                    ConfirmedNumber = 1;
                    RejectedNumber  = 0;
                    Console.WriteLine("Added Transaction.....");
                    await Task.Delay(5000);

                    BlockGeneric block;
                    BlockGeneric prevBlock;
                    if (Program.Port == 2222)
                    {
                        block     = new Block1();
                        prevBlock = _dbContext.Blockchains1
                                    .OrderBy(x => x.UnixTimeStamp)
                                    .LastOrDefault();
                    }
                    else if (Program.Port == 2223)
                    {
                        block     = new Block2();
                        prevBlock = _dbContext.Blockchains2
                                    .OrderBy(x => x.UnixTimeStamp)
                                    .LastOrDefault();
                    }
                    else
                    {
                        block     = new Block3();
                        prevBlock = _dbContext.Blockchains3
                                    .OrderBy(x => x.UnixTimeStamp)
                                    .LastOrDefault();
                    }

                    var transactions = _dbContext.Transactions
                                       .Where(x => !x.IsCommitted)
                                       .OrderBy(x => x.UnixTimeStamp)
                                       .Take(block.MaxBlockSize)
                                       .ToList();

                    var hashedTransactions = String.Join('-', transactions.Select(x => x.HashedTransactionId));

                    block.HashedTransactionIds = hashedTransactions;
                    block.Height           = (prevBlock?.Height + 1) ?? 0;
                    block.PreviousHash     = prevBlock?.Hash;
                    block.TransactionJsons = transactions != null?JsonConvert.SerializeObject(transactions) : null;

                    block.UnixTimeStamp = DateTime.Now.ToUnixTimeStamp();
                    block.Hash          = _hash.HashBlock(block);
                    block.VerifiedBy    = _hash.CalculateHash(Program.Port.ToString());
                    block.BlockSize     = transactions.Count;

                    transactions.ForEach(x => x.BlockHeight = block.Height);

                    var serializedBlock = JsonConvert.SerializeObject(block, Formatting.Indented);
                    Console.WriteLine($"Transaction inside \n {JsonConvert.SerializeObject(transactions, Formatting.Indented)}");
                    Console.WriteLine($"BlockSize : {block.BlockSize}");
                    Console.WriteLine($"Block : {serializedBlock}\n");
                    Client.Broadcast($"New Block : {serializedBlock}");

                    while (ConfirmedNumber < RequiredNumber() && ConfirmedNumber + RejectedNumber < NumNode)
                    {
                        await Task.Delay(30);
                    }

                    if (ConfirmedNumber < RequiredNumber())
                    {
                        Console.WriteLine("Rejected Block.....");
                    }
                    else
                    {
                        Console.WriteLine("Added Block.....");
                        transactions.ForEach(x => x.IsCommitted = true);

                        if (Program.Port == 2222)
                        {
                            _dbContext.Blockchains1.Add((Block1)block);
                        }

                        else if (Program.Port == 2223)
                        {
                            _dbContext.Blockchains2.Add((Block2)block);
                        }

                        else
                        {
                            _dbContext.Blockchains3.Add((Block3)block);
                        }

                        await _dbContext.SaveChangesAsync();

                        Client.Broadcast($"Add Block to Chain : {JsonConvert.SerializeObject(block)}");
                        PreDonateToFoundationIfAble(transaction);
                    }
                    ConfirmedNumber = 1;
                    RejectedNumber  = 0;
                }
            }
        }
Exemplo n.º 15
0
	public List<Block2> GetData() {
		List<Block2> NewData = new List<Block2>();
		
		for (int i = 0; i < SizeX; i++) 
		{
			Block2 NewBlock2 = new Block2(); 
			for (int j = 0; j < SizeY; j++) 
			{
				Block1 NewBlock1 = new Block1();
				for (int k = 0; k < SizeZ; k++) 
				{
					Block0 NewBlock0 = new Block0();
					NewBlock0.SetType(Data[i].Data[j].Data[k].Type);
					NewBlock0.SetIsActivated(Data[i].Data[j].Data[k].IsActivated);
					NewBlock1.AddData(NewBlock0);
				}
				NewBlock2.AddData(NewBlock1);
			}
			NewData.Add(NewBlock2);
		}
		return NewData;
	}
Exemplo n.º 16
0
	public void InitilizeData() {
		ClearData ();
		for (int i = 0; i < Size.x; i++) 
		{
			Block2 NewBlock2 = new Block2(); 
			for (int j = 0; j < Size.y; j++) 
			{
				Block1 NewBlock1 = new Block1();
				for (int k = 0; k < Size.z; k++) 
				{
					Block0 NewBlock0 = new Block0();
					NewBlock1.AddData(NewBlock0);
				}
				NewBlock2.AddData(NewBlock1);
			}
			Data.Add(NewBlock2);
		}
		for (int i = 0; i < 32; i++) {
			BlockAmounts.Add (0);
		}
	}
Exemplo n.º 17
0
	public void SetBlockData0(Block1 NewBlock1) {
		for (int k = 0; k < Size.z; k++) 
		{
			Block0 NewBlock0 = new Block0();
			NewBlock1.AddData(NewBlock0);
		}
	}
Exemplo n.º 18
0
	public void ExtendStructureX(bool IsBefore) {
		float i = Size.x;
		{
			Block2 NewBlock2 = new Block2(); 
			for (int j = 0; j < Size.y; j++) 
			{
				Block1 NewBlock1 = new Block1();
				for (int k = 0; k < Size.z; k++) 
				{
					Block0 NewBlock0 = new Block0();
					NewBlock1.AddData(NewBlock0);
				}
				NewBlock2.AddData(NewBlock1);
			}
			if (!IsBefore)
				Data.Add(NewBlock2);
			else 
				Data.Insert (0,NewBlock2);
		}
	}
Exemplo n.º 19
0
	public void ExtendStructureY(bool IsBefore) {
		for (int i = 0; i < Data.Count; i++) {
			Block1 NewBlock1 = new Block1();
			for (int j = 0; j < Data[i].GetSize(); j++) {
				Block0 NewBlock0 = new Block0();
				NewBlock1.AddData(NewBlock0);
			}
			if (!IsBefore)
				Data[i].AddData(NewBlock1);
			else 
				Data[i].Insert(0,NewBlock1);
		}
	}
Exemplo n.º 20
0
	public void Insert(int Position, Block1 NewData) {
		Data.Insert (Position, NewData);
	}
Exemplo n.º 21
0
 public void Copy()
 {
     AssertBlockContentsEqual(Genesis, Genesis.Copy());
     AssertBlockContentsEqual(Block1, Block1.Copy());
     AssertBlockContentsEqual(BlockPv0, BlockPv0.Copy());
 }
Exemplo n.º 22
0
        public ActionResult Login(FormCollection frm)
        {
            string  UserName = frm["username"].ToString();
            Account acc      = db.Accounts.Where(p => p.UserName == UserName && p.Role_Account.FirstOrDefault().Role_ID == 1).SingleOrDefault();

            if (acc != null)
            {
                bool Pass = HashPwdTool.CheckPassword(frm["password"].ToString(), acc.PasswordHash);
                if (Pass)
                {
                    Employee emp = db.Employees.Where(p => p.Account.Account_ID == acc.Account_ID).SingleOrDefault();
                    if (emp.Quits == null && (emp.Block1.LastOrDefault() == null || (emp.Block1.LastOrDefault() != null && (emp.Block1.LastOrDefault().UnBlockDate == null || emp.Block1.LastOrDefault().UnBlockDate <= DateTime.Now))))
                    {
                        db.USP_InsertAccountLog(acc.Account_ID);
                        Session["AccountUser"] = UserName;
                        Session["ID_User"]     = emp.Employee_ID;
                        Session["ID_Acc"]      = acc.Account_ID;
                        Session["Avatar"]      = "/Images/Employee/" + emp.Avatar_URL;

                        return(RedirectToAction("Index", "Home"));
                    }

                    else
                    {
                        Block1 bl = db.Block1.Where(p => p.Employee.Employee_ID == emp.Employee_ID).OrderByDescending(p => p.ModifiedDate).FirstOrDefault();
                        if (bl != null)
                        {
                            if (bl.UnBlockDate <= DateTime.Now)
                            {
                                BlockEmployee.UnBlockEmp(emp.Employee_ID);
                                db.USP_InsertAccountLog(acc.Account_ID);
                                Session["AccountUser"] = UserName;
                                Session["ID_User"]     = emp.Employee_ID; Session["Avatar"] = "/Images/Employee/" + emp.Avatar_URL;
                                Session["ID_Acc"]      = acc.Account_ID;
                                return(RedirectToAction("Index", "Home"));
                            }
                            else
                            {
                                ModelState.AddModelError("", "Login Failed! Account is lock");
                            }
                        }
                        else
                        {
                            db.USP_InsertAccountLog(acc.Account_ID);
                            Session["AccountUser"] = UserName;
                            Session["ID_User"]     = emp.Employee_ID; Session["Avatar"] = "/Images/Employee/" + emp.Avatar_URL;
                            Session["ID_Acc"]      = acc.Account_ID;
                            return(RedirectToAction("Index", "Home"));
                        }
                    }
                }



                else
                {
                    ModelState.AddModelError("", "Login Failed! Username or Password is wrong");
                }
            }
            else
            {
                ModelState.AddModelError("", "Login Failed! Account is not Admin");
            }
            return(View());
        }
Exemplo n.º 23
0
    protected void Page_Load(object sender, EventArgs e)
    {
        Block1.DataBind();
        loginblock.DataBind();
        try
        {
            //  Block3.DataBind();
            if (!this.IsPostBack)
            {
                ViewState["LoginErrors"] = 0;
                if (Session["clients"] != null)
                {
                    LinkButton lnkuser2 = loginblock.ContentPlaceholder.Controls[0].FindControl("LinkButton2") as LinkButton;
                    LinkButton lnkuser  = loginblock.ContentPlaceholder.Controls[0].FindControl("LinkButton3") as LinkButton;
                    LinkButton lnkuser1 = loginblock.ContentPlaceholder.Controls[0].FindControl("LinkButton1") as LinkButton;
                    lnkuser.Text     = "HELLO:   " + (string)(Session["clients"]);
                    lnkuser2.Visible = true;
                    lnkuser1.Visible = false;
                    lnkuser.Visible  = true;
                }
                else
                {
                    LinkButton lnkuser1 = loginblock.ContentPlaceholder.Controls[0].FindControl("LinkButton1") as LinkButton;
                    LinkButton lnkuser2 = loginblock.ContentPlaceholder.Controls[0].FindControl("LinkButton2") as LinkButton;
                    LinkButton lnkuser  = loginblock.ContentPlaceholder.Controls[0].FindControl("LinkButton3") as LinkButton;
                    lnkuser2.Visible = false;
                    lnkuser1.Visible = true;
                    lnkuser.Visible  = false;
                }

                if (Session["USERS"] != null)
                {
                    LinkButton lnkuser1 = Block1.ContentPlaceholder.Controls[0].FindControl("linkAdmin") as LinkButton;
                    LinkButton lnkuser2 = Block1.ContentPlaceholder.Controls[0].FindControl("linkBack") as LinkButton;
                    LinkButton lnkuser3 = Block1.ContentPlaceholder.Controls[0].FindControl("linkSignOut") as LinkButton;
                    lnkuser1.Text    = "HELLO [Admin]:   " + (string)(Session["USERS"]);
                    lnkuser1.Visible = true;
                    lnkuser2.Visible = true;
                    lnkuser3.Visible = true;

                    Login log = Block1.ContentPlaceholder.Controls[0].FindControl("Login1") as Login;
                    log.Visible = false;
                }
                if (Session["USERS"] == null)
                {
                    LinkButton lnkuser1 = Block1.ContentPlaceholder.Controls[0].FindControl("linkAdmin") as LinkButton;
                    LinkButton lnkuser2 = Block1.ContentPlaceholder.Controls[0].FindControl("linkBack") as LinkButton;
                    LinkButton lnkuser3 = Block1.ContentPlaceholder.Controls[0].FindControl("linkSignOut") as LinkButton;
                    lnkuser1.Visible = false;
                    lnkuser2.Visible = false;
                    lnkuser3.Visible = false;

                    Login log = Block1.ContentPlaceholder.Controls[0].FindControl("Login1") as Login;
                    log.Visible = true;
                }
            }
        }
        catch (Exception)
        {
            //Response.Redirect("Default.aspx");
        }
    }
Exemplo n.º 24
0
 public bool IsValidFormat() =>
 Block1?.IsValidFormat() == true &&
 Block2?.IsValidFormat() == true &&
 Metadata?.IsValidFormat() == true;
Exemplo n.º 25
0
    private void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            if (es.IsPointerOverGameObject())// detect whether the player is clicking/touching a GUI button that happens to be over the game object
            {
                return;
            }

            RaycastHit hit;
            if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 30.0f))
            {
                /* if (hit.transform.gameObject != foundationObject)
                 * {
                 *   Vector3 blockPostion = hit.transform.position;
                 *   BlockCollision c = 0;
                 *
                 *   if (hit.point.x - blockPostion.x == 0.5f)
                 *       c |= BlockCollision.Right;
                 *   else if (hit.point.x - blockPostion.x == -0.5f)
                 *       c |= BlockCollision.Left;
                 *   else if (hit.point.z - blockPostion.x == 0.5f)
                 *       c |= BlockCollision.Forward;
                 *   else if (hit.point.z - blockPostion.x == -0.5f)
                 *       c |= BlockCollision.Backward;
                 *   else if (hit.point.y - blockPostion.x == 0.5f)
                 *       c |= BlockCollision.Up;
                 *   else c |= BlockCollision.Down;
                 * }*/

                //go.transform.position = hit.point;


                if (isDeleting)
                {
                    if (hit.transform.name != "Foundation")
                    {
                        Vector3     oldCubeIndex  = BlockPosition(hit.point - (hit.normal * blocksize));
                        BlockColor1 previousColor = blocks[(int)oldCubeIndex.x, (int)oldCubeIndex.y, (int)oldCubeIndex.z].color;
                        Destroy(blocks[(int)oldCubeIndex.x, (int)oldCubeIndex.y, (int)oldCubeIndex.z].blockTransform.gameObject);
                        blocks[(int)oldCubeIndex.x, (int)oldCubeIndex.y, (int)oldCubeIndex.z] = null;

                        previewAction = new BlockAction1
                        {
                            delete = true,
                            index  = oldCubeIndex,
                            color  = previousColor
                        };
                    }

                    return;
                }
                Vector3 index = BlockPosition(hit.point);

                int x = (int)index.x
                , y   = (int)index.y
                , z   = (int)index.z;

                if (blocks[x, y, z] == null)
                {
                    GameObject go = CreateBlock();

                    PositionBlock(go.transform, index);
                    blocks[x, y, z] = new Block1
                    {
                        blockTransform = go.transform,
                        color          = selectedColor
                    };

                    previewAction = new BlockAction1
                    {
                        delete = false,
                        index  = new Vector3(x, y, z),
                        color  = selectedColor
                    };
                }
                else
                {
                    //Debug.Log("Eroor: clicking inside of a cube at position" + index.ToString());
                    GameObject go = CreateBlock();

                    Vector3 newIndex = BlockPosition(hit.point + (hit.normal) * blocksize);

                    blocks[(int)newIndex.x, (int)newIndex.y, (int)newIndex.z] = new Block1
                    {
                        blockTransform = go.transform,
                        color          = selectedColor
                    };

                    PositionBlock(go.transform, newIndex);

                    previewAction = new BlockAction1
                    {
                        delete = false,
                        index  = newIndex,
                        color  = selectedColor
                    };
                }
            }
        }
    }
Exemplo n.º 26
0
	public void AddData(Block1 NewData) {
		Data.Add (NewData);
	}