modified: headers.hpp
modified: monster.cpp modified: muppet.cpp modified: muppet.lk1 modified: rc4.cpp
This commit is contained in:
+42
-25
@@ -13,6 +13,45 @@
|
||||
|
||||
//#define DEBUG
|
||||
|
||||
class RC4 {
|
||||
public:
|
||||
RC4(char *seed, int len);
|
||||
unsigned int rand();
|
||||
unsigned char rand8();
|
||||
|
||||
private:
|
||||
unsigned char state[256];
|
||||
unsigned int x,y;
|
||||
};
|
||||
|
||||
#define SEEDSIZE 32
|
||||
char *init_rc4();
|
||||
|
||||
class VGA256Term {
|
||||
public:
|
||||
|
||||
VGA256Term();
|
||||
void draw_term();
|
||||
void clear_screen(unsigned char color);
|
||||
void printf_term(char *s, ...);
|
||||
void printchar_term(char c);
|
||||
void move_cursor_offset(unsigned int x, unsigned int y);
|
||||
int get_int();
|
||||
~VGA256Term();
|
||||
|
||||
private:
|
||||
unsigned char far *video_buffer;
|
||||
|
||||
char term_buff[40][25];
|
||||
char term_buff2[40][25];
|
||||
int term_x, term_y;
|
||||
|
||||
void Set_Video_Mode(int mode);
|
||||
void print_char(char c, int x1, int y1, char color, char bgcolor);
|
||||
void set_color(int index, int red, int green, int blue);
|
||||
void term_newline();
|
||||
};
|
||||
|
||||
class Room {
|
||||
public:
|
||||
int ID;
|
||||
@@ -50,38 +89,16 @@ class Muppet {
|
||||
bool hasDied;
|
||||
int moveCounter;
|
||||
|
||||
Muppet(Room *location);
|
||||
Muppet(Room *location, RC4 *Rand);
|
||||
void doActions();
|
||||
void runAway();
|
||||
~Muppet();
|
||||
#ifdef DEBUG
|
||||
void debug();
|
||||
#endif
|
||||
};
|
||||
|
||||
class VGA256Term {
|
||||
public:
|
||||
|
||||
VGA256Term();
|
||||
void draw_term();
|
||||
void clear_screen(unsigned char color);
|
||||
void printf_term(char *s, ...);
|
||||
void printchar_term(char c);
|
||||
void move_cursor_offset(unsigned int x, unsigned int y);
|
||||
int get_int();
|
||||
~VGA256Term();
|
||||
|
||||
private:
|
||||
unsigned char far *video_buffer;
|
||||
|
||||
char term_buff[40][25];
|
||||
char term_buff2[40][25];
|
||||
int term_x, term_y;
|
||||
|
||||
void Set_Video_Mode(int mode);
|
||||
void print_char(char c, int x1, int y1, char color, char bgcolor);
|
||||
void set_color(int index, int red, int green, int blue);
|
||||
void term_newline();
|
||||
RC4 *Rand;
|
||||
int prev_loc;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
+7
-2
@@ -21,10 +21,12 @@
|
||||
|
||||
#include "headers.hpp"
|
||||
|
||||
Muppet::Muppet(Room *location) {
|
||||
Muppet::Muppet(Room *location, RC4 *Rand) {
|
||||
this->location = location;
|
||||
this->prev_loc = 0;
|
||||
this->moveCounter = 0;
|
||||
this->hasDied = false;
|
||||
this->Rand = Rand;
|
||||
}
|
||||
|
||||
void Muppet::doActions() {
|
||||
@@ -36,7 +38,10 @@ void Muppet::doActions() {
|
||||
}
|
||||
|
||||
void Muppet::runAway() {
|
||||
int randRoom = (rand()%3);
|
||||
int randRoom;
|
||||
rr: randRoom = (this->Rand->rand()%3);
|
||||
if(randRoom == this->prev_loc) goto rr;
|
||||
this->prev_loc = this->location->ID;
|
||||
this->location = this->location->rooms[randRoom];
|
||||
}
|
||||
|
||||
|
||||
+26
-19
@@ -21,15 +21,15 @@
|
||||
|
||||
#include "headers.hpp"
|
||||
|
||||
inline int getRandomRoom() {
|
||||
int randint = (rand()%20);
|
||||
inline int getRandomRoom(RC4 *Rand) {
|
||||
int randint = (Rand->rand()%20);
|
||||
|
||||
if(randint == 0 || randint == 4 || randint == 1 || randint == 7) randint += 11;
|
||||
|
||||
return randint;
|
||||
}
|
||||
|
||||
bool startGame(VGA256Term *Term) {
|
||||
bool startGame(VGA256Term *Term, RC4 *Rand) {
|
||||
Room *rooms[20];
|
||||
int x;
|
||||
int randint;
|
||||
@@ -62,12 +62,12 @@ bool startGame(VGA256Term *Term) {
|
||||
rooms[18]->setRooms(rooms[17], rooms[10], rooms[19]);
|
||||
rooms[19]->setRooms(rooms[15], rooms[12], rooms[18]);
|
||||
|
||||
Muppet *Cody = new Muppet(rooms[getRandomRoom()]);
|
||||
Muppet *Cody = new Muppet(rooms[getRandomRoom(Rand)], Rand);
|
||||
|
||||
// Add Ankle Bitters
|
||||
x=2;
|
||||
while(x > 0) {
|
||||
randint = getRandomRoom();
|
||||
randint = getRandomRoom(Rand);
|
||||
if(!rooms[randint]->hasAnkleBitters && !rooms[randint]->hasMaltego) {
|
||||
rooms[randint]->hasAnkleBitters = true;
|
||||
x -= 1;
|
||||
@@ -77,7 +77,7 @@ bool startGame(VGA256Term *Term) {
|
||||
// Add Maltego
|
||||
x=2;
|
||||
while(x > 0) {
|
||||
randint = getRandomRoom();
|
||||
randint = getRandomRoom(Rand);
|
||||
if(!rooms[randint]->hasAnkleBitters && !rooms[randint]->hasMaltego) {
|
||||
rooms[randint]->hasMaltego = true;
|
||||
x -= 1;
|
||||
@@ -94,6 +94,7 @@ bool startGame(VGA256Term *Term) {
|
||||
Term->printf_term("You are blinded by rainbow orbs!\n");
|
||||
if(Neal->location->rooms[0]->hasAnkleBitters || Neal->location->rooms[1]->hasAnkleBitters || Neal->location->rooms[2]->hasAnkleBitters)
|
||||
Term->printf_term("You clutch your supplies nervously...\n");
|
||||
Term->printf_term("Muppet Location #%\n", Cody->location->ID);
|
||||
Term->printf_term("[M]ove [W]ait [S]hoot?\n");
|
||||
|
||||
top: c = getch();
|
||||
@@ -112,13 +113,18 @@ invalid1: Term->printf_term("Where to? :> "); x = Term->get_int();
|
||||
case 's':
|
||||
case 'S':
|
||||
invalid2: Term->printf_term("Fire arrow to? :> "); x = Term->get_int();
|
||||
if(Neal->location->rooms[0]->ID == x || Neal->location->rooms[1]->ID == x || Neal->location->rooms[2]->ID == x)
|
||||
if(Cody->location->ID == x) {
|
||||
Term->printf_term("You hear a squeal!\n");
|
||||
Cody->hasDied = true;
|
||||
} else
|
||||
Term->printf_term("You hear a ting...\n");
|
||||
else {
|
||||
if(Neal->location->rooms[0]->ID == x || Neal->location->rooms[1]->ID == x || Neal->location->rooms[2]->ID == x) {
|
||||
if(Neal->arrows > 0) {
|
||||
if(Cody->location->ID == x) {
|
||||
Term->printf_term("You hear a squeal!\n");
|
||||
Cody->hasDied = true;
|
||||
} else
|
||||
Term->printf_term("You hear a ting...\n");
|
||||
Neal->arrows -= 1;
|
||||
} else {
|
||||
Term->printf_term("You have no arrows left...\n");
|
||||
}
|
||||
} else {
|
||||
Term->printf_term("Invalid Room ID\n");
|
||||
goto invalid2;
|
||||
}
|
||||
@@ -144,10 +150,10 @@ invalid2: Term->printf_term("Fire arrow to? :> "); x = Term->get_int();
|
||||
if(Neal->hasDied == false) {
|
||||
if(Neal->location->hasAnkleBitters == true) {
|
||||
Term->printf_term("Ankle Bitters have stolen from you!\n");
|
||||
Neal->supplies -= (rand()%4)+1; // 1-5 supplies get stolen
|
||||
Neal->supplies -= (Rand->rand()%4)+1; // 1-5 supplies get stolen
|
||||
} else if(Neal->location->hasMaltego == true) {
|
||||
Term->printf_term("You stare at Maltego and get disoriented...\n");
|
||||
randagain: randint = rand()%20;
|
||||
randagain: randint = Rand->rand()%20;
|
||||
if(Cody->location->ID != rooms[randint]->ID)
|
||||
Neal->location = rooms[randint];
|
||||
else goto randagain;
|
||||
@@ -163,7 +169,7 @@ randagain: randint = rand()%20;
|
||||
Term->printf_term("You've slain the Muppet!\n");
|
||||
}
|
||||
|
||||
Term->printf_term("Play Another Game? [Y]es or any key to exit\n");
|
||||
Term->printf_term("Play Again? [Y]es or any key to exit\n");
|
||||
c = getch();
|
||||
if(c == 'y' || c == 'Y') return true;
|
||||
else return false;
|
||||
@@ -177,14 +183,15 @@ void print_center(VGA256Term *Term, char *s) {
|
||||
}
|
||||
|
||||
int main(int argc, unsigned char **argv) {
|
||||
char *seed = init_rc4();
|
||||
VGA256Term *Term = new VGA256Term();
|
||||
time_t t;
|
||||
srand((unsigned)time(&t));
|
||||
RC4 *Rand = new RC4(seed, SEEDSIZE);
|
||||
free(seed); // No Longer Needed
|
||||
|
||||
print_center(Term, "In The Caves, You Must Survive...\n");
|
||||
print_center(Term, "The Angry Muppets!\n");
|
||||
|
||||
while(startGame(Term) == true) {
|
||||
while(startGame(Term, Rand) == true) {
|
||||
// clear screen and stuff?
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -1,2 +1,2 @@
|
||||
FIL monster.obj,muppet.obj,player.obj,room.obj,VGA256Term.obj
|
||||
FIL monster.obj,muppet.obj,player.obj,rc4.obj,room.obj,VGA256Term.obj
|
||||
|
||||
|
||||
@@ -1,3 +1,24 @@
|
||||
/* Copyright (C) 2021 William Welna (wwelna@occultusterra.com)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "headers.hpp"
|
||||
|
||||
RC4::RC4(char *seed, int len) {
|
||||
|
||||
Reference in New Issue
Block a user