diff options
| author | Ray Hogenson <rayhogenson@gmail.com> | 2012-01-10 15:24:39 -0900 |
|---|---|---|
| committer | Ray Hogenson <rayhogenson@gmail.com> | 2012-01-10 15:24:39 -0900 |
| commit | c1d1a4cfb55e87fb4db68980b3af9c31fde363a9 (patch) | |
| tree | 2d0f92a791c1151a9683788b808dd6eaf4857c2f | |
| parent | ae0551652fa132bb512638433189c1290933164e (diff) | |
| parent | 4e87a290412cea63f548760de6f4a91b1d1ba352 (diff) | |
| download | yetihack-c1d1a4cfb55e87fb4db68980b3af9c31fde363a9.tar.zst | |
Merge branch 'master' of github.com:rayhogenson/YetiHack
| -rw-r--r-- | YetiHack/Makefile | 25 | ||||
| -rw-r--r-- | YetiHack/include/yeti.h | 21 | ||||
| -rw-r--r-- | YetiHack/os/debian/deb/DEBIAN/control | 10 | ||||
| -rw-r--r-- | YetiHack/os/linux/Makefile | 22 | ||||
| -rw-r--r-- | YetiHack/os/windows/Makefile | 15 | ||||
| -rw-r--r-- | YetiHack/os/windows/install.nsi | 97 | ||||
| -rw-r--r-- | YetiHack/os/windows/yetihack-windows/pdcurses.dll | bin | 0 -> 118784 bytes | |||
| -rwxr-xr-x | YetiHack/os/windows/yetihack-windows/yetihack.exe | bin | 0 -> 1110779 bytes | |||
| -rw-r--r-- | YetiHack/src/Makefile | 9 | ||||
| -rw-r--r-- | YetiHack/src/YetiHack.cpp | 407 | ||||
| -rw-r--r-- | YetiHack/src/yeti.cpp | 281 |
11 files changed, 887 insertions, 0 deletions
diff --git a/YetiHack/Makefile b/YetiHack/Makefile new file mode 100644 index 0000000..3bb8395 --- /dev/null +++ b/YetiHack/Makefile @@ -0,0 +1,25 @@ +yetihack: + cd src && make + +package: + make clean + zip package/yetihack-source.zip ../YetiHack + make yetihack + strip src/yetihack + sudo chown root:root src/yetihack + -rm os/debian/deb/usr/bin/yetihack + ln src/yetihack os/debian/deb/usr/bin/ + dpkg-deb --build os/debian/deb package/yetihack.deb + cd package && sudo alien -r yetihack.deb + zip package/yetihack.zip src/yetihack + +install: yetihack + cp src/yetihack /usr/local/bin/ + +clean: + -rm src/*.o + -rm src/yetihack + -rm package/yetihack.deb + -rm package/*.rpm + -rm os/debian/deb/usr/bin/yetihack + diff --git a/YetiHack/include/yeti.h b/YetiHack/include/yeti.h new file mode 100644 index 0000000..592e09f --- /dev/null +++ b/YetiHack/include/yeti.h @@ -0,0 +1,21 @@ +#include <vector> +using namespace std; +class yeti +{ + public: + void moveleft(); + void moveright(); + void moveup(); + void movedown(); + yeti(int, int, int, int); + void movetowards(int, int, vector<yeti>, int); + int xpos(); + int ypos(); + private: + int x; + int y; + int sizex; + int sizey; + int absolute(int); +}; + diff --git a/YetiHack/os/debian/deb/DEBIAN/control b/YetiHack/os/debian/deb/DEBIAN/control new file mode 100644 index 0000000..4a2c8c4 --- /dev/null +++ b/YetiHack/os/debian/deb/DEBIAN/control @@ -0,0 +1,10 @@ +Package: yetihack +Version: 1 +Section: bin +Architecture: i386 +Depends: libncurses5, libc6 +Maintainer: Ray Hogenson <rayhogenson@gmail.com> +Description: This is yetihack + YetiHack is a text based game where you + run from yetis + diff --git a/YetiHack/os/linux/Makefile b/YetiHack/os/linux/Makefile new file mode 100644 index 0000000..0a95d72 --- /dev/null +++ b/YetiHack/os/linux/Makefile @@ -0,0 +1,22 @@ +yetihack: + cd src && make + +package: + make clean + zip package/yetihack-source.zip ../YetiHack + make yetihack + strip src/yetihack + sudo chown root:root src/yetihack + dpkg-deb --build os/debian/deb package/yetihack.deb + cd package && sudo alien -r yetihack.deb + zip package/yetihack.zip src/yetihack + +install: yetihack + cp src/yetihack /usr/local/bin/ + +clean: + -rm src/*.o + -rm src/yetihack + -rm os/package/yetihack.deb + -rm os/package/*.rpm + diff --git a/YetiHack/os/windows/Makefile b/YetiHack/os/windows/Makefile new file mode 100644 index 0000000..d1e8745 --- /dev/null +++ b/YetiHack/os/windows/Makefile @@ -0,0 +1,15 @@ +yetihack.exe: ../YetiHack.cpp + i586-mingw32msvc-g++ src/YetiHack.cpp src/yeti.cpp -o yetihack.exe -lpdcurses + -rm os/windows/yetihack-windows/yetihack.exe + ln yetihack.exe yetihack-windows + +package: yetihack.exe + makensis install.nsi + zip yetihack-windows.zip yetihack-windows + +clean: + -rm yetihack.exe + -rm YetiHack_installer.exe + -rm yetihack-windows.zip + -rm yetihack-windows/yetihack.exe + diff --git a/YetiHack/os/windows/install.nsi b/YetiHack/os/windows/install.nsi new file mode 100644 index 0000000..a53078e --- /dev/null +++ b/YetiHack/os/windows/install.nsi @@ -0,0 +1,97 @@ +; example2.nsi
+;
+; This script is based on example1.nsi, but it remember the directory,
+; has uninstall support and (optionally) installs start menu shortcuts.
+;
+; It will install example2.nsi into a directory that the user selects,
+
+;--------------------------------
+
+; The name of the installer
+Name "YetiHack Installer"
+
+; The file to write
+OutFile "YetiHack_installer.exe"
+
+; The default installation directory
+InstallDir $PROGRAMFILES\YetiHack
+
+; Registry key to check for directory (so if you install again, it will
+; overwrite the old one automatically)
+InstallDirRegKey HKLM "Software\YetiHack" "Install_Dir"
+
+; Request application privileges for Windows Vista
+RequestExecutionLevel admin
+
+;--------------------------------
+
+; Pages
+
+Page components
+Page directory
+Page instfiles
+
+UninstPage uninstConfirm
+UninstPage instfiles
+
+;--------------------------------
+
+; The stuff to install
+Section "YetiHack"
+
+ SectionIn RO
+
+ SetOutPath $INSTDIR
+ File "/home/ray/Documents/programming/YetiHack/windows/yetihack.exe"
+ File "/usr/i586-mingw32msvc/bin/pdcurses.dll"
+
+ ; Write the installation path into the registry
+ WriteRegStr HKLM SOFTWARE\YetiHack "Install_Dir" "$INSTDIR"
+
+ ; Write the uninstall keys for Windows
+ WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\YetiHack" "YetiHack Uninstaller" "YetiHack"
+ WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\YetiHack" "UninstallString" '"$INSTDIR\uninstall.exe"'
+ WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\YetiHack" "NoModify" 1
+ WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\YetiHack" "NoRepair" 1
+ WriteUninstaller "uninstall.exe"
+
+SectionEnd
+
+; Optional section (can be disabled by the user)
+Section "Start Menu Shortcuts"
+
+ CreateDirectory "$SMPROGRAMS\YetiHack"
+ CreateShortCut "$SMPROGRAMS\YetiHack\Uninstall.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0
+ CreateShortCut "$SMPROGRAMS\YetiHack\YetiHack.lnk" "$INSTDIR\YetiHack.exe" "" "$INSTDIR\YetiHack.exe" 0
+
+SectionEnd
+
+Section "Desktop Shortcut"
+
+ CreateShortCut "$DESKTOP\YetiHack.lnk" "$INSTDIR\YetiHack.exe" "" "$INSTDIR\YetiHack.exe" 0
+
+SectionEnd
+
+;--------------------------------
+
+; Uninstaller
+
+Section "Uninstall"
+
+ ; Remove registry keys
+ DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\YetiHack"
+ DeleteRegKey HKLM SOFTWARE\YetiHack
+
+ ; Remove files and uninstaller
+ Delete $INSTDIR\*
+ Delete $INSTDIR\uninstall.exe
+
+ ; Remove shortcuts, if any
+ Delete "$SMPROGRAMS\YetiHack\*.*"
+ Delete "$DESKTOP\YetiHack.lnk"
+
+ ; Remove directories used
+ RMDir "$SMPROGRAMS\YetiHack"
+ RMDir "$INSTDIR"
+
+SectionEnd
diff --git a/YetiHack/os/windows/yetihack-windows/pdcurses.dll b/YetiHack/os/windows/yetihack-windows/pdcurses.dll Binary files differnew file mode 100644 index 0000000..550c7a2 --- /dev/null +++ b/YetiHack/os/windows/yetihack-windows/pdcurses.dll diff --git a/YetiHack/os/windows/yetihack-windows/yetihack.exe b/YetiHack/os/windows/yetihack-windows/yetihack.exe Binary files differnew file mode 100755 index 0000000..58ec272 --- /dev/null +++ b/YetiHack/os/windows/yetihack-windows/yetihack.exe diff --git a/YetiHack/src/Makefile b/YetiHack/src/Makefile new file mode 100644 index 0000000..4dd3f89 --- /dev/null +++ b/YetiHack/src/Makefile @@ -0,0 +1,9 @@ +yetihack: YetiHack.o yeti.o + g++ -o yetihack YetiHack.o yeti.o -lncurses + +YetiHack.o: YetiHack.cpp + g++ -I../include -o YetiHack.o -c YetiHack.cpp + +yeti.o: yeti.cpp + g++ -I../include -o yeti.o -c yeti.cpp + diff --git a/YetiHack/src/YetiHack.cpp b/YetiHack/src/YetiHack.cpp new file mode 100644 index 0000000..958c1ea --- /dev/null +++ b/YetiHack/src/YetiHack.cpp @@ -0,0 +1,407 @@ +#include <iostream> +#include <curses.h> +#include <cstdlib> +#include <time.h> +#include <vector> +#include <cstring> +#include <fstream> +#include <sstream> +#include "yeti.h" +#define Linux +using namespace std; +void endCurses(); +void startCurses(); +int wait(int); +int start(int, bool, bool, double); +void story(); +const char* convert(int); +void menu(bool); + +void endCurses() +{ + if (!isendwin()) + endwin(); +} +void startCurses() +{ + initscr(); + cbreak(); + noecho(); + intrflush(stdscr, false); + keypad(stdscr, true); +} + +int wait(int seconds) +{ + int snum; + int initial = time(NULL); + do + { + snum = time(NULL) - initial; + } while (snum < seconds); +} +int start(int rate, bool immortal, bool story, double escapeturns) +{ + int x, y; + int sizex, sizey; + getmaxyx(stdscr,y,x); + escapeturns = escapeturns * x * y; + sizey = y - 3; + sizex = x; + char input; + int yetinum = 1; + x = 1; + y = 1; + vector<yeti> yetis; + yeti yeti1(sizex / 2, sizey / 2, sizex, sizey); + yetis.push_back(yeti1); + for (int i = 0; i < sizey; ++i) + { + for (int j = 0; j < sizex; ++j) + { + addch('.'); + } + } + move(y - 1, x - 1); + addch('@'); + for (int i = 0; i < yetinum; ++i) + { + move(yetis[i].ypos() - 1, yetis[i].xpos() - 1); + addch('y'); + } + move(sizey, 0); + refresh(); + int count = 0; + move(sizey + 1, 0); + addstr("count: 0"); + while (!story || count < escapeturns) + { + input = getch(); + move(y - 1, x - 1); + addch('.'); + for (int i = 0; i < yetinum; ++i) + { + move(yetis[i].ypos() - 1, yetis[i].xpos() - 1); + addch('.'); + } + if (input == '4') + { + --x; + } + else if (input == '7') + { + --x; + --y; + } + else if (input == '8') + { + --y; + } + else if (input == '9') + { + ++x; + --y; + } + else if (input == '6') + { + ++x; + } + else if (input == '3') + { + ++x; + ++y; + } + else if (input == '2') + { + ++y; + } + else if (input == '1') + { + ++y; + --x; + } + ++count; + // did you go off the side? + if (x < 1) + { + x = sizex; + } + if (x > sizex) + { + x = 1; + } + if (y < 1) + { + y = sizey; + } + if (y > sizey) + { + y = 1; + } + // begin yeti Ai + for(int i = 0; i < yetinum; ++i) + { + yetis[i].movetowards(x, y, yetis, i); + } + // End Yeti AI + for (int i = 0; i < yetinum; ++i) + { + if (x == yetis[i].xpos() && y == yetis[i].ypos() && !immortal) + { + if (story) + { + return 1; + } + for (int i = 0; i < yetinum; ++i) + { + move(yetis[i].ypos() - 1, yetis[i].xpos() - 1); + addch('y'); + } + move(sizey, 0); + addstr("You Died!\n"); + char buf[100]; + for (int j = 0; j < 100; ++j) + { + buf[j] = ' '; + } + sprintf(buf, "You survived %d turns\n", count); + for(int j = 0; buf[j] != '\n'; ++j) + { + addch(buf[j]); + } + addstr("\nDo you want to play again?[y/n] "); + refresh(); + char playagain = getch(); + while (playagain != 'y' && playagain != 'n') + { + playagain = getch(); + } + erase(); + if (playagain == 'y') + { + #ifdef Windows + system("cls"); + #endif + return 1; + } + else + { + endCurses(); + #ifdef Windows + system("cls"); + #endif + cout << "You survived " << count << " turns" << endl; + } + return 0; + } + } + for (int i = 0; i < yetinum; ++i) + { + move(yetis[i].ypos() - 1, yetis[i].xpos() - 1); + addch('y'); + } + move(y - 1, x - 1); + addch('@'); + move(sizey + 1, 7); + addstr(" "); + move(sizey + 1, 7); + addstr(convert(count)); + move(sizey, 0); + addstr(" "); + move(sizey, 0); + refresh(); + if (count % rate == 0) + { + move((sizey / 2) - 1,(sizex / 2) - 1); + addch('y'); + move(sizey, 0); + addstr("A New Yeti Has Appeared!"); + refresh(); + ++yetinum; + yetis.push_back(yeti1); + } + } + addstr("\nYou Escaped!"); + do + { + input = getch(); + } while (input != '\n'); + return 0; +} + +void story() +{ + char input; + addstr("One day, you are ambushed by yetis!\n"); + addstr("Press any key to fight them...\n"); + refresh(); + getch(); + erase(); + if (start(10, false, true, 0.0064020) == 1) + { + erase(); + addstr("You died!"); + do + { + input = getch(); + } while (input != '\n'); + return; + } + erase(); + addstr("You escaped, unfortunately, they attack again.\n"); + addstr("Press any key to fight them...\n"); + refresh(); + getch(); + erase(); + if (start(5, false, true, 0.012804) == 1) + { + erase(); + addstr("You died!"); + do + { + input = getch(); + } while (input != '\n'); + return; + } + erase(); + addstr("Now, you are attacked a third time!\n"); + addstr("Press any key to fight them...\n"); + refresh(); + getch(); + erase(); + if (start(2, false, true, 0.064020) == 1) + { + erase(); + addstr("You died!"); + do + { + input = getch(); + } while (input != '\n'); + return; + } + erase(); + addstr("There sure are a lot of yetis, because you are attacked again!\n"); + addstr("Press any key to fight them...\n"); + refresh(); + getch(); + erase(); + if (start(1, false, true, 0.10243) == 1) + { + erase(); + addstr("You died!"); + do + { + input = getch(); + } while (input != '\n'); + return; + } + erase(); + addstr("One last fight.\n"); + addstr("Press any key to fight them...\n"); + refresh(); + getch(); + erase(); + if (start(1, false, true, 0.12804) == 1) + { + erase(); + addstr("You died!"); + do + { + input = getch(); + } while (input != '\n'); + return; + } + erase(); + addstr("You won!!!!"); + getch(); +} + +const char* convert(int a) +{ + stringstream convert; + string out; + convert << a; + convert >> out; + const char* caout = out.c_str(); + return caout; +} + +void menu(bool immortal) +{ + int a = 100; + startCurses(); + char input; + addstr("Welcome to yetihack!\n"); + addstr("\t1. Arcade mode (classic)\n"); + addstr("\t2. Story mode\n"); + addstr("Select an option to proceed: "); + refresh(); + echo(); + input = getch(); + noecho(); + int rate = 0; + switch(input) + { + case '1': + addstr("\nEnter the yeti spawn rate: "); + refresh(); + echo(); + input = '0'; + do + { + a = a + 1; + if (input == 7) + { + int x, y; + getyx(stdscr, y, x); + move(y, 0); + addstr(" "); + move(y, 0); + addstr("Enter the yeti spawn rate: "); + rate /= 10; + if (rate != 0) + { + addstr(convert(rate)); + } + refresh(); + input = getch(); + } + else + { + rate *= 10; + rate += input - '0'; + input = getch(); + } + } while (input != '\n'); + noecho(); + erase(); + while(start(rate, immortal, false, 0)); + break; + case '2': + erase(); + story(); + break; + } + addstr(convert(a)); +} + +int main(int argc, char* argv[]) +{ + /*startCurses(); + while (true) + { + char input = getch(); + int a = input; + addstr(convert(a)); + }*/ + bool immortal = false; + if (argc > 1 && strcmp(argv[1],"-c") == 0) + { + immortal = true; + } + srand(time(0)); + menu(immortal); + endCurses(); + return 0; +} + diff --git a/YetiHack/src/yeti.cpp b/YetiHack/src/yeti.cpp new file mode 100644 index 0000000..eda9d2c --- /dev/null +++ b/YetiHack/src/yeti.cpp @@ -0,0 +1,281 @@ +#include "yeti.h" +#include <cstdlib> +#include <ctime> +#include <vector> +using namespace std; +void yeti::moveleft() +{ + --x; +} +void yeti::moveright() +{ + ++x; +} +void yeti::moveup() +{ + --y; +} +void yeti::movedown() +{ + ++y; +} +yeti::yeti(int x1, int y1, int sizex1, int sizey1) +{ + sizex = sizex1; + sizey = sizey1; + x = x1; + y = y1; +} +void yeti::movetowards(int a, int b, vector<yeti> yetis, int i) +{ + int random = rand() % 2; + int left; + int right; + int real; + if (random == 0) + { + left = (x) + (sizex - a); + right = a + (sizex - x); + real = absolute(x - a); + if (left < right && left < real) + { + bool empty = true; + for (int j = 0; j < yetis.size(); ++j) + { + int anew = x - 1; + if (anew > sizex) + { + anew = 0; + } + if (anew < 1) + { + anew = sizex; + } + if (i != j && anew == yetis[j].xpos() && yetis[j].ypos() == y) + { + empty = false; + } + } + if (empty) + { + moveleft(); + } + } + else if (right < left && right < real) + { + bool empty = true; + for (int j = 0; j < yetis.size(); ++j) + { + int anew = x + 1; + if (anew > sizex) + { + anew = 0; + } + if (anew < 1) + { + anew = sizex; + } + if (i != j && anew == yetis[j].xpos() && yetis[j].ypos() == y) + { + empty = false; + } + } + if (empty) + { + moveright(); + } + } + else + { + if (x - a < 0) + { + bool empty = true; + for (int j = 0; j < yetis.size(); ++j) + { + int anew = x + 1; + if (anew > sizex) + { + anew = 0; + } + if (anew < 1) + { + anew = sizex; + } + if (i != j && anew == yetis[j].xpos() && yetis[j].ypos() == y) + { + empty = false; + } + } + if (empty) + { + moveright(); + } + } + else if (x - a > 0) + { + bool empty = true; + for (int j = 0; j < yetis.size(); ++j) + { + int anew = x - 1; + if (anew > sizex) + { + anew = 0; + } + if (anew < 1) + { + anew = sizex; + } + if (i != j && anew == yetis[j].xpos() && yetis[j].ypos() == y) + { + empty = false; + } + } + if (empty) + { + moveleft(); + } + } + } + } + // now for b + else + { + left = (y) + (sizey - b); + right = b + (sizey - y); + real = absolute(y - b); + if (left < right && left < real) + { + bool empty = true; + for (int j = 0; j < yetis.size(); ++j) + { + int bnew = y - 1; + if (bnew > sizey) + { + bnew = 0; + } + if (bnew < 1) + { + bnew = sizey; + } + if (i != j && x == yetis[j].xpos() && yetis[j].ypos() == bnew) + { + empty = false; + } + } + if (empty) + { + moveup(); + } + } + else if (right < left && right < real) + { + bool empty = true; + for (int j = 0; j < yetis.size(); ++j) + { + int bnew = y + 1; + if (bnew > sizey) + { + bnew = 0; + } + if (bnew < 1) + { + bnew = sizey; + } + if (i != j && x == yetis[j].xpos() && yetis[j].ypos() == bnew) + { + empty = false; + } + } + if (empty) + { + movedown(); + } + } + else + { + if (y - b < 0) + { + bool empty = true; + for (int j = 0; j < yetis.size(); ++j) + { + int bnew = y + 1; + if (bnew > sizey) + { + bnew = 0; + } + if (bnew < 1) + { + bnew = sizey; + } + if (i != j && x == yetis[j].xpos() && yetis[j].ypos() == bnew) + { + empty = false; + } + } + if (empty) + { + movedown(); + } + } + else if (y - b > 0) + { + bool empty = true; + for (int j = 0; j < yetis.size(); ++j) + { + int bnew = y - 1; + if (bnew > sizey) + { + bnew = 0; + } + if (bnew < 1) + { + bnew = sizey; + } + if (i != j && x == yetis[j].xpos() && yetis[j].ypos() == bnew) + { + empty = false; + } + } + if (empty) + { + moveup(); + } + } + } + } + // deal with going off the side + if (x < 1) + { + x = sizex; + } + if (x > sizex) + { + x = 1; + } + if (y < 1) + { + y = sizey; + } + if (y > sizey) + { + y = 1; + } +} + +int yeti::xpos() +{ + return x; +} +int yeti::ypos() +{ + return y; +} +int yeti::absolute(int value) +{ + if (value < 0) + { + value = 0 - value; + } + return value; +} + |
