diff --git a/Engine.cpp b/Engine.cpp new file mode 100644 index 0000000..e97f81b --- /dev/null +++ b/Engine.cpp @@ -0,0 +1,18 @@ +// +// Engine.cpp +// +// +// Created by Kevin Perkins on 9/9/15. +// +// + +#include "Engine.h" + +Engine::Engine() { + m_players = 0; + m_dice = 0; +} + +Engine::~Engine() { + +} diff --git a/Engine.h b/Engine.h new file mode 100644 index 0000000..513b483 --- /dev/null +++ b/Engine.h @@ -0,0 +1,27 @@ +// +// Engine.h +// +// +// Created by Kevin Perkins on 9/9/15. +// +// + +#ifndef ____Engine__ +#define ____Engine__ + +#include + +using namespace std; + +class Engine { +public: + Engine(); + ~Engine(); + +private: + int m_players; + int m_dice; + //Decide how to handle turns, Enum or multi dimensional array where each point is a turn status. +}; + +#endif /* defined(____Engine__) */ diff --git a/Makefile b/Makefile new file mode 100755 index 0000000..ff1fcbf --- /dev/null +++ b/Makefile @@ -0,0 +1,23 @@ +#### Makefile Start #### +CC=g++ +CFLAGS=-std=c++0x -c -Wall +LIBLOCATION=-L/usr/local/lib +LIBS= +HDRLOCATION=-I/usr/local/include + +SOURCES=main.cpp menu.cpp player.cpp cpu.cpp dice.cpp +OBJECTS=$(SOURCES:.cpp=.o) +EXECUTABLE=PigsGame + +all: $(SOURCES) $(EXECUTABLE) + +$(EXECUTABLE): $(OBJECTS) + $(CC) $(OBJECTS) $(LIBLOCATION) $(HDRLOCATION) $(LIBS) -o $@ + +.cpp.o: + $(CC) $(CFLAGS) $< -o $@ + +clean: + rm -f *.o PigsGame +##Makefile Derived from stackoverflow: +#### Makefile End #### diff --git a/PigsGame b/PigsGame new file mode 100755 index 0000000..e6c6f2e Binary files /dev/null and b/PigsGame differ diff --git a/README.md b/README.md index fd09ab5..081edef 100644 --- a/README.md +++ b/README.md @@ -13,3 +13,5 @@ The first player to score 100 or more points wins. From: https://en.wikipedia.org/wiki/Pig_(dice_game) This implementation is a single player game against a computer player. + +Currently, this version of PigsGame does not work. The code needs to be linked together and properly intertwined. [Update Sep15.2015] diff --git a/cpu.cpp b/cpu.cpp new file mode 100644 index 0000000..097dba0 --- /dev/null +++ b/cpu.cpp @@ -0,0 +1,12 @@ +#include "cpu.h" + +int CPU::Roll() { + int roll_num = Player::Roll(); + if(roll_num <= dice->get_sides()/2) { + Roll(); + EndTurn(); + } + return total_score; +} + +bool CPU::is_player() { return false; } diff --git a/cpu.h b/cpu.h new file mode 100644 index 0000000..eafd76e --- /dev/null +++ b/cpu.h @@ -0,0 +1,14 @@ +#ifndef CPU_H +#define CPU_H +#include "player.h" +#include "dice.h" + +class CPU : public Player { + + public: + CPU(int sides) : Player(sides) { }; + int Roll(); + bool is_player(); + +}; +#endif diff --git a/cpu.o b/cpu.o new file mode 100644 index 0000000..71f1712 Binary files /dev/null and b/cpu.o differ diff --git a/dice.cpp b/dice.cpp new file mode 100644 index 0000000..4b7433f --- /dev/null +++ b/dice.cpp @@ -0,0 +1,39 @@ +#include "dice.h" +#include +#include + +Dice::Dice(int sides) { + num_sides = sides; // Set number of dice sides + srand((unsigned)time(NULL)); // Seed random number generator +} + +int Dice::roll() { + cur_roll = (rand() % num_sides); + cur_roll += 1; + return cur_roll; +} + +int Dice::roll(int target) { + if((target > 0) && (target < 7)) { + cur_roll = target; + } else { + cur_roll = 6; + } + return cur_roll; +} + +int Dice::roll_no_one() { + cur_roll = (rand() % num_sides); + + while(cur_roll == 1) { + cur_roll = (rand() % num_sides); + } + + return cur_roll; +} + + + +int Dice::get_sides() { + return num_sides; // Get number of sides on dice +} diff --git a/dice.h b/dice.h new file mode 100644 index 0000000..2c51e1f --- /dev/null +++ b/dice.h @@ -0,0 +1,16 @@ +#ifndef DICE_H +#define DICE_H + +class Dice { + public: + Dice(int); + int roll(); // Fair roll + int roll(int); // Tell dice what you want to roll + int roll_no_one(); // Unfair roll (cannot roll a 1) + int get_sides(); // Return number of sides on dice + private: + int num_sides; + int cur_roll; +}; + +#endif diff --git a/dice.o b/dice.o new file mode 100644 index 0000000..f419b31 Binary files /dev/null and b/dice.o differ diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..9687cb0 --- /dev/null +++ b/main.cpp @@ -0,0 +1,17 @@ +#include "cpu.h" +#include "menu.h" +#include "player.h" +#include "dice.h" + +#include +#include + + +int main(int argc, char **argv) { + + Menu main_menu; + + main_menu.printWelcome(); + + return 0; +} diff --git a/main.o b/main.o new file mode 100644 index 0000000..29ff7aa Binary files /dev/null and b/main.o differ diff --git a/menu.cpp b/menu.cpp new file mode 100644 index 0000000..84ab3a8 --- /dev/null +++ b/menu.cpp @@ -0,0 +1,48 @@ +//menu.cpp +//bool getPlayerInfo(); +//int getNumberOfDice(); +//int getNumberOfPlayers(); +//int getScore(); +#include "menu.h" +Menu::Menu(){ + dieSides = 0; + numDice = 0; + numPlayers = 0; + score = 0; +} +int Menu::printWelcome(){ + int choice = 0; + cout << "Welcome! Pig is a game with dice, risk, and more danger than you" + << "will ever see in your life. You have been warned."; + cout << "What would you like to do?\n"; + cout << "__________________________________________________\n"; + cout << "(1) Start\n(2)Instructions\n(3)Quit\n"; + cout << "Choice: "; + cin >> choice; + + while (choice == 0) { + if (choice == 1){printStart();} + else if (choice == 2){printInstructions();} + else if (choice == 3){quit();} + else { cout << "You have entered an incorrect choice. Please follow instructions better.\n"; + choice = 0;} + } + return choice; +} +void Menu::printInstructions(){ + ; +} +void Menu::printStart(){ + +} +//void Menu::printScore(); +void Menu::printWin(){ + cout << "Congratulations, you have defeated the most difficult AI on this world.\n"; +} +void Menu::printLose(){ + +} +void Menu::quit(){ + exit(0); +} + diff --git a/menu.h b/menu.h new file mode 100644 index 0000000..ab40911 --- /dev/null +++ b/menu.h @@ -0,0 +1,33 @@ +//menu.h +#ifndef MENU_H +#define MENU_H + +#include +#include +using namespace std; + +class Menu{ + + public: + Menu(); + bool getPlayerInfo(); + int getNumberOfDice(); + int getNumberOfPlayers(); + int getScore(); + int printWelcome(); + void printInstructions(); + void printStart(); + void printScore(); + void printWin(); + void printLose(); + void quit(); + private: + int dieSides; + int numDice; + int numPlayers; + int score; + + +}; + +#endif //MENU_H diff --git a/menu.o b/menu.o new file mode 100644 index 0000000..05f87ad Binary files /dev/null and b/menu.o differ diff --git a/menu/menu.cpp b/menu/menu.cpp new file mode 100644 index 0000000..a6fb69c --- /dev/null +++ b/menu/menu.cpp @@ -0,0 +1,49 @@ +//menu.cpp +//bool getPlayerInfo(); +//int getNumberOfDice(); +//int getNumberOfPlayers(); +//int getScore(); +#include "menu.h" +Menu::Menu(){ + dieSides = 0; + numDice = 0; + numPlayers = 0; + score = 0; +} +int Menu::printWelcome(){ + int choice = 0; + cout << "Welcome! Pig is a game with dice, risk, and more danger than you" + << "will ever see in your life. You have been warned."; + cout << "What would you like to do?\n"; + cout << "__________________________________________________\n"; + cout << "(1) Start\n(2)Instructions\n(3)Quit\n"; + cout << "Choice: "; + cin >> choice; + if (choice == 1){printStart();} + else if (choice == 2){printInstructions();} + else if (choice == 3){quit();} + else { cout << "You have entered an incorrect choice. Please follow instructions better.\n";} + return choice; +} +void Menu::printInstructions(){ + ; +} +void Menu::printStart(){ + +} +//void Menu::printScore(); +void Menu::printWin(){ + cout << "Congratulations, you have defeated the most difficult AI on this world.\n"; +} +void Menu::printLose(){ + +} +void Menu::quit(){ + exit(0); +} + +int main() { + Menu mainMenu; + mainMenu.printWelcome(); + return 0; +} diff --git a/menu/menu.h b/menu/menu.h new file mode 100644 index 0000000..8521d78 --- /dev/null +++ b/menu/menu.h @@ -0,0 +1,32 @@ +//menu.h +#ifndef MENU_H +#define MENU_H + +#include +using namespace std; + +class Menu{ + + public: + Menu(); + bool getPlayerInfo(); + int getNumberOfDice(); + int getNumberOfPlayers(); + int getScore(); + int printWelcome(); + void printInstructions(); + void printStart(); + void printScore(); + void printWin(); + void printLose(); + void quit(); + private: + int dieSides; + int numDice; + int numPlayers; + int score; + + +}; + +#endif //MENU_H diff --git a/menu/menu.h.gch b/menu/menu.h.gch new file mode 100644 index 0000000..93eee5e Binary files /dev/null and b/menu/menu.h.gch differ diff --git a/player.cpp b/player.cpp new file mode 100644 index 0000000..cfcbf53 --- /dev/null +++ b/player.cpp @@ -0,0 +1,41 @@ +#include "player.h" + +Player::Player(int Sides) { + total_score = 0; + turn_score = 0; + + dice = new Dice(Sides); +} + +Player::~Player() { + delete dice; +} + +bool Player::is_player() { + return true; +} + +int Player::GetTotalScore() { + return total_score; +} + +int Player::GetTurnScore() { + return turn_score; +} + +int Player::Roll() { + int roll = dice->get_sides(); + + if (roll == 1) { + turn_score = 0; + } else { + turn_score += roll; + } + + return roll; +} + +void Player::EndTurn() { + total_score += turn_score; + turn_score = 0; +} diff --git a/player.h b/player.h new file mode 100644 index 0000000..9eb694f --- /dev/null +++ b/player.h @@ -0,0 +1,23 @@ +#ifndef __PLAYER__ +#define __PLAYER__ + +#include "dice.h" + + +class Player { + public: + Player(int Sides); + ~Player(); + bool is_player(); + int GetTotalScore(); + int GetTurnScore(); + int Roll(); + void EndTurn(); + protected: + int total_score, + turn_score; + + Dice *dice; +}; + +#endif /* __PLAYER__ */ diff --git a/player.o b/player.o new file mode 100644 index 0000000..af6b58d Binary files /dev/null and b/player.o differ diff --git a/temp_main.cpp b/temp_main.cpp new file mode 100644 index 0000000..3afde1e --- /dev/null +++ b/temp_main.cpp @@ -0,0 +1,90 @@ +// Matt Edge +// Last Update: 09/15/15 11:30 Am + +#include +#include +#include "dice.h" +#include +#include +#include "player.h" +#include "menu.h" +#include "cpu.h" +using namespace std; + +int main() +{ + int win_total = 100; + string num_sides; + string name; + string choice; + Menu mainMenu; + mainMenu.printWelcome(); + cout << "______________________________________________\n"; + cout << "Insert player name.\n"; + cin >> name; + cout << "______________________________________________\n"; + cout << "Insert number of sides on dice.\n"; + cin >> num_sides; + cout << "______________________________________________\n"; + int sides = atoi(num_sides.c_str()); + Dice dice(sides); + Player *curPlayer; + Player *player = new Player(sides); + CPU *computer = new CPU(sides); + curPlayer = player; + while(curPlayer->GetTotalScore() < 100) + { + if(curPlayer->is_player() == true) + { + cout << name << "'s turn.\n"; + cout << "What do you want to do?\n"; + cout << "(1) Roll\n (2) Hold\n"; + cout << "______________________________________________\n"; + cin >> choice; + while(choice == "1") + { + curPlayer->Roll(); + if(curPlayer->GetTurnScore() == 0) + { + cout << "You rolled a 1!\n" << name << "'s turn ends\n"; + cout << "______________________________________________\n"; + choice = 2; + } + else + { + cout << "Your turn score is:\n" << curPlayer->GetTurnScore() << "\n"; + cout << "______________________________________________\n"; + cout << "What do you want to do?\n"; + cout << "(1) Roll\n (2) Hold\n"; + cout << "______________________________________________\n"; + cin >> choice; + } + } + curPlayer->EndTurn(); + cout << name << "'s total score is:\n Total Score: " << curPlayer->GetTotalScore() << "\n" + << "______________________________________________\n"; + curPlayer = computer; + } + else + { + curPlayer->Roll(); + cout << "Computer's total score is:\n Total Score: " << curPlayer->GetTotalScore() << "\n" + << "______________________________________________\n"; + curPlayer = player; + } + + } + if(player->GetTotalScore() >= 100) + { + cout << "Congradulations "<< name << "!!!\n You won.\n"; + } + else + { + cout << "Sorry... You lose. \n"; + } + cout << name << "'s final score is: " << player->GetTotalScore() << "\n" + << "Computer's final score is: " << computer->GetTotalScore() << "\n" + << "______________________________________________\n"; + + return 0; +} diff --git a/test b/test new file mode 100755 index 0000000..2668509 Binary files /dev/null and b/test differ