Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Basic Functionality of TextBased Adventure Game - Lost Residence
Basic Functionality of TextBased Adventure Game - TerraCraft

The rooms file consists of 34 rooms.
The rooms file consists of 30 rooms.

Each Room contains:

Expand Down Expand Up @@ -56,4 +56,3 @@ Eact .txt file need to be located outside the src directory in the project folde
--STATS (HP): This will allow the player to see all the details about their stats (HP, Attack, Location, and Score).--
--The keyword command [PACK] is also used to look inside the player's backpack!--


Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
CREATE TABLE ITEM(itemID integer not null primary key autoincrement, roomID int not null, inInventory int not null, itemName text not null, itemDesc text not null, playerID int not null, canHeal int not null, healValue int null, FOREIGN KEY (roomID) REFERENCES ROOM(roomNumber) FOREIGN KEY (playerID) REFERENCES PLAYER (playerID));
CREATE TABLE ITEM(itemID integer not null primary key autoincrement, roomID int not null, inInventory int not null, itemName text not null, itemDesc text not null, playerID int not null, canHeal int not null, healValue int null, FOREIGN KEY (roomID) REFERENCES ROOM(roomNumber) FOREIGN KEY (playerID) REFERENCES PLAYER (playerID));
INSERT INTO ITEM (roomID, inInventory, itemName, itemDesc, playerID, canHeal, healValue) VALUES
(1, 0, 'Healing Potion', 'Restores health — player gets to live longer', 1, 1, 20),
(2, 0, 'Magic Scroll', 'Reveals hint for puzzle — shows puzzle clue', 1, 0, NULL),
(3, 0, 'Shield of Light', 'Blocks next monster attack — one-time protection', 1, 0, NULL),
(4, 0, 'Compass', 'Shows all exits in current room — helpful for navigation', 1, 0, NULL),
(5, 0, 'Weapons', 'Player can pick up swords or axes — helpful for combat', 1, 0, NULL);
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
CREATE TABLE PUZZLE(puzzleID integer not Null Primary Key autoincrement, description text null, ItemToSolve text null, hint text null, roomID int null, solved int null, playerID int not null); FOREIGN KEY (playerID) REFERENCES PLAYER (playerID);
INSERT INTO PUZZLE (description, ItemToSolve, hint, roomID, solved, playerID) VALUES
('I have hands but no arms and a face but no eyes. What am I?', 'A clock', 'Look at the wall to tell time.', 1, 0, 1),
('What has to be broken before you can use it?', 'An egg', 'You eat it for breakfast.', 1, 0, 1),
('I have four legs and a back but no head. What am I?', 'A chair', 'You sit on me.', 1, 0, 1),
('I come down but never go up. What am I?', 'Rain', 'Check the sky.', 1, 0, 1),
('What begins with T, ends with T, and has T in it?', 'A teapot', 'Think of something that boils.', 1, 0, 1),
('What is full of holes but still holds water?', 'A sponge', 'You clean dishes with it.', 1, 0, 1),
('What has feet but can’t walk?', 'A ruler', 'Used for measuring.', 1, 0, 1),
('What comes once in a minute, twice in a moment, but never in a thousand years?', 'The letter M', 'It''s a letter.', 1, 0, 1),
('What goes up but never comes down?', 'Your age', 'Think about birthdays.', 1, 0, 1),
('What is white, cold, and falls from the sky in winter?', 'Snow', 'Wear a coat when it happens.', 1, 0, 1);
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
package model;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
* Class : DB.java
* @author: Rick Price
* @updated: Hyesung Park
* @author: Sidibaba Simpara, Malik Key, Britney Familia, Angelica Jones
* @version: 2.0
* Course: ITEC 3860
* updated: March 26, 2022
* This class controls basic DB functionality
* Purpose:Has Query and Update DB
* Purpose: Controls basic DB functionality (Query and Update DB)
*/
abstract public class DB {
public abstract class DB {
protected String dbName = "Game.db";
protected String sJdbc;
protected String sDriverName;
Expand All @@ -24,44 +21,49 @@ abstract public class DB {
protected int timeout = 5;

/**
* Method: queryDB
* Purpose: read from the database
* @param sql
* Initializes the database connection.
*/
public void initConnection() {
try {
Class.forName("org.sqlite.JDBC"); // optional in newer JDBC versions
sDbUrl = "jdbc:sqlite:" + dbName;
conn = DriverManager.getConnection(sDbUrl);
} catch (ClassNotFoundException | SQLException e) {
System.err.println("Failed to connect to database: " + e.getMessage());
}
}

/**
* Query the database.
* @param sql SQL SELECT statement
* @return ResultSet
* @throws SQLException
*/
public ResultSet queryDB(String sql) throws SQLException {
ResultSet rs = null;
Statement stmt = conn.createStatement();
stmt.setQueryTimeout(timeout);
rs = stmt.executeQuery(sql);
return rs;
return stmt.executeQuery(sql);
}

/**
* Method: updateDB
* Purpose: Updates the database
* @param SQL
* @return boolean
* Execute a database update (INSERT, UPDATE, DELETE).
* @param SQL update statement
* @return boolean success
* @throws SQLException
*/
public boolean updateDB(String SQL) throws SQLException {
Statement stmt = conn.createStatement();
boolean success = stmt.execute(SQL);
return success;
return stmt.execute(SQL);
}

/**
* Method: count
* Purpose: Gets the count of records in the specified table
* @param table
* @return int
* Get the count of records in the specified table.
*/
public int count(String table) {
int cnt = 0;
try {
Statement stmt = conn.createStatement();
String sql = "Select count(*) as count from \"" + table + "\"";
String sql = "SELECT COUNT(*) AS count FROM \"" + table + "\"";
ResultSet rs = stmt.executeQuery(sql);
cnt = rs.getInt(1);
} catch (SQLException sqe) {
Expand All @@ -71,22 +73,31 @@ public int count(String table) {
}

/**
* Method: getMaxValue
* Purpose: Gets max value for a particular field in a particular table
* @param columnName
* @param table
* @return int
* Get max value for a column in a table.
*/
public int getMaxValue(String columnName, String table) {
int max = 0;
try {
Statement stmt = conn.createStatement();
String sql = "Select MAX(" + columnName + ") from " + table;
String sql = "SELECT MAX(" + columnName + ") FROM " + table;
ResultSet rs = stmt.executeQuery(sql);
max = rs.getInt(1);
} catch (SQLException sqe) {
System.out.println(sqe.getMessage());
}
return max;
}

/**
* Close the database connection safely.
*/
public void close() {
try {
if (conn != null && !conn.isClosed()) {
conn.close();
}
} catch (SQLException e) {
System.err.println("Failed to close DB: " + e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/**Class: Adventure.java
* @author Kyle Williams, Bradley Iverson, Miranda Darlington, Rick Price
* @author Sidibaba Simpara, Malik Key, Britney Familia, Angelica Jones
* @version 1.0
* Course: ITEC 3860, Spring 2022
* Written: 02/18 - 03/11
* Course: ITEC 3860, Summer 2025
*
*
* This class houses the main method and is the starting point of the program.
Expand Down