Exemplo n.º 1
0
        public void Print(Graphics g, GamePoint point)
        {
            Image chassisImage = ImagesTools.RotateImage(Properties.Resources.defaultTankChassis, Angle);

            g.DrawImage(chassisImage, (float)point.X, (float)point.Y, 20, 40);
            //g.DrawRectangle(new Pen(Brushes.Black), (float)point.X, (float)point.Y, 10, 10);
        }
Exemplo n.º 2
0
        //贪吃蛇往面前移动一个
        public void SnackMove()
        {
            GamePoint nextPoint = new GamePoint();
            GamePoint prePoint  = new GamePoint();

            nextPoint = head.position;
            prePoint.setPointXY(head.position.posX, head.position.posY);

            switch (head.nowDirection)
            {
            case Direction.UP: nextPoint.posX -= 1;
                break;

            case Direction.DOWN: nextPoint.posX += 1;
                break;

            case Direction.LEFT: nextPoint.posY -= 1;
                break;

            case Direction.RIGHT: nextPoint.posY += 1;
                break;
            }

            Head newhead = new Head();

            newhead.position     = nextPoint;
            newhead.nowDirection = head.nowDirection;
            Body newbody = new Body();

            newbody.position = prePoint;
            head             = newhead;
            bodyList.Insert(0, newbody);
            bodyList.RemoveAt(bodyList.Count() - 1);
        }
 GamePoint[] checkGamePoint()
 {
     GamePoint[] gamePoints = new GamePoint[noOfColors];
     for (int a = 0; a < noOfColors; a++)
     {
         GamePoint gamepoint = new GamePoint();
         setRandomNumbers(ref gamepoint.startingNode.x, ref gamepoint.startingNode.y, ref gamepoint.endingNode.x, ref gamepoint.endingNode.y);
         for (int b = 0; b < a; b++)
         {
             if (compareGamePoints(gamePoints[b], gamepoint))
             {
                 setRandomNumbers(ref gamepoint.startingNode.x, ref gamepoint.startingNode.y, ref gamepoint.endingNode.x, ref gamepoint.endingNode.y);
             }
         }
         gamePoints[a] = gamepoint;
     }
     for (int a = 0; a < noOfColors; a++)
     {
         Debug.Log("GamePoint: " + (a + 1) + "Starting Node X: " + gamePoints[a].startingNode.x + "Starting Node Y" + gamePoints[a].startingNode.y + "EndingNode X: " + gamePoints[a].endingNode.x + "Ending Node Y" + gamePoints[a].endingNode.y);
     }
     //for (int a=0;a<noOfColors;a++)
     //{
     //    for (int b=a+1;b<noOfColors;b++)
     //    {
     //        if (compareGamePoints(gamePoints[a],gamePoints[b]))
     //            setRandomNumbers(ref gamePoints[a].startingNode.x, ref gamePoints[a].startingNode.y, ref gamePoints[a].endingNode.x, ref gamePoints[a].endingNode.y);
     //    }
     //}
     for (int a = 0; a < noOfColors; a++)
     {
         Debug.Log(a);
         Debug.Log("GamePoint: " + (a + 1) + "Starting Node X: " + gamePoints[a].startingNode.x + "Starting Node Y" + gamePoints[a].startingNode.y + "EndingNode X: " + gamePoints[a].endingNode.x + "Ending Node Y" + gamePoints[a].endingNode.y);
     }
     return(gamePoints);
 }
Exemplo n.º 4
0
        /// <summary>
        /// Получить игровую клетку.
        /// </summary>
        /// <param name="location"></param>
        /// <returns></returns>
        public GamePeice GetPeiceOnLocation(Point location)
        {
            var point = new GamePoint(location.X, location.Y);
            var peice = InnerGame.Board.SingleOrDefault(x => x.Point.Equals(point));

            return(peice);
        }
Exemplo n.º 5
0
        private static List <GameMove> GetMovesForBishop(GamePeice peice, ChessGame game)
        {
            var result = new List <GameMove>();

            var quadOffsets = new GamePoint[]
            {
                new GamePoint(1, 1),
                new GamePoint(1, -1),
                new GamePoint(-1, -1),
                new GamePoint(-1, 1)
            };

            foreach (var quad in quadOffsets)
            {
                var offset = quad;
                while (true)
                {
                    var newLoc = new GamePoint(peice.Point.X + offset.X, peice.Point.Y + offset.Y);
                    var tile   = game.GetGameTile(newLoc, peice.Side);

                    AddPossibleValidMove(result, newLoc, peice, tile);

                    if (tile.IsBarrier())
                    {
                        break;
                    }

                    offset = new GamePoint(offset.X + quad.X, offset.Y + quad.Y);
                }
            }

            return(result);
        }
Exemplo n.º 6
0
        private static List <GameMove> GetMovesForKing(GamePeice peice, ChessGame game)
        {
            var result = new List <GameMove>();

            var king_offsets = new GamePoint[]
            {
                new GamePoint(0, 1),
                new GamePoint(1, 0),
                new GamePoint(0, -1),
                new GamePoint(-1, 0),
                new GamePoint(1, 1),
                new GamePoint(1, -1),
                new GamePoint(-1, -1),
                new GamePoint(-1, 1)
            };

            foreach (var offset in king_offsets)
            {
                var newLoc = new GamePoint(peice.Point.X + offset.X, peice.Point.Y + offset.Y);
                var tile   = game.GetGameTile(newLoc, peice.Side);

                AddPossibleValidMove(result, newLoc, peice, tile);
            }

            //Castling  TO-DO

            return(result);
        }
    void generateGamePointColors()
    {
        Debug.Log("In Generate GamePoint Colors");
        GamePoint[] gpArray = new GamePoint[noOfColors];
        gpArray = checkGamePoint();
        for (int a = 0; a < noOfColors; a++)
        {
            gamePointDict.Add(colors[a], gpArray[a]);
        }
        GamePoint testpoint;

        gamePointDict.TryGetValue(Color.red, out testpoint);
        startPositionX = testpoint.startingNode.x;
        startPositionY = testpoint.startingNode.y;
        endPositionX   = testpoint.endingNode.x;
        endPositionY   = testpoint.endingNode.y;

        for (int a = 0; a < noOfColors; a++)
        {
            GamePoint point;
            gamePointDict.TryGetValue(colors[a], out point);
            Debug.Log("Color: " + colors[a].ToString() + "Starting Node X:" + point.startingNode.x + "Y:" + point.startingNode.y);
            Debug.Log("Color: " + colors[a].ToString() + "Ending Node X " + point.endingNode.x + "Y:" + point.endingNode.y);
        }
    }
Exemplo n.º 8
0
        public void TestMove()
        {
            gamePolygon.SetMove(10);

            var newPoints = new GamePoint[]
            {
                new GamePoint(5, 15),
                new GamePoint(15, 15),
                new GamePoint(15, 25),
                new GamePoint(5, 25)
            };
            var drawPoints = gamePolygon.GetDrawPolygon();

            CollectionAssert.AreEqual(newPoints, drawPoints);
            gamePolygon.SetMove(10, 90);
            newPoints = new GamePoint[]
            {
                new GamePoint(-5, 15),
                new GamePoint(5, 15),
                new GamePoint(5, 25),
                new GamePoint(-5, 25)
            };
            drawPoints = gamePolygon.GetDrawPolygon();
            CollectionAssert.AreEqual(newPoints, drawPoints);
        }
Exemplo n.º 9
0
        private static List <GameMove> GetMovesForKnight(GamePeice peice, ChessGame game)
        {
            var result = new List <GameMove>();

            var offsets = new GamePoint[]
            {
                new GamePoint(1, 2),
                new GamePoint(2, 1),
                new GamePoint(2, -1),
                new GamePoint(1, -2),
                new GamePoint(-1, -2),
                new GamePoint(-2, -1),
                new GamePoint(-2, 1),
                new GamePoint(-1, 2)
            };

            foreach (var offset in offsets)
            {
                var newLoc = new GamePoint(peice.Point.X + offset.X, peice.Point.Y + offset.Y);
                var tile   = game.GetGameTile(newLoc, peice.Side);

                AddPossibleValidMove(result, newLoc, peice, tile);
            }

            return(result);
        }
Exemplo n.º 10
0
 public void Move(GamePoint point, MoveType moveType)
 {
     if (CanMove(point))
     {
         _gameBoard[point.X, point.Y] = moveType;
     }
 }
Exemplo n.º 11
0
 void movementDebugStartConditions()
 {
     tiles = new GameObject[rows, columns];
     nodes = new Node[rows, columns];
     generateGrid();
     gp                         = new GamePoint();
     gp2                        = new GamePoint();
     gp.startingNode            = nodes[0, 0];
     nodes[0, 0].renderer.color = Color.red;
     nodes[0, 0].isColored      = true;
     nodes[0, 0].isGamePoint    = true;
     gp.endingNode              = nodes[4, 4];
     nodes[4, 4].renderer.color = Color.red;
     nodes[4, 4].isColored      = true;
     nodes[4, 4].isGamePoint    = true;
     nodes[4, 0].renderer.color = Color.yellow;
     nodes[4, 0].isColored      = true;
     nodes[4, 0].isGamePoint    = true;
     nodes[0, 4].renderer.color = Color.yellow;
     nodes[0, 4].isColored      = true;
     nodes[0, 4].isGamePoint    = true;
     gp2.startingNode           = nodes[4, 0];
     gp2.endingNode             = nodes[0, 4];
     gamePointDict              = new Dictionary <Color, GamePoint>();
     colors                     = new Color[] { Color.red, Color.yellow };
     gamePointDict.Add(Color.red, gp);
     gamePointDict.Add(Color.yellow, gp2);
     currentPath    = new List <Node>();
     currentColor   = new Color();
     currentNode    = new Node();
     collisionColor = new Color();
     colorTaken     = false;
 }
Exemplo n.º 12
0
    void generateGamePointColors()
    {
        //Debug.Log("In Generate GamePoint Colors");
        GamePoint[] gpArray = new GamePoint[noOfColors];
        gpArray = checkGamePoint();
        for (int a = 0; a < noOfColors; a++)
        {
            if (!gamePointDict.ContainsKey(colors[a]))
            {
                gamePointDict.Add(colors[a], gpArray[a]);
                if (gamePointDict[colors[a]].startingNode.renderer == null)
                {
                    //Debug.Log("WTF IS THIS SHIT");
                }
                //changeTileColor(gamePointDict[colors[a]].startingNode, colors[a]);
                //changeTileColor(gamePointDict[colors[a]].endingNode, colors[a]);
                //Debug.Log("Game Points Starting X:" + gamePointDict[colors[a]].startingNode.x + "Y: " + gamePointDict[colors[a]].startingNode.y);
                //Debug.Log("Game Points Ending X:" + gamePointDict[colors[a]].endingNode.x + "Y: " + gamePointDict[colors[a]].endingNode.y);
            }
            else
            {
                continue;
            }
        }
        GamePoint testpoint;

        gamePointDict.TryGetValue(Color.red, out testpoint);
        startPositionX = testpoint.startingNode.x;
        startPositionY = testpoint.startingNode.y;
        endPositionX   = testpoint.endingNode.x;
        endPositionY   = testpoint.endingNode.y;
    }
Exemplo n.º 13
0
    void checkPathValidity(Color color)
    {
        GamePoint currentGamePoint = new GamePoint();

        gamePointDict.TryGetValue(color, out currentGamePoint);
        List <Node> path = new List <Node>();

        path = currentGamePoint.path;
        if (path.Count != 0)
        {
            if (!checkGamePositions(path[path.Count - 1], color))
            {
                if (path.Count > 1)
                {
                    for (int i = 0; i < path.Count; i++)
                    {
                        if (path[i] == currentGamePoint.startingNode || path[i] == currentGamePoint.endingNode)
                        {
                            if (path[i] == currentGamePoint.startingNode)
                            {
                                Debug.Log("Index: " + i);
                                Debug.Log("Total Count" + path.Count);
                            }
                            continue;
                        }
                        changeTileColor(path[i], Color.white);
                        path[i].isColored = false;
                    }
                }
            }
        }
        path.Clear();
    }
Exemplo n.º 14
0
 public void Move(GamePoint point)
 {
     if (CanMove(point))
     {
         _gameBoard[point.X, point.Y] = _currentMove;
         _currentMove = _currentMove == MoveType.X ? MoveType.O : MoveType.X;
     }
 }
Exemplo n.º 15
0
        protected override void Move()
        {
            GamePoint temp      = _player.CenterPolygonAbsolute - this.CenterPolygonAbsolute;
            GamePoint direction = Normalize(temp);

            CenterPolygonAbsolute += direction * Speed;
            base.Move();
        }
Exemplo n.º 16
0
        public Bullet ShotBullet(GamePoint creationPoint, float angleRotateGradus)
        {
            var bullet = new Bullet(BulletPolygonPonts, angleRotateGradus, creationPoint, BulletLifeTime);

            bullet.Speed = BulletSpeed;
            Create?.Invoke(this, bullet);
            return(bullet);
        }
Exemplo n.º 17
0
 public void Move(GamePoint nextHeadPosition, bool hasBonus)
 {
     if (!CanSnakeGrow || !hasBonus)
     {
         SnakePoints.RemoveAt(SnakePoints.Count - 1);
     }
     SnakePoints.Insert(0, nextHeadPosition);
 }
Exemplo n.º 18
0
        // new world with the editor
        private World(PlayMode playMode)
        {
            this.PlayMode = playMode;
            this.viewport = new GamePoint(0, 0);

            if (playMode == PlayMode.Editor)
                mainGameObject = new NullMGO();
        }
Exemplo n.º 19
0
        private bool IsCollusionLine(GamePoint a1, GamePoint a2, GamePoint b1, GamePoint b2)
        {
            var v1 = (b2.X - b1.X) * (a1.Y - b1.Y) - (b2.Y - b1.Y) * (a1.X - b1.X);
            var v2 = (b2.X - b1.X) * (a2.Y - b1.Y) - (b2.Y - b1.Y) * (a2.X - b1.X);
            var v3 = (a2.X - a1.X) * (b1.Y - a1.Y) - (a2.Y - a1.Y) * (b1.X - a1.X);
            var v4 = (a2.X - a1.X) * (b2.Y - a1.Y) - (a2.Y - a1.Y) * (b2.X - a1.X);

            return((v1 * v2 < 0) && (v3 * v4 < 0));
        }
Exemplo n.º 20
0
        protected GameObject(GamePoint[] notMovedPolygon, float angleGradus,
                             GamePoint creationGamePoint, bool offcetCenter = false)
        {
            _polygon = !offcetCenter?GamePolygon.GetPolygon(notMovedPolygon, angleGradus, creationGamePoint)
                           : GamePolygon.GetPollygonOffcetCenter(notMovedPolygon, angleGradus, creationGamePoint);

            Collider = new Collider(_polygon);
            Speed    = 10;
        }
Exemplo n.º 21
0
 internal Bullet(GamePoint[] notMovedPolygon, float angleRotateGradus, GamePoint creationGamePoint, int lifeTime)
     : base(notMovedPolygon, angleRotateGradus, creationGamePoint)
 {
     if (lifeTime <= 0)
     {
         throw new ArgumentException("Время жизни не может быть меньше либо равным нулю.");
     }
     LifeTime = lifeTime;
 }
Exemplo n.º 22
0
        private GamePoint GenerateBonus()
        {
            GamePoint newBonus;

            do
            {
                newBonus = new GamePoint(Random.Next(GameSize.Width), Random.Next(GameSize.Height));
            } while (GetFieldState(newBonus) != FieldState.Empty);
            return(newBonus);
        }
Exemplo n.º 23
0
 internal Asteroid(GamePoint[] notMovedPolygon, float angleRotateGradus, GamePoint creationGamePoint, float speed, int typeVisualization, EnemyBuilder builder)
     : base(notMovedPolygon, angleRotateGradus, creationGamePoint, typeVisualization)
 {
     _builder = builder;
     if (speed <= 0)
     {
         throw new ArgumentException("Скорость объекта не может быть меньше либо равным нулю.");
     }
     Speed = speed;
 }
Exemplo n.º 24
0
 public Laser(GamePoint[] notMovedPolygon, float angleRotateGradus, GamePoint creationGamePoint, int lifeTime, Player player)
     : base(notMovedPolygon, angleRotateGradus, creationGamePoint, true)
 {
     if (lifeTime <= 0)
     {
         throw new ArgumentException("Время жизни не может быть меньше либо равным нулю.");
     }
     LifeTime = lifeTime;
     _player  = player;
 }
Exemplo n.º 25
0
 public FlyingSaucer(GamePoint[] notMovedPolygon, float angleRotateGradus, GamePoint creationGamePoint, float speed, Player player)
     : base(notMovedPolygon, angleRotateGradus, creationGamePoint)
 {
     _player = player;
     if (speed <= 0)
     {
         throw new ArgumentException("Скорость объекта не может быть меньше либо равным нулю.");
     }
     Speed = speed;
 }
Exemplo n.º 26
0
 public void PublishGamePoint(GamePoint gamePoint)
 {
     Bus.Publish <GamePoint>(new GamePoint
     {
         PlayerId  = gamePoint.PlayerId,
         GameId    = gamePoint.GameId,
         Win       = gamePoint.Win,
         TimeStamp = DateTime.Now
     });
 }
Exemplo n.º 27
0
        static void Main(string[] args)
        {
            GamePoint point1 = new GamePoint()
            {
                X = 5, Y = 7
            };

            Console.WriteLine(point1.X);

            Console.ReadKey();
        }
Exemplo n.º 28
0
 private static void AddPossibleValidMove(List <GameMove> moves, GamePoint location, GamePeice peice, GameTile tile)
 {
     if (tile == Enums.GameTile.Free)
     {
         moves.Add(new GameMove(peice, Enums.GameMoveType.Standart, location));
     }
     else if (tile == Enums.GameTile.Enemy)
     {
         moves.Add(new GameMove(peice, Enums.GameMoveType.Attack, location));
     }
 }
Exemplo n.º 29
0
 private void Redraw()
 {
     for (int i = 0; i < _game.BoardSize; i++)
     {
         for (int j = 0; j < _game.BoardSize; j++)
         {
             GamePoint p = new GamePoint(i, j);
             GetCell(p).MoveTypeOnCell = _game.Get(p);
         }
     }
     OnPropertyChanged(nameof(IsCurrentX));
 }
Exemplo n.º 30
0
        public FlyingSaucer CreateFlyingSaucer(GamePoint createGamePoint, float angleMoveGradus, Player player)
        {
            if (TypeFlyingSaucer.Count == 0)
            {
                throw new InvalidOperationException("В коллекции нет полигонов для отображения летающих тарелок.");
            }
            var points       = TypeFlyingSaucer[_rand.Next(0, TypeFlyingSaucer.Count)];
            var flyingSaucer = new FlyingSaucer(points, angleMoveGradus, createGamePoint, SpeedFlyingSaucer, player);

            Create?.Invoke(this, flyingSaucer);
            return(flyingSaucer);
        }
Exemplo n.º 31
0
 public override FieldState GetFieldState(GamePoint point)
 {
     if (TetrisFigure.Contains(point))
     {
         return(FieldState.TetrisFigure);
     }
     if (Walls[point.Y][point.X])
     {
         return(FieldState.Wall);
     }
     return(FieldState.Empty);
 }
Exemplo n.º 32
0
        private void level_MouseDown(object sender, MouseEventArgs e)
        {
            List<GameObject> gos = world.AllElements;
            bool found = false;
            for (int i = gos.Count - 1; i >= 0; i--)
            {
                GameObject go = gos[i];
                if (go.Hit(e.Y - world.Viewport.Y, e.X - world.Viewport.X))
                {
                    focus = go;

                    moving = true;
                    mouseX = e.X - go.Left;
                    mouseY = e.Y - go.Top;
                    found = true;
                    break;
                }
            }

            if (found)
            {
                // check if current selected object is already in list
                if (Array.IndexOf<object>(properties.SelectedObjects, focus) == -1)
                {
                    // not in list & STRG-Key press
                    if (pressedKeys.Contains(Keys.ControlKey))
                    {
                        if (properties.SelectedObjects.Length == 1 && properties.SelectedObject is LevelSettings)
                        {
                            properties.SelectedObjects = new object[] { focus };
                        }
                        else
                        {
                            object[] selected = properties.SelectedObjects;
                            Array.Resize<object>(ref selected, selected.Length + 1);
                            selected[selected.Length - 1] = focus;

                            properties.SelectedObjects = selected;
                        }

                    }
                    else // no STRG Key - remove selection of other objects, add only one selection to current
                    {
                        properties.SelectedObjects = new object[] { focus };
                    }
                }
                // object selected (in array) & STRG -> remove selection
                else if (pressedKeys.Contains(Keys.ControlKey))
                {
                    List<object> selected = new List<object>(properties.SelectedObjects);
                    selected.Remove(focus);
                    properties.SelectedObjects = selected.ToArray();
                }
            }
            else if (!pressedKeys.Contains(Keys.ControlKey))
            {
                focus = null;
                properties.SelectedObjects = new object[] { };
            }

            startRectangle = new GamePoint(e.X - world.Viewport.X, e.Y - world.Viewport.Y);
        }
Exemplo n.º 33
0
 public bool CanMove(GamePoint point)
 {
     return CanMove(point.X, point.Y);
 }
Exemplo n.º 34
0
 public void Move(GamePoint point, MoveType moveType)
 {
     if (CanMove(point))
         _gameBoard[point.X, point.Y] = moveType;
 }
Exemplo n.º 35
0
        private void level_MouseMove(object sender, MouseEventArgs e)
        {
            bool repaint = false;

            if (moving && focus != null)
            {
                float movementTop = (e.Y - mouseY) - focus.Top;
                float movementLeft = (e.X - mouseX) - focus.Left;

                focus.Top += movementTop;
                focus.Left += movementLeft;

                for (int i = 0; i < properties.SelectedObjects.Length; i++)
                {
                    if (properties.SelectedObjects[i] != focus &&
                        properties.SelectedObjects[i] is GameObject)
                    {
                        ((GameObject)properties.SelectedObjects[i]).Top += movementTop;
                        ((GameObject)properties.SelectedObjects[i]).Left += movementLeft;
                    }
                }

                repaint = true;
            }

            if (startRectangle != null && focus == null)
            {
                endRectangle = new GamePoint(e.X - world.Viewport.X, e.Y - world.Viewport.Y);
                curRectangle = GamePoint.GetRectangle(startRectangle, endRectangle);

                repaint = true;
            }

            if (repaint)
                drawHandler.Update();
        }
        private void SyncViewModelToUI()
        {
            this._gameCanvas.Children.Clear();
            GameViewModel gameViewModel = this.ViewModel as GameViewModel;

            if (gameViewModel != null)
            {
                foreach (PointViewModel pointViewModel in gameViewModel.GamePoints)
                {
                    GamePoint point = new GamePoint();
                    point.OnPointMoveCompleted += this.WinStateCheck;

                    point.ViewModel = pointViewModel;
                    pointViewModel.View = point;

                    this._gameCanvas.Children.Add(point);
                    Canvas.SetLeft(point, pointViewModel.CurPosition.X);
                    Canvas.SetTop(point, pointViewModel.CurPosition.Y);
                    Canvas.SetZIndex(point, 10);
                }

                foreach (LineViewModel lineViewModel in gameViewModel.GameLines)
                {
                    this._gameCanvas.Children.Add(lineViewModel.Segment);
                }
            }
        }
Exemplo n.º 37
0
        private void level_MouseUp(object sender, MouseEventArgs e)
        {
            moving = false;

            if (endRectangle != null)
            {
                EditorUI.FetchElementsInRectangle(curRectangle, ref world, ref properties, pressedKeys.Contains(Keys.ControlKey));

                startRectangle = null;
                endRectangle = null;
                curRectangle = Rectangle.Empty;
            }

            properties.Refresh();
            drawHandler.Update();
        }
Exemplo n.º 38
0
 public GameLinePoint(GamePoint point, MoveType? moveType)
 {
     Point = point;
     MoveType = moveType;
 }