Commit 63343fc5 authored by Noah Olsen's avatar Noah Olsen

commit

parent 22b90558
Pipeline #4719 failed with stages
in 55 seconds
......@@ -94,38 +94,38 @@ code_coverage:
expire_in: 7 days
# deploy_prod:
# stage: deploy
# before_script:
# - apt-get update -qq
# - apt-get install -qq curl
# - 'which ssh-agent || ( apt-get install -qq openssh-client )'
# - eval $(ssh-agent -s)
# - ssh-add <(echo "$SSH_PRIVATE_KEY" | base64 -d -w 0)
# - mkdir -p ~/.ssh
# - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
# script:
# - ELF_NAME="${CI_PROJECT_NAMESPACE}-quotes"
# - SSH_COMMAND_STRING="if pgrep ${ELF_NAME}; then pkill ${ELF_NAME}; fi && "
# # Double quotes around everything needed as it has a colon in it
# - "SSH_COMMAND_STRING+=\"curl --location --header 'PRIVATE-TOKEN: ${API_TOKEN}' '${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/jobs/artifacts/${CI_BUILD_REF_NAME}/raw/build/quotes?job=build_programs' --output ${ELF_NAME} &&\" "
# # Make sure the file is executable
# - SSH_COMMAND_STRING+="chmod +x ${ELF_NAME} && "
# # Start it in the background in such a way that SSH will not hang when we exit
# - SSH_COMMAND_STRING+="(nohup ./${ELF_NAME} ${RUN_PORT} > /dev/null 2>&1 &) && "
# # Make sure the program is running, if it is, we exit gracefully
# - SSH_COMMAND_STRING+="if pgrep ${ELF_NAME}; then exit; fi && "
# # If the program is not running, exit with an error code to say something went wrong
# - SSH_COMMAND_STRING+="exit 1"
# # Print it out so we can see what happened for debugging purposes.
# - echo "$SSH_COMMAND_STRING"
# # Execute the deploy
# - ssh $SSH_USER@$SSH_HOST "${SSH_COMMAND_STRING}"
# # Make sure it is running
# - "curl --location http://${SSH_HOST}:${RUN_PORT} | grep \"Go to /quote/# or /random to get a quote.\""
# when: manual
# only:
# - master
deploy_prod:
stage: deploy
before_script:
- apt-get update -qq
- apt-get install -qq curl
- 'which ssh-agent || ( apt-get install -qq openssh-client )'
- eval $(ssh-agent -s)
- ssh-add <(echo "$SSH_PRIVATE_KEY" | base64 -d -w 0)
- mkdir -p ~/.ssh
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
script:
- ELF_NAME="${CI_PROJECT_NAMESPACE}-quotes"
- SSH_COMMAND_STRING="if pgrep ${ELF_NAME}; then pkill ${ELF_NAME}; fi && "
# Double quotes around everything needed as it has a colon in it
- "SSH_COMMAND_STRING+=\"curl --location --header 'PRIVATE-TOKEN: ${API_TOKEN}' '${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/jobs/artifacts/${CI_BUILD_REF_NAME}/raw/build/quotes?job=build_programs' --output ${ELF_NAME} &&\" "
# Make sure the file is executable
- SSH_COMMAND_STRING+="chmod +x ${ELF_NAME} && "
# Start it in the background in such a way that SSH will not hang when we exit
- SSH_COMMAND_STRING+="(nohup ./${ELF_NAME} ${RUN_PORT} > /dev/null 2>&1 &) && "
# Make sure the program is running, if it is, we exit gracefully
- SSH_COMMAND_STRING+="if pgrep ${ELF_NAME}; then exit; fi && "
# If the program is not running, exit with an error code to say something went wrong
- SSH_COMMAND_STRING+="exit 1"
# Print it out so we can see what happened for debugging purposes.
- echo "$SSH_COMMAND_STRING"
# Execute the deploy
- ssh $SSH_USER@$SSH_HOST "${SSH_COMMAND_STRING}"
# Make sure it is running
- "curl --location http://${SSH_HOST}:${RUN_PORT} | grep \"Go to /quote/# or /random to get a quote.\""
when: manual
only:
- master
variables:
......
/*************************************************************************
*
* Homework 4: Exploring continuous deployment.
*
* File Name: quote.cpp
* Course: CPTR 245
*
*/
#include "Quotes.h"
#include <random>
#include <string>
#include <vector>
Quotes::Quotes(unsigned int seed) {
this->seed = seed;
quotes = {
{"Andrew Platner", "", ""},
{"Austin Garner",
"Men talk of killing time, while time quietly kills them.",
"Dion Boucicault"},
{"Cameron Bierwagen", "", ""},
{"Elon Bontemps",
"True humility is not thinking less of yourself; it is thinking of "
"yourself less",
"C.S. Lewis"},
{"Ivan Guillen",
"Logic will get you from A to B. Imagination will take you "
"everywhere.",
"Albert Einstein"},
{"James Foster",
"The most disastrous thing that you can ever learn is your first "
"programming language.",
"Alan Kay"},
{"Jarod Owen", "I do not fear computers. I fear lack of them.",
"Isaac Asimov"},
{"Jeff Peters", "God does not play dice with the universe.",
"A. Einstein"},
{"Kaelan Willauer",
"Action without a name, a 'who' attached to it, is meaningless.",
"St. Jerome"},
{"Luke Hagan", "", ""},
{"Luke Irvine",
"Life is what happens when you're busy making other plans.", "Lennon"},
{"Michael Stacy",
"Measuring programming progress by number of lines "
"is like measuring aircraft build process by the weight",
"anonymous author"},
{"Nelson Phillips", "Ogres are like onions, they have layers", "Shrek"},
{"Noah Olsen", "The greatest teacher, failure is", "Master Yoda"},
{"Owen Hoffman", "", ""},
{"Welcome! Please select a menu option.", "Talk is cheap. Show me the code.",
"Linus Torvalds"},
{"Samuel Nguyen", "", ""},
{"Trevor Claridge",
"Its easy to make frends if you let pepul laff at you.",
"Daniel Keyes"},
{"Trevor Natiuk",
"Before you marry a person, you should first make "
"them use a computer with slow Internet to see who they really are",
"Will Ferrell"},
{"Will Hensel",
"The question of whether a computer can think is no more "
"interesting than the question of whether a submaring can swim.",
"Edsger W. Dijkstra"},
};
}
Quote Quotes::getRandomQuote() {
int index = rand_r(&seed) % quotes.size();
return quotes.at(index);
}
Quote Quotes::getQuote(int id) {
int index = id % quotes.size();
return quotes.at(index);
}
/*************************************************************************
*
* Homework 4: Exploring continuous deployment.
*
* File Name: quote.h
* Course: CPTR 245
*
*/
#include <string>
#include <vector>
struct Quote {
std::string student;
std::string quote;
std::string author;
};
class Quotes {
private:
std::vector<Quote> quotes;
unsigned int seed;
public:
explicit Quotes(unsigned int);
Quote getRandomQuote();
Quote getQuote(int);
};
/*************************************************************************
*
* Homework 4: Exploring continuous deployment.
*
* File Name: quote.cpp
* Course: CPTR 245
*
*/
#include <cpp-httplib/httplib.h>
#include <iostream>
#include <stdexcept>
#include <string>
#include <vector>
#include "Quotes.h"
std::vector<std::string> explode(const std::string &s, const char &c) {
std::string buff;
std::vector<std::string> v;
for (auto n : s) {
if (n != c) {
buff += n;
} else if (n == c && !buff.empty()) {
v.push_back(buff);
buff = "";
}
}
if (!buff.empty()) {
v.push_back(buff);
}
return v;
}
int main(int argc, char **argv) {
if (argc != 2) {
std::cerr << "You must provide a port to run on" << std::endl;
return -1;
}
int port = 0;
try {
port = std::stoi(argv[1]);
} catch (const std::invalid_argument &e) {
std::cerr << "Invalid port specified" << std::endl;
return -1;
}
if (port < 1024 || port > 65535) {
std::cerr << "Port is not in allowable range" << std::endl;
return -1;
}
httplib::Server svr;
svr.Get("/", [](const httplib::Request &req, httplib::Response &res) {
res.set_content("Go to /quote/# or /random to get a quote.", "text/plain");
});
svr.Get("/random",
[](const httplib::Request &req, httplib::Response &res) {
Quotes myQuotes(time(NULL));
Quote quote = myQuotes.getRandomQuote();
std::string output = "Today's Random Quote was submitted by " +
quote.student + ".\n\n" + "\"" + quote.quote +
"\"\n ~ " + quote.author + "\n";
res.set_content(output, "text/plain");
});
svr.Get(R"(/quote/([0-9]+))",
[](const httplib::Request &req, httplib::Response &res) {
auto urlExploded = explode(req.matches[0], '/');
auto numbers = std::vector<std::string>(urlExploded.begin() + 1,
urlExploded.end());
Quotes myQuotes(time(NULL));
Quote quote = myQuotes.getQuote(std::stoi(numbers[0]));
std::string output = "Today's Quote was submitted by " +
quote.student + ".\n\n" + "\"" + quote.quote +
"\"\n ~ " + quote.author + "\n";
res.set_content(output, "text/plain");
});
svr.listen("0.0.0.0", port);
return 0;
}
......@@ -4,12 +4,14 @@
#include <iostream>
#include <string>
#include <vector>
#include "Grid.h"
#include "Moves.h"
using namespace std;
class MoveSet;
using std::cerr;
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
// void Entity::action() {}
......@@ -17,13 +19,18 @@ void Entity::move() {
}
void Entity::setPos() {
srand(time(0));
// Random Positioning
this->colPos = rand() % 4;
this->rowPos = rand() % 4;
this->colPos = rand_r() % 3;
this->rowPos = rand_r() % 3;
}
bool Entity::checkHealth() {
return (con > 0);
bool life = true;
if (con <= 0) {
life = false;
}
return life;
}
Player::Player() {
......@@ -31,41 +38,20 @@ Player::Player() {
this->con = 10;
this->str = 10;
this->dex = 10;
// setClass('a');
}
void Player::action() {
char act;
do {
cout << "What will you do?" << endl;
cout << " a. Light Attack" << endl;
cout << " b. Heavy Attack" << endl;
cout << " c. Defend" << endl;
cout << " d. Counter" << endl;
cout << " e. Flee" << endl;
cout << " Enter Action Here: ";
cin >> act;
switch (act) {
case 'a':
// callLightAttack();
break;
case 'b':
// callHeavyAttack();
break;
case 'c':
// callDefend();
break;
case 'd':
break;
case 'e':
break;
default:
cout << "Please enter a valid option." << endl;
break;
}
} while (act != 'a' && act != 'b' && act != 'c' && act != 'd' &&
act != 'e' && act != 'f');
cout << "What will you do?" << endl;
cout << " a. Light Attack" << endl;
cout << " b. Heavy Attack" << endl;
cout << " c. Defend" << endl;
cout << " d. Counter" << endl;
cout << " f. Flee" << endl;
cout << " Enter Action Here: ";
cin >> act;
switch (act) {}
}
void Player::setClass(char Class) {
......@@ -77,28 +63,16 @@ void Player::setClass(char Class) {
break;
case 'b': // Rogue
break;
case 'c': // Mage
break;
}
}
void Enemy::action() {
int act = rand() % 10;
if (con <= 2) {
// Attempt flee
} else {
if (act <= 2) {
// Heavy Attack
} else if (act >= 3 && act <= 5) {
// Light Attack
} else if (act >= 6 && act <= 8) {
// Defend
} else if (act >= 9) {
// Counter
}
}
}
void Enemy::setBossClass() {
srand(time(0));
int monster = rand_r() % 3; // Boss Monster Randomization
void Enemy::setBossClassByChoice(int boss) {
switch (boss) {
switch (monster) {
case 1: // Minotaur
this->str = 16;
this->con = 14;
......@@ -117,12 +91,6 @@ void Enemy::setBossClassByChoice(int boss) {
}
}
void Enemy::setBossClassByRand() {
int monster = rand() % 3; // Boss Monster Randomization
setBossClassByChoice(monster);
}
void Enemy::setClassByChoice(int monster) {
switch (monster) {
case 1: // Goblin
......@@ -144,16 +112,28 @@ void Enemy::setClassByChoice(int monster) {
}
void Enemy::setClassByRand() {
int monster = rand() % 3; // Monster Randomization
srand(time(0));
int monster = rand_r() % 3; // Monster Randomization
setClassByChoice(monster);
switch (monster) {
case 1: // Goblin
this->str = 6;
this->con = 6;
this->dex = 12;
break;
case 2: // Orc
this->str = 14;
this->con = 10;
this->dex = 8;
break;
case 3: // Skeleton
this->str = 8;
this->con = 10;
this->dex = 10;
break;
}
}
Enemy::Enemy(bool boss) {
Enemy::Enemy() {
setPos();
if (boss) {
setBossClassByRand();
} else {
setClassByRand();
}
}
// "Copyright [year] <Copyright Owner>"
#ifndef ENTITY_H
#define ENTITY_H
#ifndef SRC_ENTITY_H_
#define SRC_ENTITY_H_
// no includes?
#include <string>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
class MoveSet;
class Entity {
public:
public:
bool checkHealth();
void move();
void setPos();
int getCol() {
return colPos;
}
int getRow() {
return rowPos;
}
virtual void action() const = 0;
virtual void setClass() const = 0;
protected:
// MoveSet* moves;
protected:
int colPos;
int rowPos;
int con;
......@@ -27,29 +31,28 @@ class Entity {
};
class Player : public Entity {
public:
public:
Player();
void action();
void setClass(char Class);
private:
private:
// Vector of inventory items
// Vector of equipped items
};
class Enemy : public Entity {
public:
Enemy(bool boss);
public:
Enemy();
void action();
void setBossClassByChoice(int boss);
void setBossClassByRand();
void setBossClass();
void setClassByRand();
void setClassByChoice(int monster);
bool seesPlayer();
private:
private:
// Vector of drop items
// Vector of equipped items
};
#endif
#endif // SRC_ENTITY_H_
// "Copyright [year] <Copyright Owner>"
#include <cstdlib>
#include <iostream>
using namespace std;
#include "Grid.h"
// randomly generate grid and start score at 0
// Ensure player and enemies start at different places
// define the functions for grid
char Grid::getDirection() {
cout << "Where do you want to go?" << endl;
cout << "Please enter u for up, r for right, d for down, l for left, or m "
"for a random direction."
<< endl;
cin >> direction;
return direction;
}
using std::cerr;
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
// 2D array using subtraction in direction
/*int Grid::move(int GridRows, int GridColumns, char direction) {
if (direction == 'u') {
if ((room == 3) || (room == 2) || (room == 1)) {
} else {
room = room - 3;
}
} else if (direction == 'r') {
if ((room == 3) || (room == 6) || (room == 9)) {
} else {
room = room + 1;
}
} else if (direction == 'd') {
if ((room == 7) || (room == 8) || (room == 9)) {
} else {
room = room + 3;
}
} else if (direction == 'l') {
if ((room == 1) || (room == 4) || (room == 7)) {
} else {
room = room - 1;
}
} else if (direction == 'm') {
room = move(room, getRandDirection());
} else {
cout << "Invalid entry. Please input valid entry. ";
room = move(room, getDirection());
}
return room;
}*/
int Grid::move(int GridRows, int GridColumns, char direction) {
if (direction == 'u') {
if ((GridRows == 4) || (GridRows == 3) || (GridRows == 2) ||
(GridRows == 1)) {
} else {
GridRows += 1;
}
} else if (direction == 'r') {
if ((GridColumns == 4) || (GridColumns == 8) || (GridColumns == 12) ||
(GridColumns == 16)) {
} else {
GridColumns += 1;
}
} else if (direction == 'd') {
if ((GridRows == 13) || (GridRows == 14) || (GridRows == 15) ||
(GridRows == 16)) {
} else {
GridRows -= 1;
}
} else if (direction == 'l') {
if ((GridColumns == 1) || (GridColumns == 5) || (GridColumns == 9) ||
(GridColumns == 13)) {
} else {
GridColumns -= 1;
}
} else if (direction == 'm') {
move(GridRows, GridColumns, getRandDirection());
}
}
char Grid::getRandDirection() {
otherDirection = rand() % 5 + 1;
if (otherDirection == 5) {
return 'u';
} else if (otherDirection == 3) {
return 'r';
} else if (otherDirection == 4) {
return 'd';
} else {
return 'l';
}
}
void Grid::printGrid(int GridRows, int GridColumns) {
char grid[GridRows][GridColumns];
for (int i = 0; i < GridRows; i++) {
for (int j = 0; j < GridColumns; j++) {
grid[i][j] = '.';