Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
24 changed files
with
717 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
cmake_minimum_required(VERSION 3.0) | ||
set(CMAKE_CXX_STANDARD 14) | ||
|
||
project(terminal_game_example CXX) | ||
|
||
# turns out that g++ will allow variable length arrays but I | ||
# dont' want students getting dependant on non-standard features | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wvla -Werror=vla") | ||
|
||
# limit number of errors shown to 1 | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wfatal-errors") | ||
|
||
# location of source code files | ||
include_directories(${CMAKE_SOURCE_DIR}/include) | ||
|
||
# tell cmake where to put the executables that it creates | ||
file(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) | ||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin ) | ||
|
||
# where to put the object files it creates | ||
file(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/lib) | ||
SET(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/lib) | ||
|
||
add_library( drawable src/drawable.cpp ) | ||
add_library( entity src/entity.cpp ) | ||
add_library( keyboard src/keyboard.cpp ) | ||
add_library( position src/position.cpp ) | ||
add_library( textbox src/textbox.cpp ) | ||
add_library( terminal src/terminal.cpp ) | ||
add_library( tilecolor src/tilecolor.cpp ) | ||
add_library( tile src/tile.cpp ) | ||
add_library( view src/view.cpp ) | ||
add_library( world src/world.cpp ) | ||
|
||
add_executable( main main.cpp ) | ||
target_link_libraries( main world view tile entity terminal textbox position keyboard ) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,10 @@ | ||
### Getting started | ||
There are various things you can do to quickly and efficiently configure your Codio Box to your exact requirements. | ||
### terminal-gui | ||
|
||
### GUI Applications and the Virtual Desktop | ||
The Virtual Desktop allows you auto develop GUI based applications using any programming language. You can install a Virtual Desktop in your Box. You can then start the desktop and view it within the Codio IDE or in a new browser tab. | ||
A simple and minimal terminal based GUI for Coventry ALL project development. | ||
Students are welcome to contribute features to this repo via pull request. | ||
|
||
[Virtual Desktop documentation](https://codio.com/docs/ide/boxes/installsw/gui/) | ||
As this is a work in progress I do not promise backwards compatibility but I will try and avoid major changes. | ||
|
||
### Documentation | ||
Work in progress | ||
|
||
### Command line access and the Terminal window | ||
All Codio Boxes provide sudo level privileges to the underlying Ubuntu server. This means you can install and configure any component you like. You access the terminal from the **Tools->Terminal** menu item. | ||
|
||
### Debugger | ||
The Codio IDE comes with a powerful visual debugger. Currently we support Python, Java, C, C++ and NodeJS. Other languages can be added on request. | ||
|
||
[Debugger documentation](https://codio.com/docs/ide/features/debugging/) | ||
|
||
|
||
### Content authoring and assessments | ||
Codio comes with a very powerful content authoring tool, Codio Guides. Guides is also where you create all forms of auto-graded assessments. | ||
|
||
- [Guides documentation](https://codio.com/docs/content/authoring/overview/) | ||
- [Assessments documentation](https://codio.com/docs/content/authoring/assessments/) | ||
|
||
### Templating Box configurations and projects | ||
Codio offers two very powerful templating options so you can create new projects from those templates with just a couple of clicks. **Stacks** allow you to create snapshots of the Box’s underlying software configuration. You can then create new projects from a Stack avoiding having to configure anew each time you start a new project. **Starter Packs** allow you to template an entire project, including workspace code. | ||
|
||
- [Stacks documentation](https://codio.com/docs/project/stacks/) | ||
- [Starter Packs documentation](https://codio.com/docs/project/packs/) | ||
|
||
### Install software | ||
You can always install software onto your Box using the command line. However, Codio offers a shortcut for commonly installed components that can be accessed from the **Tools->Install Software** menu. | ||
|
||
We can easily add new items to the Install Software screen, so feel free to submit requests. | ||
|
||
[Install Software documentation](https://codio.com/docs/ide/boxes/installsw/box-parts/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#ifndef DRAWABLE_H | ||
#define DRAWABLE_H | ||
|
||
#include "terminal.h" | ||
#include "position.h" | ||
|
||
class Drawable : public Position | ||
{ | ||
public: | ||
Terminal::Color foreground, background; | ||
|
||
Drawable( int _x=0, int _y=0, | ||
Terminal::Color _foreground=Terminal::Color::FG_DEFAULT, Terminal::Color _background=Terminal::Color::BG_DEFAULT ) | ||
: Position( _x, _y ), foreground(_foreground), background(_background) {} | ||
|
||
virtual void draw() const = 0; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#ifndef ENTITY_H | ||
#define ENTITY_H | ||
|
||
#include "drawable.h" | ||
#include <iostream> | ||
|
||
class Entity : public Drawable | ||
{ | ||
public: | ||
char appearance; | ||
|
||
Entity( char _appearance, | ||
int _x=0, int _y=0, | ||
Terminal::Color _foreground=Terminal::Color::FG_DEFAULT, Terminal::Color _background=Terminal::Color::BG_DEFAULT ) | ||
: Drawable( _x, _y, _foreground, _background ), appearance(_appearance) | ||
{ | ||
} | ||
|
||
void draw() const; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#ifndef KEYBOARD_H | ||
#define KEYBOARD_H | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <sys/time.h> | ||
#include <sys/types.h> | ||
#include <unistd.h> | ||
#include <fcntl.h> | ||
#include <termios.h> | ||
|
||
class Keyboard | ||
{ | ||
private: | ||
static termios oldSettings, newSettings; | ||
static bool grabbed; | ||
|
||
public: | ||
Keyboard(); | ||
|
||
static void grab(); | ||
|
||
static char get( float timeout = 0.5f ); | ||
|
||
static void release(); | ||
|
||
~Keyboard(); | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#ifndef POSITION_H | ||
#define POSITION_H | ||
|
||
#include <ostream> | ||
|
||
class Position | ||
{ | ||
public: | ||
int x, y; | ||
|
||
Position( int _x=0, int _y=0 ) | ||
: x(_x), y(_y) | ||
{} | ||
|
||
void up(); | ||
void down(); | ||
void left(); | ||
void right(); | ||
|
||
friend std::ostream& operator<<( std::ostream& os, const Position& p ); | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#ifndef TERMINAL_H | ||
#define TERMINAL_H | ||
|
||
#include <iostream> | ||
|
||
namespace Terminal | ||
{ | ||
enum Color | ||
{ | ||
FG_BLACK = 30, | ||
FG_RED = 31, | ||
FG_GREEN = 32, | ||
FG_YELLOW = 33, | ||
FG_BLUE = 34, | ||
FG_MAGENTA = 35, | ||
FG_CYAN = 36, | ||
FG_WHITE = 37, | ||
FG_DEFAULT = 39, | ||
|
||
BG_BLACK = 40, | ||
BG_RED = 41, | ||
BG_GREEN = 42, | ||
BG_YELLOW = 43, | ||
BG_BLUE = 44, | ||
BG_MAGENTA = 45, | ||
BG_CYAN = 46, | ||
BG_WHITE = 47, | ||
BG_DEFAULT = 49 | ||
}; | ||
|
||
std::ostream& operator<<( std::ostream& os, const Color& c ); | ||
|
||
class Position | ||
{ | ||
private: | ||
int x, y; | ||
public: | ||
Position( int _x, int _y ); | ||
|
||
friend std::ostream& operator<<( std::ostream& os, const Position& p ); | ||
}; | ||
|
||
std::ostream& operator<<( std::ostream& os, const Position& p ); | ||
|
||
const std::string Default = "\033[39m\033[49m"; | ||
const std::string Clear = "\033[2J\033[1;1H"; | ||
|
||
const std::string CursorOff = "\e[?25l"; | ||
const std::string CursorOn = "\e[?25h"; | ||
|
||
void cursor( bool onoff ); | ||
|
||
void defaults(); | ||
|
||
void clear(); | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#ifndef TEXTBOX_H | ||
#define TEXTBOX_H | ||
|
||
#include <iostream> | ||
#include <iomanip> | ||
#include <string> | ||
#include <sstream> | ||
#include "drawable.h" | ||
|
||
|
||
|
||
class TextBox : public Drawable | ||
{ | ||
public: | ||
int width; | ||
std::stringstream ss; | ||
|
||
TextBox( int _x, int _y, int _width) | ||
: Drawable( _x, _y ), width(_width) {} | ||
|
||
void draw() const; | ||
|
||
void clear(); | ||
}; | ||
|
||
template<typename T> | ||
TextBox& operator<<( TextBox& os, T t ) | ||
{ | ||
os.ss << t; | ||
return os; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#ifndef TILE_H | ||
#define TILE_H | ||
|
||
#include <iostream> | ||
#include "terminal.h" | ||
|
||
class Tile | ||
{ | ||
public: | ||
static const char defaultContents = '-'; | ||
|
||
Terminal::Color foreground, background; | ||
char contents; | ||
|
||
Tile( char _contents=defaultContents, | ||
Terminal::Color _foreground=Terminal::Color::FG_DEFAULT, | ||
Terminal::Color _background=Terminal::Color::BG_DEFAULT ) | ||
: contents(_contents), foreground(_foreground), background(_background) {} | ||
|
||
void draw() const; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ifndef TILECOLOR_H | ||
#define TILECOLOR_H | ||
|
||
#include "terminal.h" | ||
#include <iostream> | ||
|
||
class TileColor | ||
{ | ||
public: | ||
Terminal::Color foreground; | ||
Terminal::Color background; | ||
|
||
TileColor( Terminal::Color _foreground=Terminal::Color::FG_DEFAULT, | ||
Terminal::Color _background=Terminal::Color::BG_DEFAULT ) | ||
: foreground(_foreground), background(_background) | ||
{} | ||
|
||
friend std::ostream& operator<<( std::ostream& os, const TileColor& c ); | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef VIEW_H | ||
#define VIEW_H | ||
|
||
#include "drawable.h" | ||
#include "world.h" | ||
|
||
class World; | ||
|
||
class View : public Position | ||
{ | ||
public: | ||
World& world; | ||
std::set<const Drawable*> drawables; | ||
const int width, height; | ||
|
||
View( World& _world, int _width=-1, int _height=-1 ); | ||
|
||
bool move( int x, int y ); | ||
|
||
void add( const Drawable& drawable ); | ||
|
||
void draw() const; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#ifndef WORLD_H | ||
#define WORLD_H | ||
|
||
#include <vector> | ||
#include <set> | ||
#include <tuple> | ||
#include <algorithm> | ||
#include <iomanip> | ||
#include <stdexcept> | ||
|
||
|
||
#include "terminal.h" | ||
#include "tile.h" | ||
#include "entity.h" | ||
#include "view.h" | ||
|
||
class View; | ||
|
||
class World | ||
{ | ||
private: | ||
std::vector<Tile> world; | ||
std::set<const Entity*> entities; | ||
|
||
public: | ||
const int width, height; | ||
|
||
World( int _width, int _height ); | ||
|
||
//bool set( int x, int y, Tile t ); | ||
|
||
void fill( Tile t ); | ||
|
||
Tile& get( int x, int y ); | ||
|
||
void add( Entity& entity ); | ||
|
||
friend class View; | ||
}; | ||
|
||
#endif |
Oops, something went wrong.