Exemplo n.º 1
0
        private Expression ParseAdditiveExpInternal(Expression arg1)
        {
            if (!new[] { TokenType.ADD, TokenType.SUB }.Contains(PeekType()))
            {
                return(arg1);
            }
            var oper = PeekToken();

            ReadToken();
            var arg2 = ParseMultiplicativeExp();

            var type1 = arg1.Type;
            var type2 = arg2.Type;

            Helper.MakeTypesCompatible(arg1, arg2, out arg1, out arg2);
            Wall.Add(arg1, arg2, type1, type2, oper);

            switch (oper.Type)
            {
            case TokenType.ADD:
                return(ParseAdditiveExpInternal(
                           (arg1.Type.IsString() || arg2.Type.IsString())
                            ? Expression.Add(
                               Expression.Convert(arg1, typeof(object)),
                               Expression.Convert(arg2, typeof(object)),
                               typeof(string).GetMethod("Concat", new[] { typeof(object), typeof(object) }))   // convert string + string into a call to string.Concat
                            : Expression.Add(arg1, arg2)));

            default:
                Debug.Assert(oper.Type == TokenType.SUB);
                return(ParseAdditiveExpInternal(Expression.Subtract(arg1, arg2)));
            }
        }
Exemplo n.º 2
0
    // ロード開始
    public void Load(int stage)
    {
        TMXLoader tmx = new TMXLoader();

        // ファイルパスを作成
        string path = string.Format("Levels/{0:D3}", stage);

        tmx.Load(path);

        // 0番目のレイヤーに情報を取得する
        Layer2D layer = tmx.GetLayer(0);

        // タイルの配置
        for (int j = 0; j < layer.Height; j++)
        {
            for (int i = 0; i < layer.Width; i++)
            {
                // 座標を指定してレイヤーの値を取得
                int   v = layer.Get(i, j);
                float x = GetChipX(i);
                float y = GetChipY(j);

                switch (v)
                {
                case CHIP_PLAYER:
                {
                    // プレイヤを移動させる
                    GameObject obj    = GameObject.Find("Player") as GameObject;
                    Player     player = obj.GetComponent <Player>();
                    player.SetPosition(x, y);
                }
                break;

                case CHIP_WALL:
                    // 壁を作成
                    Wall.Add(x, y);
                    break;

                case CHIP_SPIKE:
                    // トゲを生成
                    Spike.Add(x, y);
                    break;

                case CHIP_FLOOR_MOVE:
                    // 移動床を作成
                    FloorMove.Add(x, y);
                    break;

                case CHIP_GOAL:
                {
                    // ゴールを移動させる
                    GameObject obj  = GameObject.Find("Goal") as GameObject;
                    Goal       goal = obj.GetComponent <Goal>();
                    goal.SetPosition(x, y);
                }
                break;
                }
            }
        }
    }
Exemplo n.º 3
0
        private void AddArenaBoundaries(List <Wall> walls)
        {
            if (this.Arena.ArenaOptions.BoundaryStyle == BoundaryStyle.Walled)
            {
                var thisWall = new Wall();
                for (int i = 0; i < this.Arena.Width; i++)
                {
                    thisWall.Add(new Position(i, 0));
                }
                walls.Add(thisWall);

                thisWall = new Wall();
                for (int i = 0; i < this.Arena.Width; i++)
                {
                    thisWall.Add(new Position(i, this.Arena.Height - 1));
                }
                walls.Add(thisWall);

                thisWall = new Wall();
                for (int i = 0; i < this.Arena.Height; i++)
                {
                    thisWall.Add(new Position(0, i));
                }
                walls.Add(thisWall);

                thisWall = new Wall();
                for (int i = 0; i < this.Arena.Height; i++)
                {
                    thisWall.Add(new Position(this.Arena.Width - 1, i));
                }
                walls.Add(thisWall);
            }
        }
Exemplo n.º 4
0
        public Arena CreateArena(Position playerOnePosition, Position playerTwoPosition, bool AddWalls)
        {
            var players = new Player[]
            {
                new Mock <Player>(Guid.NewGuid().ToString()).Object,
                new Mock <Player>(Guid.NewGuid().ToString()).Object
            };

            players.ElementAt(0).Position = playerOnePosition;
            players.ElementAt(1).Position = playerTwoPosition;
            var arena = new Code.State.Arena
            {
                Height  = 100,
                Width   = 100,
                Players = players,
                Tracks  = new Track[]
                {
                    new Track(players.First()),
                    new Track(players.Last())
                },
            };

            if (AddWalls)
            {
                List <Wall> walls = new List <Wall>();

                var thisWall = new Wall();
                for (int i = 0; i < arena.Width; i++)
                {
                    thisWall.Add(new Position(i, 0));
                }
                walls.Add(thisWall);

                thisWall = new Wall();
                for (int i = 0; i < arena.Width; i++)
                {
                    thisWall.Add(new Position(i, arena.Height));
                }
                walls.Add(thisWall);

                thisWall = new Wall();
                for (int i = 0; i < arena.Height; i++)
                {
                    thisWall.Add(new Position(0, i));
                }
                walls.Add(thisWall);

                thisWall = new Wall();
                for (int i = 0; i < arena.Height; i++)
                {
                    thisWall.Add(new Position(arena.Width, i));
                }
                walls.Add(thisWall);

                arena.Walls = walls;
            }

            return(arena);
        }
Exemplo n.º 5
0
    public void Load(int stage)
    {
        TMXLoader tmx  = new TMXLoader();
        string    path = string.Format("Levels/{0:D3}", stage);

        tmx.Load(path);
        Layer2D layer = tmx.GetLayer(0);

        //Debug.Log ("幅:" + layer.Width);
        //Debug.Log ("高:" + layer.Height);
        for (int j = 0; j < layer.Height; j++)
        {
            for (int i = 0; i < layer.Width; i++)
            {
                int   v = layer.Get(i, j);
                float x = GetChipX(i);
                float y = GetChipY(j);
                switch (v)
                {
                case CHIP_PLAYER:
                {
                    GameObject obj    = GameObject.Find("Player") as GameObject;
                    Player     player = obj.GetComponent <Player> ();
                    player.SetPosition(x, y);
                }
                break;

                case CHIP_WALL:
                    Wall.Add(x, y);
                    break;

                case CHIP_SPIKE:
                    Spike.Add(x, y);
                    break;

                case CHIP_FLOOR_MOVE:
                    FloorMove.Add(x, y);
                    break;

                case CHIP_GOAL:
                {
                    GameObject obj  = GameObject.Find("Goal") as GameObject;
                    Goal       goal = obj.GetComponent <Goal>();
                    goal.SetPosition(x, y);
                }
                break;
                }
            }
        }
    }
Exemplo n.º 6
0
        public Player()
        {
            for (var i = 0; i < 5; i++)
            {
                Rows.Add(new RowToInsert(i + 1));
            }

            var typesAllowed = new List <TileType>
            {
                TileType.Blue,
                TileType.Yellow,
                TileType.Red,
                TileType.Black,
                TileType.Ice
            };

            for (var i = 0; i < 5; i++)
            {
                Wall.Add(typesAllowed.Select(type => new WallTile(type)).ToList());
                typesAllowed.Insert(0, typesAllowed.Last());
                typesAllowed.RemoveAt(typesAllowed.Count - 1);
            }
        }
Exemplo n.º 7
0
    public void InitGrid()
    {
        foreach (Transform child in transform)
        {
            GameObject.Destroy(child.gameObject);
        }

        foreach (Wall wall in GetComponents <Wall>())
        {
            Destroy(wall);
        }

        roundSize = new Vector2Int(size);
        boxes     = new Box[roundSize.x][];

        for (int i = 0; i < roundSize.x; ++i)
        {
            boxes[i] = new Box[roundSize.y];
            for (int j = 0; j < roundSize.y; ++j)
            {
                Box           currentBox         = Instantiate(boxPrefab, this.transform).GetComponent <Box>();
                BoxCollider2D wallpartPrefabSize = wallPartPrefab.GetComponent <BoxCollider2D>();
                currentBox.size = wallpartPrefabSize.bounds.extents.x * 2 + wallpartPrefabSize.bounds.extents.y * 2;
                var collider = currentBox.gameObject.AddComponent <BoxCollider2D>();
                collider.size          = new Vector2(1 * currentBox.size, 1 * currentBox.size);
                collider.isTrigger     = true;
                currentBox._position.x = i;
                currentBox._position.y = j;

                currentBox.transform.position = new Vector2(
                    currentBox._position.x * currentBox.size,
                    currentBox._position.y * currentBox.size);
            }
        }
        Destroy(wallPartPrefab.GetComponent <BoxCollider2D>());
        foreach (Transform child in transform)
        {
            Box box = child.GetComponent <Box>();
            if (box)
            {
                boxes[box._position.x][box._position.y] = box;
            }
        }

        wallPartPrefab.transform.position = boxes[roundSize.x / 2][roundSize.y / 2].transform.position;
        //Debug.Log(wallPartPrefab.transform.position);

        InitWall(ref LeftWall, new Vector2Int(1, 0));
        InitWall(ref RightWall, new Vector2Int(-1, 0));
        InitWall(ref TopWall, new Vector2Int(0, -1));
        InitWall(ref BottomWall, new Vector2Int(0, 1));

        UpdateEditorParamsLists();

        //---------------------------------------------
        // ADDING WALL PARTS TO WALLS
        //---------------------------------------------
        for (int i = 0; i < roundSize.y; ++i)
        {
            // adding wall parts to leftwall
            WallPart currentWallPart = Instantiate(wallPartPrefab, this.transform).GetComponent <WallPart>();
            currentWallPart.transform.position = wallPartPrefab.transform.position;
            currentWallPart.GetComponent <SpriteRenderer>().enabled = true;
            currentWallPart.transform.Rotate(new Vector3(0, 0, 270));
            int moveTo = FindInEditorParameters(EditorLeftWallList, i);
            if (moveTo != -1)
            {
                currentWallPart.box1           = boxes[moveTo][i];
                currentWallPart.box2           = boxes[moveTo - 1][i];
                currentWallPart.box1.wallRight = currentWallPart;
                currentWallPart.box2.wallLeft  = currentWallPart;
            }
            else
            {
                currentWallPart.box1          = boxes[0][i];
                currentWallPart.box1.wallLeft = currentWallPart;
                currentWallPart.box2          = null;
            }
            LeftWall.Add(currentWallPart);
            currentWallPart.UpdateRealPositionSnap();

            // adding wall parts to rightwall
            currentWallPart = Instantiate(wallPartPrefab, this.transform).GetComponent <WallPart>();
            currentWallPart.transform.position = wallPartPrefab.transform.position;
            currentWallPart.GetComponent <SpriteRenderer>().enabled = true;
            currentWallPart.transform.Rotate(new Vector3(0, 0, 90));
            moveTo = FindInEditorParameters(EditorRightWallList, i);
            if (moveTo != -1)
            {
                currentWallPart.box2           = boxes[boxes.Length - moveTo][i];
                currentWallPart.box1           = boxes[boxes.Length - moveTo - 1][i];
                currentWallPart.box1.wallRight = currentWallPart;
                currentWallPart.box2.wallLeft  = currentWallPart;
            }
            else
            {
                currentWallPart.box1           = boxes[boxes.Length - 1][i];
                currentWallPart.box1.wallRight = currentWallPart;
                currentWallPart.box2           = null;
            }

            RightWall.Add(currentWallPart);
            currentWallPart.UpdateRealPositionSnap();
        }

        for (int i = 0; i < roundSize.x; ++i)
        {
            // adding wall parts to topwall
            WallPart currentWallPart = Instantiate(wallPartPrefab, this.transform).GetComponent <WallPart>();
            currentWallPart.transform.position = wallPartPrefab.transform.position;
            currentWallPart.GetComponent <SpriteRenderer>().enabled = true;
            currentWallPart.transform.Rotate(new Vector3(0, 0, 180));
            int moveTo = FindInEditorParameters(EditorTopWallList, i);
            if (moveTo != -1)
            {
                currentWallPart.box2            = boxes[i][boxes[i].Length - moveTo];
                currentWallPart.box1            = boxes[i][boxes[i].Length - moveTo - 1];
                currentWallPart.box1.wallTop    = currentWallPart;
                currentWallPart.box2.wallBottom = currentWallPart;
            }
            else
            {
                currentWallPart.box1         = boxes[i][boxes[i].Length - 1];
                currentWallPart.box1.wallTop = currentWallPart;
                currentWallPart.box2         = null;
            }
            TopWall.Add(currentWallPart);
            currentWallPart.UpdateRealPositionSnap();

            // adding wall parts to bottomwall
            currentWallPart = Instantiate(wallPartPrefab, this.transform).GetComponent <WallPart>();
            currentWallPart.transform.position = wallPartPrefab.transform.position;
            currentWallPart.GetComponent <SpriteRenderer>().enabled = true;
            moveTo = FindInEditorParameters(EditorBottomWallList, i);
            if (moveTo != -1)
            {
                currentWallPart.box1            = boxes[i][moveTo];
                currentWallPart.box2            = boxes[i][moveTo - 1];
                currentWallPart.box1.wallTop    = currentWallPart;
                currentWallPart.box2.wallBottom = currentWallPart;
            }
            else
            {
                currentWallPart.box1            = boxes[i][0];
                currentWallPart.box1.wallBottom = currentWallPart;
                currentWallPart.box2            = null;
            }

            BottomWall.Add(currentWallPart);
            currentWallPart.UpdateRealPositionSnap();
        }
    }
Exemplo n.º 8
0
        public Map(string fMap, string fTower)
        {
            Rectangle a   = new Rectangle();
            string    str = "";

            foreach (char c in fMap)
            {
                if (c == ' ')
                {
                    a.X = Convert.ToInt32(str);
                    str = "";
                }
                else if (c == '\r')
                {
                }
                else if (c == '\n')
                {
                    a.Y      = Convert.ToInt32(str);
                    a.Width  = 30;
                    a.Height = 30;
                    Wall.Add(new Rectangle(a.X, a.Y, a.Width, a.Height));
                    str = "";
                }
                else
                {
                    str = str + c.ToString();
                }
            }
            a.Y      = Convert.ToInt32(str);
            a.Width  = 30;
            a.Height = 30;
            Wall.Add(new Rectangle(a.X, a.Y, a.Width, a.Height));
            str = "";



            Point     p  = new Point();
            TrangThai Tt = TrangThai.Down;
            Random    rd = new Random();
            bool      x  = false;

            foreach (char c in fTower)
            {
                if (c == ' ' && !x)
                {
                    p.X = Convert.ToInt32(str);
                    str = "";
                    x   = true;
                }
                else if (c == ' ' && x)
                {
                    p.Y = Convert.ToInt32(str);
                    str = "";
                    x   = false;
                }
                else if (c == '\r')
                {
                }
                else if (c == '\n')
                {
                    Tt = (TrangThai)(Convert.ToInt32(str));
                    ListFile.Add(new Tower(p, Tt));
                    str = "";
                }
                else
                {
                    str = str + c.ToString();
                }
            }
            Tt = (TrangThai)(Convert.ToUInt32(str));
            ListFile.Add(new Tower(p, Tt));
        }
Exemplo n.º 9
0
 public void AddWallPost(Views views)
 {
     Wall.Add(views);
     Raiting.AddWallPost();
 }
Exemplo n.º 10
0
        public OneDemExample(double dx_gr = 0d) : base()
        {
            dx_granica = dx_gr;
            int n_pm = perc * scaler;


            var dx1 = boardL / n_pm;

            for (int i = 0; i < n_pm; i++)
            {
                Particles.Add(new Particle()
                {
                    Name = i.ToString(),
                    X    = -boardL + i * dx1,
                    Ro   = 1,
                    P    = 1,
                    E    = 2.5,
                    V    = 0
                });
            }
            var dx2 = boardL / (Np - n_pm);

            for (int i = n_pm; i < Np; i++)
            {
                Particles.Add(new Particle()
                {
                    Name = i.ToString(),
                    X    = (i - n_pm) * dx2 + dx_granica,
                    Ro   = 0.25,
                    P    = 0.1795,
                    E    = 1.795,
                    V    = 0
                });
            }

            for (int i = -1; i > -Np_wall - 1; i--)
            {
                Wall.Add(new Particle()
                {
                    Name   = (i).ToString(),
                    X      = -boardL + (i) * dx1,
                    Ro     = 1,
                    P      = 1,
                    E      = 2.5,
                    V      = 0,
                    IsWall = true
                });
            }
            for (int i = Np + 1; i <= Np + Np_wall; i++)
            {
                Wall.Add(new Particle()
                {
                    Name   = (i).ToString(),
                    X      = (i - n_pm - 1) * dx2 + dx_granica,
                    Ro     = 0.25,
                    P      = 0.1795,
                    E      = 1.795,
                    V      = 0,
                    IsWall = true
                });
            }

            var all = Particles.Concat(Wall).OrderBy(p => p.X);

            AllParticles.AddRange(all);

            AllParticles.ForEach(p => p.M = 0.6 / n_pm);

            for (int i = 0; i < AllParticles.Count; i++)
            {
                AllParticles[i].MInd = i;
            }

            var xs    = AllParticles.Select(p => p.X).ToArray();
            var walls = AllParticles.Select(p => p.IsWall).ToArray();

            SynchMeBefore += SynchMeAfterAct;

            foreach (var p in Particles)
            {
                AddChild(p);
            }
            Particles.ForEach(p => p.SetDts());



            var mhi  = Particles.Where(p => p.P > 0.3).Sum(p => p.M);
            var mlo  = Particles.Where(p => p.P < 0.3).Sum(p => p.M);
            var mall = Particles.Sum(p => p.M);

            foreach (var part in AllParticles)
            {
                part.Ro = AllParticles.Sum(p => p.M * KernelF.W(part.X - p.X, h));
            }
            foreach (var p in Particles)
            {
                p.P = GetP(p);
            }

            SynchMeAfter += SynchMeAfterAct;
            //SynchMeForNext += t => {
            //    foreach(var p in Particles) {
            //        p.P = GetP(p);
            //    }
            //};

            particles_par = Particles.AsParallel();
        }