added more code
This commit is contained in:
1
CPE455/ncursesdemo/.vscode/configurationCache.log
vendored
Normal file
1
CPE455/ncursesdemo/.vscode/configurationCache.log
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"buildTargets":["clean","make","ncursesdemo"],"launchTargets":["/home/student/anw0044/CPE455/ncursesdemo>ncursesdemo()"],"customConfigurationProvider":{"workspaceBrowse":{"browsePath":["/home/student/anw0044/CPE455/ncursesdemo"],"compilerArgs":["-g","-Wall","--pedantic","-ansi","--coverage","ncursesdemo.c","-o","ncursesdemo","-l","ncurses"],"compilerPath":"/usr/bin/gcc","windowsSdkVersion":""},"fileIndex":[["/home/student/anw0044/CPE455/ncursesdemo/ncursesdemo.c",{"uri":{"$mid":1,"fsPath":"/home/student/anw0044/CPE455/ncursesdemo/ncursesdemo.c","path":"/home/student/anw0044/CPE455/ncursesdemo/ncursesdemo.c","scheme":"file"},"configuration":{"defines":[],"includePath":[],"forcedInclude":[],"compilerPath":"/usr/bin/gcc","compilerArgs":["-g","-Wall","--pedantic","-ansi","--coverage","ncursesdemo.c","-o","ncursesdemo","-l","ncurses"],"windowsSdkVersion":""},"compileCommand":{"command":"gcc -g -Wall --pedantic -ansi --coverage ncursesdemo.c -o ncursesdemo -l ncurses","directory":"/home/student/anw0044/CPE455/ncursesdemo","file":"/home/student/anw0044/CPE455/ncursesdemo/ncursesdemo.c"}}]]}}
|
5
CPE455/ncursesdemo/.vscode/dryrun.log
vendored
Normal file
5
CPE455/ncursesdemo/.vscode/dryrun.log
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
make --dry-run --always-make --keep-going --print-directory
|
||||
make: Entering directory `/home/student/anw0044/CPE455/ncursesdemo'
|
||||
gcc -g -Wall --pedantic -ansi --coverage ncursesdemo.c -o ncursesdemo -l ncurses
|
||||
make: Leaving directory `/home/student/anw0044/CPE455/ncursesdemo'
|
||||
|
3
CPE455/ncursesdemo/.vscode/settings.json
vendored
Normal file
3
CPE455/ncursesdemo/.vscode/settings.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"makefile.extensionOutputFolder": "./.vscode"
|
||||
}
|
329
CPE455/ncursesdemo/.vscode/targets.log
vendored
Normal file
329
CPE455/ncursesdemo/.vscode/targets.log
vendored
Normal file
@ -0,0 +1,329 @@
|
||||
make all --print-data-base --no-builtin-variables --no-builtin-rules --question
|
||||
# GNU Make 3.82
|
||||
# Built for x86_64-redhat-linux-gnu
|
||||
# Copyright (C) 2010 Free Software Foundation, Inc.
|
||||
# License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
|
||||
# This is free software: you are free to change and redistribute it.
|
||||
# There is NO WARRANTY, to the extent permitted by law.
|
||||
|
||||
# Make data base, printed on Thu Apr 7 10:06:16 2022
|
||||
|
||||
# Variables
|
||||
|
||||
# automatic
|
||||
<D = $(patsubst %/,%,$(dir $<))
|
||||
# automatic
|
||||
?F = $(notdir $?)
|
||||
# environment
|
||||
DESKTOP_SESSION = gnome-classic
|
||||
# default
|
||||
.SHELLFLAGS := -c
|
||||
# environment
|
||||
XDG_SESSION_TYPE = x11
|
||||
# environment
|
||||
VSCODE_LOG_NATIVE = false
|
||||
# environment
|
||||
MODULEPATH = /usr/share/Modules/modulefiles:/etc/modulefiles
|
||||
# automatic
|
||||
?D = $(patsubst %/,%,$(dir $?))
|
||||
# automatic
|
||||
@D = $(patsubst %/,%,$(dir $@))
|
||||
# environment
|
||||
XAUTHORITY = /run/gdm/auth-for-anw0044-r85HPv/database
|
||||
# environment
|
||||
GDMSESSION = gnome-classic
|
||||
# environment
|
||||
XMODIFIERS = @im=ibus
|
||||
# makefile
|
||||
CURDIR := /home/student/anw0044/CPE455/ncursesdemo
|
||||
# makefile
|
||||
SHELL = /bin/sh
|
||||
# environment
|
||||
GDM_LANG = en_US.UTF-8
|
||||
# environment
|
||||
VTE_VERSION = 5204
|
||||
# environment
|
||||
VSCODE_NLS_CONFIG = {"locale":"en-us","availableLanguages":{},"_languagePackSupport":true}
|
||||
# environment
|
||||
_ = /usr/bin/make
|
||||
# makefile (from `Makefile', line 6)
|
||||
CFLAGS = -g -Wall --pedantic -ansi --coverage
|
||||
# environment
|
||||
ftp_proxy = http://172.21.0.47:3128/
|
||||
# environment
|
||||
LESSOPEN = ||/usr/bin/lesspipe.sh %s
|
||||
# makefile (from `Makefile', line 1)
|
||||
MAKEFILE_LIST := Makefile
|
||||
# automatic
|
||||
@F = $(notdir $@)
|
||||
# environment
|
||||
HISTCONTROL = ignoredups
|
||||
# environment
|
||||
QT_IM_MODULE = ibus
|
||||
# environment
|
||||
USERNAME = anw0044
|
||||
# environment
|
||||
XDG_DATA_DIRS = /home/student/anw0044/.local/share/flatpak/exports/share/:/var/lib/flatpak/exports/share/:/usr/local/share/:/usr/share/
|
||||
# environment
|
||||
DBUS_SESSION_BUS_ADDRESS = unix:abstract=/tmp/dbus-EFKMXbehS5,guid=669cf737c8dcaa80e1706587624ef7e5
|
||||
# environment
|
||||
VSCODE_VERBOSE_LOGGING = true
|
||||
# environment
|
||||
VSCODE_IPC_HOOK_EXTHOST = /run/user/17833/vscode-ipc-45b6c4b3-7426-4237-ad55-20f60392d975.sock
|
||||
# environment
|
||||
VSCODE_CWD = /home/student/anw0044/CPE455/ncursesdemo
|
||||
# environment
|
||||
NO_PROXY = localhost,127.0.0.0/8,::1
|
||||
# environment
|
||||
LM_LICENSE_FILE = 1717@lm1
|
||||
# environment
|
||||
SESSION_MANAGER = local/unix:@/tmp/.ICE-unix/19036,unix/unix:/tmp/.ICE-unix/19036
|
||||
# environment
|
||||
XDG_RUNTIME_DIR = /run/user/17833
|
||||
# environment
|
||||
XDG_MENU_PREFIX = gnome-
|
||||
# environment
|
||||
VSCODE_LOG_STACK = false
|
||||
# environment
|
||||
ELECTRON_RUN_AS_NODE = 1
|
||||
# default
|
||||
.FEATURES := target-specific order-only second-expansion else-if shortest-stem undefine oneshell archives jobserver check-symlink
|
||||
# environment
|
||||
XDG_SESSION_DESKTOP = gnome-classic
|
||||
# environment
|
||||
SSH_AUTH_SOCK = /run/user/17833/keyring/ssh
|
||||
# automatic
|
||||
%F = $(notdir $%)
|
||||
# environment
|
||||
DISPLAY = :0
|
||||
# environment
|
||||
no_proxy = localhost,127.0.0.0/8,::1
|
||||
# environment
|
||||
IMSETTINGS_INTEGRATE_DESKTOP = yes
|
||||
# environment
|
||||
PWD = /home/student/anw0044/CPE455/ncursesdemo
|
||||
# environment
|
||||
XDG_SEAT = seat0
|
||||
# environment
|
||||
SSH_AGENT_PID = 19161
|
||||
# environment
|
||||
ORIGINAL_XDG_CURRENT_DESKTOP = GNOME-Classic:GNOME
|
||||
# environment
|
||||
VSCODE_AMD_ENTRYPOINT = vs/workbench/api/node/extensionHostProcess
|
||||
# environment
|
||||
HOME = /home/student/anw0044
|
||||
# environment
|
||||
LD_LIBRARY_PATH = /opt/Qt/5.12.4/gcc_64/lib:
|
||||
# environment
|
||||
VSCODE_CLI = 1
|
||||
# environment
|
||||
VSCODE_CODE_CACHE_PATH = /home/student/anw0044/.config/Code/CachedData/c722ca6c7eed3d7987c0d5c3df5c45f6b15e77d1
|
||||
# environment
|
||||
LOGNAME = anw0044
|
||||
# environment
|
||||
APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL = 1
|
||||
# environment
|
||||
ELECTRON_NO_ATTACH_CONSOLE = 1
|
||||
# environment
|
||||
VSCODE_HANDLES_UNCAUGHT_ERRORS = true
|
||||
# default
|
||||
MAKE_VERSION := 3.82
|
||||
# environment
|
||||
GNOME_DESKTOP_SESSION_ID = this-is-deprecated
|
||||
# automatic
|
||||
^D = $(patsubst %/,%,$(dir $^))
|
||||
# environment
|
||||
HOSTNAME = eb246-13
|
||||
# environment
|
||||
XDG_VTNR = 1
|
||||
# environment
|
||||
MAKELEVEL := 0
|
||||
# environment
|
||||
COLORTERM = truecolor
|
||||
# default
|
||||
MAKE = $(MAKE_COMMAND)
|
||||
# default
|
||||
MAKECMDGOALS := all
|
||||
# environment
|
||||
PATH = /opt/Qt/5.12.4/gcc_64/bin/:/opt/Qt/Tools/QtCreator/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin
|
||||
# environment
|
||||
SHLVL = 4
|
||||
# makefile (from `Makefile', line 5)
|
||||
CC = gcc
|
||||
# environment
|
||||
GNOME_SHELL_SESSION_MODE = classic
|
||||
# environment
|
||||
XDG_SESSION_ID = 1483
|
||||
# environment
|
||||
USER = anw0044
|
||||
# makefile
|
||||
.DEFAULT_GOAL := ncursesdemo
|
||||
# environment
|
||||
XDG_CURRENT_DESKTOP = GNOME-Classic:GNOME
|
||||
# automatic
|
||||
%D = $(patsubst %/,%,$(dir $%))
|
||||
# environment
|
||||
define BASH_FUNC_module()
|
||||
() { eval `/usr/bin/modulecmd bash $*`
|
||||
}
|
||||
endef
|
||||
# default
|
||||
MAKE_COMMAND := make
|
||||
# default
|
||||
.VARIABLES :=
|
||||
# environment
|
||||
IMSETTINGS_MODULE = none
|
||||
# automatic
|
||||
*F = $(notdir $*)
|
||||
# environment
|
||||
VSCODE_IPC_HOOK = /run/user/17833/vscode-cca9002f-1.65.2-main.sock
|
||||
# makefile
|
||||
MAKEFLAGS = Rrqp
|
||||
# environment
|
||||
MFLAGS = -Rrqp
|
||||
# automatic
|
||||
*D = $(patsubst %/,%,$(dir $*))
|
||||
# environment
|
||||
MAIL = /var/spool/mail/anw0044
|
||||
# environment
|
||||
LOADEDMODULES =
|
||||
# automatic
|
||||
+D = $(patsubst %/,%,$(dir $+))
|
||||
# environment
|
||||
GDK_BACKEND = x11
|
||||
# environment
|
||||
MODULESHOME = /usr/share/Modules
|
||||
# automatic
|
||||
+F = $(notdir $+)
|
||||
# environment
|
||||
NO_AT_BRIDGE = 1
|
||||
# environment
|
||||
VSCODE_PIPE_LOGGING = true
|
||||
# default
|
||||
MAKEFILES :=
|
||||
# automatic
|
||||
<F = $(notdir $<)
|
||||
# environment
|
||||
https_proxy = https://172.21.0.47:3128/
|
||||
# environment
|
||||
LC_ALL = C
|
||||
# environment
|
||||
SBX_CHROME_API_RQ = 1
|
||||
# environment
|
||||
SANDBOX_LD_LIBRARY_PATH = /opt/Qt/5.12.4/gcc_64/lib:
|
||||
# environment
|
||||
GJS_DEBUG_TOPICS = JS ERROR;JS LOG
|
||||
# environment
|
||||
GNOME_TERMINAL_SCREEN = /org/gnome/Terminal/screen/60d05c49_e4d3_4916_80f4_11300cb409d0
|
||||
# automatic
|
||||
^F = $(notdir $^)
|
||||
# environment
|
||||
GNOME_TERMINAL_SERVICE = :1.106
|
||||
# default
|
||||
SUFFIXES :=
|
||||
# environment
|
||||
HISTSIZE = 1000
|
||||
# environment
|
||||
CHROME_DESKTOP = code-url-handler.desktop
|
||||
# environment
|
||||
WINDOWPATH = 1:1:1:1:1:1:1:1:1
|
||||
# default
|
||||
.INCLUDE_DIRS = /usr/include /usr/local/include /usr/include
|
||||
# environment
|
||||
GJS_DEBUG_OUTPUT = stderr
|
||||
# default
|
||||
.RECIPEPREFIX :=
|
||||
# environment
|
||||
http_proxy = http://172.21.0.47:3128/
|
||||
# environment
|
||||
LANG = C
|
||||
# environment
|
||||
TERM = xterm-256color
|
||||
# environment
|
||||
VSCODE_PID = 21080
|
||||
# variable set hash-table stats:
|
||||
# Load=114/1024=11%, Rehash=0, Collisions=15/136=11%
|
||||
|
||||
# Pattern-specific Variable Values
|
||||
|
||||
# No pattern-specific variable values.
|
||||
|
||||
# Directories
|
||||
|
||||
# . (device 45, inode 192937990): 12 files, no impossibilities.
|
||||
|
||||
# 12 files, no impossibilities in 1 directories.
|
||||
|
||||
# Implicit Rules
|
||||
|
||||
# No implicit rules.
|
||||
|
||||
# Files
|
||||
|
||||
# Not a target:
|
||||
ncursesdemo.c:
|
||||
# Implicit rule search has not been done.
|
||||
# Modification time never checked.
|
||||
# File has not been updated.
|
||||
|
||||
# Not a target:
|
||||
all:
|
||||
# Command line target.
|
||||
# Implicit rule search has been done.
|
||||
# File does not exist.
|
||||
# File has not been updated.
|
||||
|
||||
# Not a target:
|
||||
.SUFFIXES:
|
||||
# Implicit rule search has not been done.
|
||||
# Modification time never checked.
|
||||
# File has not been updated.
|
||||
|
||||
# Not a target:
|
||||
Makefile:
|
||||
# Implicit rule search has been done.
|
||||
|
||||
make: *** No rule to make target `all'. Stop.
|
||||
|
||||
# Last modified 2022-04-05 14:52:22
|
||||
# File has been updated.
|
||||
# Successfully updated.
|
||||
|
||||
# Not a target:
|
||||
.DEFAULT:
|
||||
# Implicit rule search has not been done.
|
||||
# Modification time never checked.
|
||||
# File has not been updated.
|
||||
|
||||
clean:
|
||||
# Implicit rule search has not been done.
|
||||
# Modification time never checked.
|
||||
# File has not been updated.
|
||||
# recipe to execute (from `Makefile', line 12):
|
||||
rm ncursesdemo *.gcda *.gcno *.gcov
|
||||
|
||||
ncursesdemo: ncursesdemo.c
|
||||
# Implicit rule search has not been done.
|
||||
# Modification time never checked.
|
||||
# File has not been updated.
|
||||
# recipe to execute (from `Makefile', line 9):
|
||||
$(CC) $(CFLAGS) ncursesdemo.c -o ncursesdemo -l ncurses
|
||||
|
||||
# files hash-table stats:
|
||||
# Load=7/1024=1%, Rehash=0, Collisions=0/18=0%
|
||||
# VPATH Search Paths
|
||||
|
||||
# No `vpath' search paths.
|
||||
|
||||
# No general (`VPATH' variable) search path.
|
||||
|
||||
# # of strings in strcache: 0 / lookups = 26 / hits = 26
|
||||
# # of strcache buffers: 1 (* 8176 B/buffer = 8176 B)
|
||||
# strcache used: total = 0 (179) / max = 0 / min = 8176 / avg = 0
|
||||
# strcache free: total = 0 (7997) / max = 0 / min = 8176 / avg = 0
|
||||
|
||||
# strcache hash-table stats:
|
||||
# Load=19/8192=0%, Rehash=0, Collisions=1/26=4%
|
||||
# Finished Make data base on Thu Apr 7 10:06:16 2022
|
||||
|
||||
|
13
CPE455/ncursesdemo/Makefile
Normal file
13
CPE455/ncursesdemo/Makefile
Normal file
@ -0,0 +1,13 @@
|
||||
#
|
||||
# ncursesdemo Makefile
|
||||
#
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -g -Wall --pedantic -ansi --coverage
|
||||
|
||||
ncursesdemo: ncursesdemo.c
|
||||
$(CC) $(CFLAGS) ncursesdemo.c -o ncursesdemo -l ncurses
|
||||
|
||||
clean:
|
||||
rm ncursesdemo *.gcda *.gcno *.gcov
|
||||
|
14
CPE455/ncursesdemo/maze1.txt
Normal file
14
CPE455/ncursesdemo/maze1.txt
Normal file
@ -0,0 +1,14 @@
|
||||
M 12 40
|
||||
########################################
|
||||
# # # #
|
||||
# # # #
|
||||
# # # #
|
||||
# # ###### ############ ### #
|
||||
# # # # # #
|
||||
# # # # # #
|
||||
# # ###### #### ########## #
|
||||
# # # #
|
||||
# # # #
|
||||
# # # #
|
||||
########################################
|
||||
P 2 10
|
15
CPE455/ncursesdemo/maze2.txt
Normal file
15
CPE455/ncursesdemo/maze2.txt
Normal file
@ -0,0 +1,15 @@
|
||||
M 12 40
|
||||
########################################
|
||||
# # # #
|
||||
# # # #
|
||||
# # # #
|
||||
# # ###### ############ ### #
|
||||
# # # # # #
|
||||
# # # # # #
|
||||
# # ###### #### ########## #
|
||||
# # # #
|
||||
# # # #
|
||||
# # # #
|
||||
########################################
|
||||
P 2 10
|
||||
Z 8 10
|
16
CPE455/ncursesdemo/maze3.txt
Normal file
16
CPE455/ncursesdemo/maze3.txt
Normal file
@ -0,0 +1,16 @@
|
||||
M 12 40
|
||||
########################################
|
||||
# # # #
|
||||
# # # #
|
||||
# # # #
|
||||
# # ###### ############ ### #
|
||||
# # # # # #
|
||||
# # # # # #
|
||||
# # ###### #### ########## #
|
||||
# # # #
|
||||
# # # #
|
||||
# # # #
|
||||
########################################
|
||||
Z 8 10
|
||||
P 2 10
|
||||
T 8 15
|
16
CPE455/ncursesdemo/maze4.txt
Normal file
16
CPE455/ncursesdemo/maze4.txt
Normal file
@ -0,0 +1,16 @@
|
||||
M 12 40
|
||||
########################################
|
||||
# # # #
|
||||
# # # #
|
||||
# # # #
|
||||
# # ###### ############ ### #
|
||||
# # # # # #
|
||||
# # # # # #
|
||||
# # ###### #### ########## #
|
||||
# # # #
|
||||
# # # #
|
||||
# # # #
|
||||
########################################
|
||||
T 8 15
|
||||
Z 8 10
|
||||
P 2 10
|
18
CPE455/ncursesdemo/maze5.txt
Normal file
18
CPE455/ncursesdemo/maze5.txt
Normal file
@ -0,0 +1,18 @@
|
||||
M 12 40
|
||||
########################################
|
||||
# # # #
|
||||
# # # #
|
||||
# # # #
|
||||
# # ###### ############ ### #
|
||||
# # # # # #
|
||||
# # # # # #
|
||||
# # ###### #### ########## #
|
||||
# # # #
|
||||
# # # #
|
||||
# # # #
|
||||
########################################
|
||||
T 8 15
|
||||
Z 8 10
|
||||
P 2 10
|
||||
Z 7 24
|
||||
T 2 20
|
21
CPE455/ncursesdemo/maze6.txt
Normal file
21
CPE455/ncursesdemo/maze6.txt
Normal file
@ -0,0 +1,21 @@
|
||||
M 14 21
|
||||
#####################
|
||||
# # # #
|
||||
# # # #
|
||||
# # # #
|
||||
# ####### #######
|
||||
# #
|
||||
# #
|
||||
# ########### #
|
||||
# # #
|
||||
# # #
|
||||
# ##### #
|
||||
# #
|
||||
# #
|
||||
#####################
|
||||
T 8 15
|
||||
Z 9 10
|
||||
Z 6 11
|
||||
T 2 8
|
||||
P 2 10
|
||||
T 2 12
|
39
CPE455/ncursesdemo/maze7.txt
Normal file
39
CPE455/ncursesdemo/maze7.txt
Normal file
@ -0,0 +1,39 @@
|
||||
M 22 75
|
||||
###########################################################################
|
||||
# # #
|
||||
# # #
|
||||
# # #
|
||||
# ################## # #
|
||||
# # # #
|
||||
# # # #
|
||||
# # ############ # # #
|
||||
# # # # # # #
|
||||
# # # # # #
|
||||
# # # # # #
|
||||
# # # # # #
|
||||
# # # # # #
|
||||
# # # # # #
|
||||
# # # # # #
|
||||
# # # #
|
||||
# # # #
|
||||
# ######################### #
|
||||
# # #
|
||||
# # #
|
||||
# # #
|
||||
###########################################################################
|
||||
P 10 30
|
||||
Z 19 5
|
||||
Z 19 10
|
||||
Z 19 15
|
||||
T 5 43
|
||||
T 10 43
|
||||
T 15 43
|
||||
Z 2 5
|
||||
Z 2 10
|
||||
Z 2 15
|
||||
T 5 55
|
||||
T 10 55
|
||||
T 15 55
|
||||
T 5 67
|
||||
T 10 67
|
||||
T 15 67
|
BIN
CPE455/ncursesdemo/ncursesdemo
Executable file
BIN
CPE455/ncursesdemo/ncursesdemo
Executable file
Binary file not shown.
135
CPE455/ncursesdemo/ncursesdemo.c
Normal file
135
CPE455/ncursesdemo/ncursesdemo.c
Normal file
@ -0,0 +1,135 @@
|
||||
/*
|
||||
*
|
||||
* ncursesdemo.c
|
||||
*
|
||||
* REFERENCES
|
||||
* https://tldp.org/HOWTO/pdf/NCURSES-Programming-HOWTO.pdf
|
||||
*
|
||||
* Hyperlinked man page - very useful
|
||||
* https://man.netbsd.org/curses.3
|
||||
*
|
||||
*/
|
||||
|
||||
#include <ncurses.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
|
||||
int main(int argc, char* argv[ ])
|
||||
{
|
||||
WINDOW* W = 0; /* Curses Window handle */
|
||||
int rowLimit, colLimit; /* Num of rows and columns in terminal window */
|
||||
int playerRow, playerCol; /* Player row-column position */
|
||||
int deltaRow, deltaCol; /* Change in row-column position based on key input */
|
||||
|
||||
|
||||
/* Initialize ncurses -- you will want to use the following settings */
|
||||
W = initscr(); /* Determine terminal type and initialize curses data structures */
|
||||
start_color(); /* Enable use of color with ncurses */
|
||||
cbreak(); /* Disable line buffering and make char inputs immediately accessible to program */
|
||||
noecho(); /* Disable echo printing of chars type by user */
|
||||
nodelay(W, true); /* Make getch( ) a non-blocking call */
|
||||
keypad(W, true); /* Enable keypad and arrow keys */
|
||||
curs_set(0); /* Set cursor to be invisible - 0 */
|
||||
getmaxyx(W, rowLimit, colLimit); /* Query terminal dimensions */
|
||||
|
||||
/* Define color pallete foreground-background color pairs */
|
||||
/* PairID#, Foreground Color, Background Color */
|
||||
/* Foreground color == Background color ==> solid color block */
|
||||
init_pair(1, COLOR_BLACK, COLOR_BLACK); /* Black text on Black background */
|
||||
init_pair(2, COLOR_RED, COLOR_BLACK); /* Red text on Black background */
|
||||
init_pair(3, COLOR_WHITE, COLOR_BLUE); /* White text on Blue background */
|
||||
init_pair(4, COLOR_YELLOW, COLOR_YELLOW); /* Yellow text on Yellow background */
|
||||
|
||||
/* Draw some obstacle */
|
||||
attron(COLOR_PAIR(2)); /* Turn on color attribute #2 */
|
||||
wmove(W, rowLimit/2, colLimit/2); /* Position cursor in middle of terminal window */
|
||||
waddch(W, '#'); /* Draw # symbol */
|
||||
attroff(COLOR_PAIR(2)); /* Turn off color attribute #2 */
|
||||
|
||||
/* Initialize player movement variables */
|
||||
playerRow = rowLimit/4;
|
||||
playerCol = colLimit/4;
|
||||
deltaCol = 0;
|
||||
deltaRow = 0;
|
||||
|
||||
/* Player movement loop */
|
||||
do
|
||||
{
|
||||
int kb = wgetch(W); /* Grab keypress */
|
||||
|
||||
/* Support player movement via WASD, IJKL, and arrow keys */
|
||||
if (kb == 'a' || kb == 'j' || kb == KEY_LEFT)
|
||||
{
|
||||
/* Move Left */
|
||||
deltaCol = -1;
|
||||
deltaRow = 0;
|
||||
}
|
||||
else if (kb == 'd' || kb == 'l' || kb == KEY_RIGHT)
|
||||
{
|
||||
/* Move Right */
|
||||
deltaCol = 1;
|
||||
deltaRow = 0;
|
||||
}
|
||||
else if (kb == 'w' || kb == 'i' || kb == KEY_UP)
|
||||
{
|
||||
/* Move Up */
|
||||
deltaCol = 0;
|
||||
deltaRow = -1;
|
||||
}
|
||||
else if (kb == 's' || kb == 'k' || kb == KEY_DOWN)
|
||||
{
|
||||
/* Move Down */
|
||||
deltaCol = 0;
|
||||
deltaRow = 1;
|
||||
}
|
||||
else if (kb == 'q')
|
||||
{
|
||||
/* q to exit player movement loop */
|
||||
break;
|
||||
};
|
||||
|
||||
/* Erase player from current position */
|
||||
/* An alternate option is to invoke clear() */
|
||||
/* which erases everything on the screen */
|
||||
/* If you comment out this code, the player will leave an onscreen trail */
|
||||
/* */
|
||||
/* Algorithm: */
|
||||
/* - Turn on color attribute #1 (solid block of background color) */
|
||||
/* - Position cursor */
|
||||
/* - Draw player symbol */
|
||||
/* - Turn off color attribute #1 */
|
||||
attron(COLOR_PAIR(1));
|
||||
wmove(W, playerRow, playerCol);
|
||||
waddch(W, 'P');
|
||||
attroff(COLOR_PAIR(1));
|
||||
|
||||
/* Compute new player position without checking to see if new position is valid */
|
||||
playerRow = playerRow + deltaRow;
|
||||
playerCol = playerCol + deltaCol;
|
||||
|
||||
|
||||
/* Redraw player in new position */
|
||||
attron(COLOR_PAIR(3)); /* Turn on color attribute #3 */
|
||||
wmove(W, playerRow, playerCol); /* Position cursor */
|
||||
waddch(W, 'P'); /* Draw player symbol */
|
||||
attroff(COLOR_PAIR(3)); /* Turn off color attribute #3 */
|
||||
|
||||
/* Zero offsets prior to next key press */
|
||||
deltaRow = 0;
|
||||
deltaCol = 0;
|
||||
|
||||
wrefresh(W); /* Refresh ncurses window */
|
||||
|
||||
} while (true); /* Repeat until user selects q to quit */
|
||||
|
||||
endwin(); /* Terminate ncurses window -- very important */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
BIN
CPE455/ncursesdemo/ncursesdemo.gcda
Normal file
BIN
CPE455/ncursesdemo/ncursesdemo.gcda
Normal file
Binary file not shown.
BIN
CPE455/ncursesdemo/ncursesdemo.gcno
Normal file
BIN
CPE455/ncursesdemo/ncursesdemo.gcno
Normal file
Binary file not shown.
Reference in New Issue
Block a user