Ejemplo n.º 1
0
 private void button2_Click(object sender, EventArgs e)
 {
     if (head.y != body[0].y - 1)
     {
         direction = _direction.UP;
     }
 }
Ejemplo n.º 2
0
 private void button4_Click(object sender, EventArgs e)
 {
     if (head.y != body[0].y + 1)
     {
         direction = _direction.DOWN;
     }
 }
Ejemplo n.º 3
0
 private void button3_Click(object sender, EventArgs e)
 {
     if (head.x != body[0].x - 1)
     {
         direction = _direction.LEFT;
     }
 }
Ejemplo n.º 4
0
 public void Reset()
 {
     Body = new List <Block>();
     Body.Add(new Block(Color.Red, GameConfig.BlockSize, new Point(r.Next((int)GameConfig.MapSize), r.Next((int)GameConfig.MapSize))));
     Direction    = _direction.Down;
     OldDirection = Direction;
 }
Ejemplo n.º 5
0
 private void button5_Click(object sender, EventArgs e)
 {
     if (head.x != body[0].x + 1)
     {
         direction = _direction.RIGHT;
     }
 }
 void SetDirection(_direction changeDir)
 {
     foreach (GameObject go in animObjects)
     {
         go.GetComponent <Animator>().SetInteger("Direction", (int)changeDir);
     }
 }
Ejemplo n.º 7
0
    // Update is called once per frame
    void Update()
    {
        if (lastChange < Time.time)
        {
            foreach (GameObject go in animObjects)
            {
                go.GetComponent <Animator>().SetInteger("Direction", (int)Dir);
                go.GetComponent <Animator>().SetInteger("Action", (int)Act);
                go.GetComponent <Animator>().SetBool("ChangeAnim", true);
            }

            lastChange = Time.time + 3f;

            Dir++;

            if ((int)Dir > 3)
            {
                Dir = 0;
                Act++;

                if ((int)Act > 4)
                {
                    Act = 0;
                }
            }
        }
    }
Ejemplo n.º 8
0
 private void ChooseStartDirection()
 {
     if (UnityEngine.Random.Range(0, 2) == 1)
     {
         direction = _direction.right;
     }
     else
     {
         direction = _direction.left;
         Turn();
     }
 }
Ejemplo n.º 9
0
    public void DirectedMove()
    {
        switch (_currentDir)
        {
        case _direction.Up:
            if (Neighbour(0, 1) == null || !_colStorage.CheckTags(Neighbour(0, 1).tag))
            {
                _grid.Move(_grid.findLocation(gameObject) + new Vector2(0, 1), gameObject);
                gameObject.transform.Translate(new Vector2(0, 1));
            }
            else
            {
                _currentDir = _direction.Down;
            }
            break;

        case _direction.Down:
            if (Neighbour(0, -1) == null || !_colStorage.CheckTags(Neighbour(0, -1).tag))
            {
                _grid.Move(_grid.findLocation(gameObject) + new Vector2(0, -1), gameObject);
                gameObject.transform.Translate(new Vector2(0, -1));
            }
            else
            {
                _currentDir = _direction.Up;
            }
            break;

        case _direction.Left:
            if (Neighbour(-1, 0) == null || !_colStorage.CheckTags(Neighbour(-1, 0).tag))
            {
                _grid.Move(_grid.findLocation(gameObject) + new Vector2(-1, 0), gameObject);
                gameObject.transform.Translate(new Vector2(-1, 0));
            }
            else
            {
                _currentDir = _direction.Right;
            }
            break;

        case _direction.Right:
            if (Neighbour(1, 0) == null || !_colStorage.CheckTags(Neighbour(1, 0).tag))
            {
                _grid.Move(_grid.findLocation(gameObject) + new Vector2(1, 0), gameObject);
                gameObject.transform.Translate(new Vector2(1, 0));
            }
            else
            {
                _currentDir = _direction.Left;
            }
            break;
        }
    }
Ejemplo n.º 10
0
 public void Turn()
 {
     direction = (direction == _direction.right) ? _direction.left : _direction.right;
     if (direction == _direction.right)
     {
         directionVector = Vector3.right;
     }
     else
     {
         directionVector = -Vector3.right;
     }
     GetComponent <Rigidbody>().velocity = directionVector * velocityMagnitude;
 }
Ejemplo n.º 11
0
    private void Start()
    {
        _colStorage = new CollisionStorage();

        if (_initalDir == 1)
        {
            _currentDir = _direction.Up;
        }
        else
        {
            _currentDir = _direction.Left;
        }
    }
Ejemplo n.º 12
0
      public void form1_keydown(object sender, KeyEventArgs e)
      {
          switch (e.KeyCode)
          {
          case Keys.A:
              direction = _direction.LEFT; break;

          case Keys.S:
              direction = _direction.DOWN; break;

          case Keys.D:
              direction = _direction.RIGHT; break;

          case Keys.W:
              direction = _direction.UP; break;
          }
      }
Ejemplo n.º 13
0
    private void getFloor(_direction dir)
    {
        switch (dir)
        {
        case _direction.up:
            if (rayCaster(Vector3.up))
            {
                CalculateMove(floorObject);
            }
            break;

        case _direction.down:
            if (rayCaster(Vector3.down))
            {
                CalculateMove(floorObject);
            }
            break;
        }
    }
Ejemplo n.º 14
0
    public void DirectedMove()
    {
        switch (_currentDir)
        {
        case _direction.Up:
            if (_colStorage.CheckTags(Neighbour(0, 1).tag))
            {
                _grid.Move(_grid.findLocation(gameObject) + new Vector2(0, 1), gameObject);
                _currentDir = _direction.Down;
            }
            break;

        case _direction.Down:
            if (_colStorage.CheckTags(Neighbour(0, -1).tag))
            {
                _grid.Move(_grid.findLocation(gameObject) + new Vector2(0, -1), gameObject);
                _currentDir = _direction.Up;
            }
            break;

        case _direction.Left:
            if (_colStorage.CheckTags(Neighbour(-1, 0).tag))
            {
                _grid.Move(_grid.findLocation(gameObject) + new Vector2(-1, 0), gameObject);
                _currentDir = _direction.Right;
            }
            break;

        case _direction.Right:
            if (_colStorage.CheckTags(Neighbour(1, 0).tag))
            {
                _grid.Move(_grid.findLocation(gameObject) + new Vector2(1, 0), gameObject);
                _currentDir = _direction.Left;
            }
            break;
        }
    }
Ejemplo n.º 15
0
    // Update is called once per frame
    void Update()
    {
        if (lastChange < Time.time)
        {
            GetComponent <Animator>().SetInteger("Direction", (int)Dir);
            GetComponent <Animator>().SetInteger("Action", (int)Act);
            GetComponent <Animator>().SetBool("ChangeAnim", true);

            lastChange = Time.time + 3f;

            Dir++;

            if ((int)Dir > 3)
            {
                Dir = 0;
                Act++;

                if ((int)Act > 4)
                {
                    Act = 0;
                }
            }
        }
    }
Ejemplo n.º 16
0
      public void play()
      {
          int i = 0, c = 0, d = 0;

          temp = head;

          while (true)  //苹果位置
          {
              if (growed)
              {
                  break;
              }
              Random rand = new Random();
              apple.x = rand.Next(1, map_length);
              apple.y = rand.Next(1, map_height);
              growed  = true;
              if (!apple_check())
              {
                  break;
              }
          }
          predirect = checkdirection();
          switch (predirect)
          {
          case _direction.DOWN: if (head.y == map_height)
              {
                  head.y = 1;
              }
              else
              {
                  head.y += 1;
              } break;

          case _direction.LEFT: if (head.x == 1)
              {
                  head.x = map_length;
              }
              else
              {
                  head.x -= 1;
              } break;

          case _direction.UP: if (head.y == 1)
              {
                  head.y = map_height;
              }
              else
              {
                  head.y -= 1;
              } break;

          case _direction.RIGHT: if (head.x == map_length)
              {
                  head.x = 1;
              }
              else
              {
                  head.x += 1;
              } break;

          default: break;
          }
          //尾巴
          if (head.x == apple.x && head.y == apple.y)
          {
              grow();
          }

          for (i = 0; i < body.Count; i++)
          {
              point trans;
              trans   = body[i];
              body[i] = temp;
              temp    = trans;
          }
          d = body[body.Count - 1].x - 1 + map_length * ((body[body.Count - 1].y - 1)); //
          //尾巴
          //判定
          for (i = 0; i < body.Count; i++)
          {
              if (head.x == body[i].x && head.y == body[i].y)
              {
                  Invoke(new MethodInvoker(delegate() { stop(); label101.Text = "you lose"; }));
              }
          }

          //判定


          for (i = 0; i < body.Count; i++)
          {
              c = map_length * (body[i].y - 1) + body[i].x - 1;
              board[c].Image = Image.FromFile(Application.StartupPath + "\\snake\\body.jpg");
          }
          c = map_length * (apple.y - 1) + apple.x - 1;
          board[c].Image = Image.FromFile(Application.StartupPath + "\\snake\\body.jpg");
          c = map_length * (head.y - 1) + head.x - 1;
          board[c].Image = Image.FromFile(Application.StartupPath + "\\snake\\head.jpg");
          board[d].Image = null;
      }
Ejemplo n.º 17
0
        public List <Block> Move()
        {
            Block head = Body[0];
            Point Next = new Point(head.Point.X, head.Point.Y);

            switch (Direction)
            {
            case _direction.Down:
            {
                Next.Y += 1;
                break;
            }

            case _direction.Up:
            {
                Next.Y -= 1;
                break;
            }

            case _direction.Left:
            {
                Next.X -= 1;
                break;
            }

            case _direction.Right:
            {
                Next.X += 1;
                break;
            }
            }

            if (Next.X < 0 || Next.Y < 0 || Next.X >= (int)GameConfig.MapSize || Next.Y >= (int)GameConfig.MapSize)
            {
                GameConfig.GameOver  = true;
                GameConfig.GameStart = false;
            }

            if (InBody(Next))
            {
                GameConfig.GameOver  = true;
                GameConfig.GameStart = false;
            }

            Block NextBlock = new Block(Color.Red, GameConfig.BlockSize, Next);

            Body.Insert(0, NextBlock);

            //如果没有吃到食物,则尾部减一
            if (Next != Food.block.Point)
            {
                Body.RemoveAt(Body.Count - 1);
            }
            else
            {
                Food.Eaten = true;
            }

            OldDirection = Direction;

            return(Body);
        }
Ejemplo n.º 18
0
 set => SetProperty(ref _direction, value);
Ejemplo n.º 19
0
    public IEnumerator parseLevelFile(string fileName)
    {
        string[] levelData;
        string[] LineSeps = { "\n" };

        if (fileName.Contains("://"))
        {
            WWW www = new WWW(fileName);
            yield return(www);

            levelData = www.text.Split(LineSeps, System.StringSplitOptions.RemoveEmptyEntries);
        }
        else
        {
            levelData = System.IO.File.ReadAllLines(fileName);
        }

        for (int i = 0; i < levelData.Length; i++)
        {
            string key = "";
            string val = "";

            if (levelData[i].Split(seps, System.StringSplitOptions.RemoveEmptyEntries).Length > 1)
            {
                key = levelData[i].Split(seps)[0].TrimStart().ToLower();
            }
            else
            {
                key = levelData[i].TrimStart().TrimEnd().ToLower();
            }
            key = key.Replace(":", "");
            if (levelData[i].Split(seps).Length > 1)
            {
                val = levelData[i].Split(seps)[1].TrimEnd();
            }

            switch (key)
            {
            case "startshards":
                startShards = int.Parse(val);
                break;

            case "attackersletthrough":
                AttackersLetThrough = int.Parse(val);
                break;

            case "isplayerattacker":
                isPlayerAttacker = bool.Parse(val);
                break;

            case "attackerdir":
                if (val.ToLower() == "up")
                {
                    attackerDir = _direction.Up;
                }
                else if (val.ToLower() == "left")
                {
                    attackerDir = _direction.Left;
                }
                else if (val.ToLower() == "down")
                {
                    attackerDir = _direction.Down;
                }
                else if (val.ToLower() == "right")
                {
                    attackerDir = _direction.Right;
                }
                break;

            case "wave":
                i = parseAllWaves(levelData, i + 1);
                break;

            case "wall":
                if (levelData[i].Split(seps).Length > 6)
                {
                    // Wall:Col:StartRow:EndRow:Health:FallPercent:HealthRegen
                    usingWall       = true;
                    wallCol         = int.Parse(levelData[i].Split(seps)[1].ToLower());
                    wallBotRow      = int.Parse(levelData[i].Split(seps)[2].ToLower());
                    wallTopRow      = int.Parse(levelData[i].Split(seps)[3].ToLower());
                    wallHealth      = int.Parse(levelData[i].Split(seps)[4].ToLower());
                    wallFallPercent = float.Parse(levelData[i].Split(seps)[5].ToLower());
                    wallHealthRegen = int.Parse(levelData[i].Split(seps)[6].TrimEnd().ToLower());
                }
                break;

            case "predialogue":
                preLevelDialogue = new List <_statement>();
                i = parseDialogue(levelData, preLevelDialogue, i + 1);
                break;

            case "postdialogue":
                postLevelDialogue = new List <_statement>();
                i = parseDialogue(levelData, postLevelDialogue, i + 1);
                break;

            case "lane":
                Lanes.Add(int.Parse(val));
                if (levelData[i].Split(seps).Length > 2)
                {
                    if (levelData[i].Split(seps)[2].TrimStart().TrimEnd().ToLower() == "disable")
                    {
                        laneEnable.Add(false);
                    }
                    else
                    {
                        laneEnable.Add(true);
                    }
                }
                else
                {
                    laneEnable.Add(true);
                }
                break;

            case "placeable":
                if (levelData[i].Split(seps).Length > 3)
                {
                    _placeable pl = new _placeable();

                    pl.num = int.Parse(val);
                    pl.x   = float.Parse(levelData[i].Split(seps)[2]);
                    pl.y   = float.Parse(levelData[i].Split(seps)[3].TrimEnd());

                    placeables.Add(pl);
                }
                break;

            case "upgradeatwave":
                upgradeAtWave.Add(int.Parse(val));
                break;

            case "firsttimebonus":
                firstTimeBonus = int.Parse(val);
                break;

            case "music":
                backGroundMusic = int.Parse(val);
                break;

            case "allow":
                finaleSpawnables = new string[levelData[i].Split(seps).Length];
                for (int j = 1; j < levelData[i].Split(seps).Length; ++j)
                {
                    finaleSpawnables[j - 1] = levelData[i].Split(seps)[j];
                }
                break;

            case "finale":
                if (levelData[i].Split(seps).Length == 4)
                {
                    int      numOfLines = (int.Parse(levelData[i].Split(seps)[1]) * 4) + 2;
                    string[] finale     = new string[numOfLines];

                    finale[0] = "waittime:" + int.Parse(levelData[i].Split(seps)[2]);
                    finale[numOfLines - 1] = "done";
                    for (int j = 0; j < int.Parse(levelData[i].Split(seps)[1]); ++j)
                    {
                        finale[(j * 4) + 1] = "waveunit:";
                        finale[(j * 4) + 2] = "time:" + int.Parse(levelData[i].Split(seps)[3]) * j;
                        finale[(j * 4) + 3] = "unit:" + finaleSpawnables[Random.Range(0, finaleSpawnables.Length - 1)];
                        finale[(j * 4) + 4] = "spawnloc:randrow";
                        Debug.Log(finale[(j * 4) + 1]);
                        Debug.Log(finale[(j * 4) + 2]);
                        Debug.Log(finale[(j * 4) + 3]);
                        Debug.Log(finale[(j * 4) + 4]);
                    }
                    waveStarted.Add(false);
                    parseWave(finale, 0, waves);
                }
                break;

            default:
                break;
            }
        }
    }
Ejemplo n.º 20
0
 // Use this for initialization
 void Start()
 {
     Dir        = _direction.DirUp;
     Act        = _action.Idle;
     lastChange = -1;
 }