Official Everybody Edits Forums

Do you think I could just leave this part blank and it'd be okay? We're just going to replace the whole thing with a header image anyway, right?

You are not logged in.

#1 2015-05-13 11:58:09, last edited by 1448 (2015-05-14 09:21:30)

1448
Formerly alkazam1448
From: Numberland
Joined: 2015-04-12
Posts: 683
Website

[Question] Dig code

Edit: Tried a dig code, didn't work. Here's my current code:

case "m":
                try
                {
                    string mover = Players[m.GetInt(0)];
                    int leftOrRight = m.GetInt(7); //-1 left, 1 right
                    int upOrDown = m.GetInt(8);//-1 up, 1 down
                    int xPlayer = (int)m.GetDouble(1);
                    int yPlayer = (int)m.GetDouble(2);
                    BlockTracker bt;
                    if (checkBox1.Checked)
                    {
                        if (leftOrRight == -1 && RoomData[0, xPlayer - 1, yPlayer] == 16)
                        {
                            bt = new BlockTracker(xPlayer - 1, yPlayer);
                            bt.hp--;
                            if (bt.hp == 0)
                            {
                                conn.Send(bldatm, xPlayer - 1, yPlayer, 4);
                                points[mover]++;
                            }
                        }
                        if (leftOrRight == 1 && RoomData[0, xPlayer + 1, yPlayer] == 16)
                        {
                            bt = new BlockTracker(xPlayer + 1, yPlayer);
                            bt.hp--;
                            if (bt.hp == 0)
                            {
                                conn.Send(bldatm, xPlayer + 1, yPlayer, 4);
                                points[mover]++;
                            }
                        }
                        if (upOrDown == -1 && RoomData[0, xPlayer, yPlayer + 1] == 16)
                        {
                            bt = new BlockTracker(xPlayer, yPlayer + 1);
                            bt.hp--;
                            if (bt.hp == 0)
                            {
                                conn.Send(bldatm, xPlayer, yPlayer + 1, 0);
                                points[mover]++;
                            }
                        }
                        if (upOrDown == 1 && RoomData[0, xPlayer, yPlayer - 1] == 16)
                        {
                            bt = new BlockTracker(xPlayer, yPlayer - 1);
                            bt.hp--;
                            if(bt.hp == 0)
                            {
                                conn.Send(bldatm, xPlayer, yPlayer - 1, 0);
                                points[mover]++;
                            }
                        }
                    }
                }
                catch { }
                break;

BlockTracker.cs (I know this is unnecessary, but I made a class)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Forms_Bot_Rebuild
{
    class BlockTracker
    {
        private int _X;
        private int _Y;
        private int _Hp = 5;
        public BlockTracker(int x, int y)
        {
            _X = x;
            _Y = y;
        }

        public int x
        {
            get
            {
                return _X;
            }
            set
            {
                _Y = value;
            }
        }
        public int y
        {
            get
            {
                return _Y;
            }
            set
            {
                _Y = value;
            }
        }
        public int hp
        {
            get
            {
                return _Hp;
            }
            set
            {
                _Hp = value;
            }
        }
    }
}

Doesn't work. Please help.

Offline

#2 2015-05-13 13:16:42

den3107
Member
From: Netherlands
Joined: 2015-04-24
Posts: 1,025

Re: [Question] Dig code

Just check when somebody moves, which direction it is and if the direction he's wishing to go is against a block. Do minHp() and make sure you handle some sort of event once hp has reached 0.

Offline

#3 2015-05-13 13:21:15, last edited by Zumza (2015-05-13 13:21:31)

Zumza
Member
From: root
Joined: 2015-02-17
Posts: 4,656

Re: [Question] Dig code

BTW did you heard about c# accessors?


Everybody edits, but some edit more than others

Offline

#4 2015-05-13 13:39:30

1448
Formerly alkazam1448
From: Numberland
Joined: 2015-04-12
Posts: 683
Website

Re: [Question] Dig code

What's a C# accessor?

Offline

#5 2015-05-13 15:06:54

SmittyW
Member
Joined: 2015-03-13
Posts: 2,085

Re: [Question] Dig code

alkazam1448 wrote:

What's a C# accessor?

He's talking about properties and get/set accessors, which you could use to replace your class methods.

Here's more info about properties:
http://www.dotnetperls.com/property

Offline

#6 2015-05-14 17:15:04

1448
Formerly alkazam1448
From: Numberland
Joined: 2015-04-12
Posts: 683
Website

Re: [Question] Dig code

Ok I made a dig code which I made myself, but it didn't work. Help appreciated //forums.everybodyedits.com/img/smilies/smile

Offline

#7 2015-05-14 17:44:01, last edited by SmittyW (2015-05-14 17:44:43)

SmittyW
Member
Joined: 2015-03-13
Posts: 2,085

Re: [Question] Dig code

I'm not  sure if this is right, but I think the problem is that you keep creating a new BlockTracker so that every time you try digging, the block's health resets to 5. You should try storing your blocks into an array and then check if the spot you are digging in has already been added. If not, then create a new BlockTracker with those coordinates. Then if it reaches 0, remove that block.

Offline

#8 2015-05-15 04:25:55

1448
Formerly alkazam1448
From: Numberland
Joined: 2015-04-12
Posts: 683
Website

Re: [Question] Dig code

Didn't quite get ya.

Offline

#9 2015-05-15 08:09:01

den3107
Member
From: Netherlands
Joined: 2015-04-24
Posts: 1,025

Re: [Question] Dig code

alkazam1448 wrote:

Didn't quite get ya.

Everytime a person hits a block, you give that block a new blocktracker, starting it off at 5hp again.

What what I would personally do is include the hp into you Block object instead of making a new class which tracks the blocks POSITION seperatly.
I think you can also more easily add seperate hp values per block type if you'd do it this way.

Offline

den31071431673741504982

Board footer

Powered by FluxBB

[ Started around 1732796627.4343 - Generated in 0.081 seconds, 11 queries executed - Memory usage: 1.44 MiB (Peak: 1.58 MiB) ]