public async Task <IActionResult> Create(JoinClassInfor joinClassInfor) { if (ModelState.IsValid) { AppUser currentUser = await userManager.FindByNameAsync(HttpContext.User.Identity.Name); joinClassInfor.NewClass.User = currentUser; joinClassInfor.NewClass.isActive = true; //joinClassInfor.NewClass.HOC = hoc; _context.Classes.Add(joinClassInfor.NewClass); RoomDocument roomD = new RoomDocument { ClassInfoID = joinClassInfor.NewClass.ClassID }; _context.RoomDocuments.Add(roomD); RoomMember roomM = new RoomMember { ClassID = joinClassInfor.NewClass.ClassID }; _context.RoomMembers.Add(roomM); await _context.SaveChangesAsync(); return(RedirectToAction("Room", "Room", joinClassInfor.NewClass)); } return(View()); }
public Response HandleTurn(Request request) { ResponseHeader header = new ResponseHeader(); RoomDocument document = (RoomDocument)request.Body; User winner; // Antwort an Spielpartner schicken header.Targets = new List <User> { document.Game.CurrentPlayer }; // Wenn ein Spieler das Spiel verlassen hat, hat der verbleibende Spieler gewonnen if (document.Game.Player1 is null || document.Game.Player2 is null) { if (document.Game.Player1 is null) { document.Game.Player1 = document.Game.CurrentPlayer; winner = document.Game.Player2; } else { document.Game.Player2 = document.Game.CurrentPlayer; winner = document.Game.Player2; } }
public Response StartGame(Request request) { ResponseHeader header = new ResponseHeader(); RoomDocument document = (RoomDocument)request.Body; header.Targets = new List <User> { document.Game.Player1, document.Game.Player2 }; if (!db.ChangeRoomStatus(document.Id, RoomStatus.Ongoing)) { header.Code = ResponseCode.PlannedError; header.Message = "Game could not be started"; return(new Response() { Header = header, Body = document }); } StartNewGame(document.Game); header.Code = ResponseCode.GameStart; header.Message = $"Game started. It is {document.Game.CurrentPlayer.Name}'s turn"; return(new Response() { Header = header, Body = document }); }
public void InsertMatch(RoomDocument room, User winner) { string winnerName = string.IsNullOrEmpty(winner.Name) ? $"{room.Game.Player1.Name}_{room.Game.Player2.Name}" : $"{winner.Name}"; string sql = ""; sql += $"INSERT INTO matches (won_by, roomid) VALUES ('{winnerName}', {room.Id});" + Environment.NewLine; sql += $"INSERT INTO users_played_matches (users_name, matches_id) VALUES ('{room.Game.Player1.Name}', (SELECT id FROM matches WHERE won_by='{winnerName}' ORDER BY timestamp DESC LIMIT 1));" + Environment.NewLine; sql += $"INSERT INTO users_played_matches (users_name, matches_id) VALUES ('{room.Game.Player2.Name}', (SELECT id FROM matches WHERE won_by='{winnerName}' ORDER BY timestamp DESC LIMIT 1));"; database.ExecuteNonQuery(sql); }
public JoinGameControl(RoomDocument room) { InitializeComponent(); ControlRoom = room; lbRoomName.Content = room.Name; lbUser1.Content = room.Game.Player1 != null ? room.Game.Player1.Name : ""; lbUser2.Content = room.Game.Player2 != null ? room.Game.Player2.Name : ""; lbStatus.Content = room.RoomStatus; if (string.IsNullOrEmpty(ControlRoom.Password)) { pbRoomPassword.Visibility = Visibility.Hidden; } }
public Response CreateRoom(Request request) { ResponseHeader header = new ResponseHeader() { Targets = new List <User> { request.Header.User } }; RoomDocument body = (RoomDocument)request.Body; body.Game = new Game() { Player1 = request.Header.User }; body.Id = db.CreateNewGame(body.Name, body.Password); if (body.Id < 0) { header.Code = ResponseCode.PlannedError; header.Message = "Room could not be created"; } else { if (db.AddUserToRoom(request.Header.User, body.Id)) { header.Code = ResponseCode.Ok; header.Message = "Room created successfully"; } else { header.Code = ResponseCode.PlannedError; header.Message = "User could not be added to game"; db.ChangeRoomStatus(body.Id, RoomStatus.Closed); } } return(new Response() { Header = header, Body = body }); }
public void UpdateIndex(IEnumerable <Room> rooms) { //Pessimistic approach: dropping/recreting the index will do for this demo //You should consider updating it instead slimLock.EnterWriteLock(); DeleteIndex(); CreateIndexIfNotExists(); if (rooms.Any()) { var bulkResponse = client.Bulk(descriptor => { foreach (var room in rooms) { var roomDocument = RoomDocument.FromRoom(room); descriptor.Index <RoomDocument>(doc => doc.Index(indexName).Document(roomDocument).Id(new Id(roomDocument.RoomId))); foreach (var specialPrice in room.SpecialPrices) { var specialPriceDocument = SpecialPriceDocument.FromSpecialPrice(specialPrice); descriptor.Index <SpecialPriceDocument>(doc => doc.Index(indexName).Document(specialPriceDocument).Parent(new Id(roomDocument.RoomId))); } foreach (var reservation in room.Reservations) { var reservationDocument = ReservationDocument.FromReservation(reservation); descriptor.Index <ReservationDocument>(doc => doc.Index(indexName).Document(reservationDocument).Parent(new Id(roomDocument.RoomId))); } } return(descriptor); }); slimLock.ExitWriteLock(); if (!bulkResponse.IsValid) { throw new InvalidOperationException("Error adding rooms to index: " + bulkResponse.ServerError.Error.Reason); } } else { slimLock.ExitWriteLock(); } }
public List <SegmentData> CollectSegmentData(List <LinkElementId> exteriorElementIds, bool includeLinkedModel) { var segmentDataList = new List <SegmentData>(); try { var options = new SpatialElementBoundaryOptions(); options.SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Center; var segments = RoomObj.GetBoundarySegments(options); foreach (var segmentList in segments) { foreach (var segment in segmentList) { var sData = new SegmentData(segment); #if RELEASE2015 Element element = segment.Element; #else var element = RoomDocument.GetElement(segment.ElementId); #endif if (null != element) { if (null != element.Category) { Wall wall = null; var transform = Transform.Identity; if (element.Category.Id.IntegerValue == (int)(BuiltInCategory.OST_Walls)) { wall = element as Wall; if (null != wall) { var linkIds = from linkId in exteriorElementIds where linkId.HostElementId == wall.Id select linkId; if (linkIds.Any()) { sData.IsExteriror = true; } } } else if (includeLinkedModel && element.Category.Id.IntegerValue == (int)(BuiltInCategory.OST_RvtLinks)) { var instance = element as RevitLinkInstance; transform = instance.GetTotalTransform(); var linkDoc = instance.GetLinkDocument(); var centerPoint = sData.BoundaryCurve.Evaluate(0.5, true); centerPoint = transform.Inverse.OfPoint(centerPoint); var bbFilter = new BoundingBoxContainsPointFilter(centerPoint); var collector = new FilteredElementCollector(linkDoc); var walls = collector.OfCategory(BuiltInCategory.OST_Walls).OfClass(typeof(Wall)).WherePasses(bbFilter).WhereElementIsNotElementType().ToElements().Cast <Wall>().ToList(); if (walls.Count > 0) { wall = walls.First(); var linkIds = from linkId in exteriorElementIds where linkId.LinkedElementId == wall.Id && linkId.LinkInstanceId == instance.Id select linkId; if (linkIds.Any()) { sData.IsExteriror = true; } } } if (null != wall) { sData.WallId = wall.Id; if (wall.WallType.Kind == WallKind.Curtain) { sData.VisibleCurves.Add(sData.BoundaryCurve); sData.GetViewPoints(true); segmentDataList.Add(sData); } else { var windowCurves = GetWindowsDoorCurves(wall, sData.BoundaryCurve, transform); if (windowCurves.Any()) { sData.VisibleCurves.AddRange(windowCurves); sData.GetViewPoints(false); segmentDataList.Add(sData); } } } } } else { sData.GetViewPoints(true); segmentDataList.Add(sData); } } } } catch (Exception ex) { var message = ex.Message; } return(segmentDataList); }
public Response JoinRoom(Request request) { ResponseHeader header = new ResponseHeader(); RoomDocument body = (RoomDocument)request.Body; List <RoomDocument> rooms; header.Targets = new List <User> { request.Header.User }; rooms = db.GetRooms().Where(x => x.Id == body.Id).ToList(); // Wenn es keine Räume zu der Raum Id gibt if (rooms.Count() == 0) { header.Code = ResponseCode.PlannedError; header.Message = $"The room does not exist"; return(new Response() { Header = header, Body = body }); } // Wenn es mehr als einen Raum zu der Id gibt if (rooms.Count() > 2) { header.Code = ResponseCode.PlannedError; header.Message = $"The room is full"; return(new Response() { Header = header, Body = body }); } // Wenn der Raum nicht offen ist if (rooms.First(x => x.Id == body.Id).RoomStatus != RoomStatus.Open) { header.Code = ResponseCode.PlannedError; header.Message = $"The room is not open"; return(new Response() { Header = header, Body = body }); } if (!db.AddUserToRoom(request.Header.User, body.Id)) { header.Code = ResponseCode.PlannedError; header.Message = $"Player {request.Header.User.Name} could not join the room"; return(new Response() { Header = header, Body = body }); } header.Code = ResponseCode.JoinedRoom; header.Message = $"Player {request.Header.User.Name} joined the room"; // Den Spieler im Game-Objekt füllen, abhängig davon, welcher noch nicht gefüllt ist if (body.Game.Player1 is null) { body.Game.Player1 = request.Header.User; header.Targets.Add(body.Game.Player2); } else { body.Game.Player2 = request.Header.User; header.Targets.Add(body.Game.Player1); } // Wenn jetzt zwei Spieler im Raum sind wird dieser auf "Full" gesetzt if (!(body.Game.Player1 is null || body.Game.Player2 is null)) { db.ChangeRoomStatus(body.Id, RoomStatus.Full); header.Message += Environment.NewLine + "Room full"; } return(new Response() { Header = header, Body = body }); }