/// <summary> /// Updates a data point for a ship /// </summary> /// <param name="shipLocation"></param> /// <returns>bool</returns> public bool UpdateShipLocation(db_ShipLocation shipLocation) { try { _context.MySqlDb.Query <db_ShipLocation>("UPDATE ship_location SET row = " + shipLocation.Row + ", col = " + shipLocation.Col + " WHERE ship_id = " + shipLocation.Ship_Id + ";", commandType: CommandType.Text); return(true); } catch (MySqlException mysqlex) { Debug.WriteLine("MYSQL EXCEPTION IN CreateNewShipLocation"); Debug.WriteLine(mysqlex.InnerException); return(false); } catch (InvalidOperationException ioe) { Debug.WriteLine("INVALID OPERATION EXCEPTION IN CreateNewShipLocation"); Debug.WriteLine(ioe.InnerException); return(false); } catch (Exception e) { Debug.WriteLine("EXCEPTION IN CreateNewShipLocation"); Debug.WriteLine(e.InnerException); return(false); } }
/// <summary> /// Inserts a data point for a ship. /// </summary> /// <param name="shipLocation"></param> /// <returns>bool</returns> public bool CreateNewShipLocation(db_ShipLocation shipLocation) { try { _context.MySqlDb.Query <db_ShipLocation>("INSERT INTO ship_location (ship_id, board_id, row, col) VALUES (" + shipLocation.Ship_Id + ", " + shipLocation.Board_Id + ", " + shipLocation.Row + ", " + shipLocation.Col + ");", commandType: CommandType.Text); return(true); } catch (MySqlException mysqlex) { Debug.WriteLine("MYSQL EXCEPTION IN CreateNewShipLocation"); Debug.WriteLine(mysqlex.InnerException); return(false); } catch (InvalidOperationException ioe) { Debug.WriteLine("INVALID OPERATION EXCEPTION IN CreateNewShipLocation"); Debug.WriteLine(ioe.InnerException); return(false); } catch (Exception e) { Debug.WriteLine("EXCEPTION IN CreateNewShipLocation"); Debug.WriteLine(e.InnerException); return(false); } }
public JsonResult CheckForHit(db_ShipLocation shipLocation) { // Check to see if there is a ship at the target location var ship = _shipLocationRepo.CheckLocation(shipLocation); // ship found at the row/col combination on the board id // Create the new shot var shot = new db_Shot { Board_Id = shipLocation.Board_Id, Col = shipLocation.Col, Row = shipLocation.Row, Is_Hit = (ship != null) ? 1 : 0 }; var newShotReturn = _shotRepo.CreateNewShot(shot); // Check to make sure the shot was made. if (newShotReturn != null) { if (!newShotReturn[0].Equals("Shot made")) { return(Json(new { errMsg = "Error creating shot, please try again.", err = "An error creating your shot has occured.", invalidToken = false })); } // Return the win if the repo says you won if (newShotReturn[1].Equals("Win")) { return(Json(new { shotMade = true, hit = shot.Is_Hit, win = true, winningBoard = shot.Board_Id })); } // Return without the win if there is no win condition return(Json(new { shotMade = true, win = false })); } return(Json(new { errMsg = "Error creating shot, please try again.", err = "An error creating your shot has occured.", invalidToken = false })); }
/// <summary> /// Checks a location to see if a ship is there or not. /// </summary> /// <param name="shipLocation"></param> /// <returns>db_ShipLocation</returns> public db_ShipLocation CheckLocation(db_ShipLocation shipLocation) { return(_context.MySqlDb.Query <db_ShipLocation>("SELECT * FROM ship_location WHERE board_id = " + shipLocation.Board_Id + " AND row = " + shipLocation.Row + " AND col = " + shipLocation.Col + ";", commandType: CommandType.Text).FirstOrDefault()); }
public JsonResult UpdateShipLocation(db_ShipLocation shipLocation) { return(Json(_shipLocationRepo.UpdateShipLocation(shipLocation))); }
public bool CreateNewShipLocation(db_ShipLocation shipLocation) { var ship = _shipLocationRepo.CheckLocation(shipLocation); return(ship != null || _shipLocationRepo.CreateNewShipLocation(shipLocation)); }