Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
92d5d50
Added Kevinspush.rb
Sep 9, 2015
8ad678a
Created cpu class file which inherits player class
ahorgan Sep 9, 2015
7f443ff
Created main.cpp
Sep 9, 2015
358e779
Added the Engine Class, Still needs a man structure for event handling.
Sep 9, 2015
df9316b
Adds shell class for dice
Sep 9, 2015
32f5ed2
created basic player class
chadduffin Sep 9, 2015
193ed96
Added partially complete menu.h and menu.cpp, needs rest of fxns
jdifuria Sep 9, 2015
8c98d99
Fixes random number generation
Sep 14, 2015
2b82be1
Fixed Endturn / Roll functions
chadduffin Sep 14, 2015
0ad751b
Wrote roll function
ahorgan Sep 14, 2015
da91a45
Adds some loaded dice functionality
Sep 14, 2015
5736091
Added is_player function
chadduffin Sep 14, 2015
8b70e7e
Added is_player() function
ahorgan Sep 14, 2015
3baefcb
Updated menu to be working, needs other classes to fully function.
jdifuria Sep 14, 2015
0b5a4cb
Changed AI to reroll for lower dice numbers
ahorgan Sep 14, 2015
b37503c
Updated main.cpp to handle user input to perform game functions
Sep 14, 2015
cf8a954
Formatting and changed to pointers to objects
Sep 15, 2015
88d66de
Updated last update info
Sep 15, 2015
93daf5e
Merge pull request #1 from jdifuria/menu
jdifuria Sep 15, 2015
2412fa2
Put menu files into one directory
jdifuria Sep 15, 2015
8658239
Merge pull request #2 from jdifuria/menu
jdifuria Sep 15, 2015
cfd6df9
Merge pull request #3 from jdifuria/engine
jdifuria Sep 15, 2015
e364cb5
Merge pull request #4 from jdifuria/main
Sep 16, 2015
c3f3da4
Merge pull request #5 from jdifuria/computer
jdifuria Sep 16, 2015
974099b
Update README.md
jdifuria Sep 16, 2015
966bf18
Merge pull request #6 from jdifuria/player-class
jdifuria Sep 16, 2015
ac46747
Merge pull request #7 from jdifuria/dice
jdifuria Sep 16, 2015
1c2ac4b
Updated program links, allowed for compilation
chadduffin Sep 16, 2015
8655d17
Delete Kevins_Push.rb
chadduffin Sep 16, 2015
e2fb60b
Added makefile
chadduffin Sep 16, 2015
09d9696
Merge branch 'master' of https://github.com/jdifuria/PigsGame
chadduffin Sep 16, 2015
9db5f3a
Update and rename makefile to Makefile
jdifuria Sep 16, 2015
a79ccf4
Updated makefile, no more warning issues, added a clean
jdifuria Sep 16, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Engine.cpp
Original file line number Diff line number Diff line change
@@ -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() {

}
27 changes: 27 additions & 0 deletions Engine.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// Engine.h
//
//
// Created by Kevin Perkins on 9/9/15.
//
//

#ifndef ____Engine__
#define ____Engine__

#include <iostream>

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__) */
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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 ####
Binary file added PigsGame
Binary file not shown.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
12 changes: 12 additions & 0 deletions cpu.cpp
Original file line number Diff line number Diff line change
@@ -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; }
14 changes: 14 additions & 0 deletions cpu.h
Original file line number Diff line number Diff line change
@@ -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
Binary file added cpu.o
Binary file not shown.
39 changes: 39 additions & 0 deletions dice.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "dice.h"
#include <cstdlib>
#include <ctime>

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
}
16 changes: 16 additions & 0 deletions dice.h
Original file line number Diff line number Diff line change
@@ -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
Binary file added dice.o
Binary file not shown.
17 changes: 17 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "cpu.h"
#include "menu.h"
#include "player.h"
#include "dice.h"

#include <string>
#include <iostream>


int main(int argc, char **argv) {

Menu main_menu;

main_menu.printWelcome();

return 0;
}
Binary file added main.o
Binary file not shown.
48 changes: 48 additions & 0 deletions menu.cpp
Original file line number Diff line number Diff line change
@@ -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);
}

33 changes: 33 additions & 0 deletions menu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//menu.h
#ifndef MENU_H
#define MENU_H

#include <stdlib.h>
#include <iostream>
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
Binary file added menu.o
Binary file not shown.
49 changes: 49 additions & 0 deletions menu/menu.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
32 changes: 32 additions & 0 deletions menu/menu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//menu.h
#ifndef MENU_H
#define MENU_H

#include <iostream>
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
Binary file added menu/menu.h.gch
Binary file not shown.
41 changes: 41 additions & 0 deletions player.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
Loading