Beispiel #1
0
        public void OnPostUploadField([FromBody] List <List <Coordinate> > JSON)
        {
            validateUser();
            PlayerField myField = new PlayerField();

            myField.fieldNumber = StaticResources.user.orderNumber;

            foreach (List <Coordinate> coordinatesList in JSON)
            {
                List <ICoordinate> coordinates = coordinatesList.Cast <ICoordinate>().ToList();

                IBoat boat = new Boat();
                boat.FillWithCoordinates(coordinates);

                myField.AddNewBoatToField(boat);
            }

            StaticResources.field = myField;

            StaticResources.user.ready = true;

            MessageSender sender = new MessageSender();

            sender.SendReadyUpMessage();
        }
        public void SendSurrenderMessage()
        {
            PlayerField field = new PlayerField()
            {
                fieldNumber = StaticResources.field.fieldNumber,
                hitList     = StaticResources.field.hitList
            };

            foreach (IBoat boat in StaticResources.field.boats)
            {
                field.AddNewBoatToField(boat);
            }

            SurrenderResponse response = new SurrenderResponse()
            {
                playerId = StaticResources.user.PlayerId,
                field    = field
            };

            var indented = Formatting.Indented;
            var settings = new JsonSerializerSettings()
            {
                TypeNameHandling = TypeNameHandling.All
            };

            string line = JsonConvert.SerializeObject(response, indented, settings);

            ServiceBusHandler.program.topic.SendTopicMessage(line, MessageType.Surrender);
        }
Beispiel #3
0
        public PlayerField GetMyDummyField()
        {
            int         field   = StaticResources.user.orderNumber;
            PlayerField myField = new PlayerField()
            {
                fieldNumber = field,
            };

            List <List <ICoordinate> > CoordinateList = new List <List <ICoordinate> >()
            {
                new List <ICoordinate>()
                {
                    new Coordinate()
                    {
                        field = field, row = 1, col = 1
                    }, new Coordinate()
                    {
                        field = field, row = 1, col = 2
                    }, new Coordinate()
                    {
                        field = field, row = 1, col = 3
                    }, new Coordinate()
                    {
                        field = field, row = 1, col = 4
                    }, new Coordinate()
                    {
                        field = field, row = 1, col = 5
                    }
                },
                new List <ICoordinate>()
                {
                    new Coordinate()
                    {
                        field = field, row = 4, col = 9
                    }, new Coordinate()
                    {
                        field = field, row = 5, col = 9
                    }, new Coordinate()
                    {
                        field = field, row = 6, col = 9
                    }, new Coordinate()
                    {
                        field = field, row = 7, col = 9
                    }
                },
                new List <ICoordinate>()
                {
                    new Coordinate()
                    {
                        field = field, row = 7, col = 4
                    }, new Coordinate()
                    {
                        field = field, row = 7, col = 5
                    }, new Coordinate()
                    {
                        field = field, row = 7, col = 6
                    }
                },
                new List <ICoordinate>()
                {
                    new Coordinate()
                    {
                        field = field, row = 9, col = 7
                    }, new Coordinate()
                    {
                        field = field, row = 9, col = 8
                    }, new Coordinate()
                    {
                        field = field, row = 9, col = 9
                    }
                },
                new List <ICoordinate>()
                {
                    new Coordinate()
                    {
                        field = field, row = 3, col = 4
                    }, new Coordinate()
                    {
                        field = field, row = 4, col = 4
                    }
                },
            };

            foreach (List <ICoordinate> coordinates in CoordinateList)
            {
                IBoat boat = new Boat();
                boat.FillWithCoordinates(coordinates);

                myField.AddNewBoatToField(boat);
            }

            return(myField);
        }