Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
all: pigs

pigs: main.o computer.o player.o
g++ main.o computer.o player.o -o pigs

main.o: main.cpp
g++ -c main.cpp

player.o: player.cpp player.h
g++ -c player.cpp player.h

hello.o: computer.cpp computer.h
g++ -c computer.cpp computer.h

clean:
rm *o pigs
22 changes: 22 additions & 0 deletions computer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//cpp file for computer
#include<iostream>
#include<string>
using namespace std;


int computer(int playernum, int totalscore, int score)
{
if(score == 1)
{
playernum++;
}
else
{
if(totalscore >= 100)
{
cout<<"Player "<<playernum<<" is win !"<<endl;
}
}
return playernum
}

28 changes: 28 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//main file for pigsgame
#include <iostream>
#include <string>
#include "player.h"
using namespace std;

int main()
{
player p;
computer c;
int player_win = 0;
int computer_win = 0;
while(1)
{
player_win = p.turn();
if(player_win >= 100)
{
cout << "Player Wins!\n";
exit(0);
}
computer_win = c.turn();
if(computer_win >= 100)
{
cout << "Computer Wins!\n";
exit(0);
}
}
}
62 changes: 62 additions & 0 deletions player.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//cpp file for player

#include"player.h"

using namespace std;

void Player:Player(int Score)
{
Score = TotalScore;
}

void Player:ResetTurnScore()
{
TurnScore=0;
}
bool Player:CheckForContinue()
{
string YesOrNo;
cout << "Roll Again? (y/n)" << endl;
while()
{
cin >> YesOrNo;
if ( cin == "y")
{
return true;
}
else if(cin == "n")
{
return false;
}
else
{
cout << "Please type a y or n"
}
}
}
int Player:ReturnTotalScore()
{
return TurnScore+TotalScore;
}

void Player:PlayerTurn()
{
int dice;
while()
{
dice = rand () % 6 + 1;
if (dice == 1)
{
ResetTurnScore();
return;
}
TurnScore = TurnScore + dice;
if(CheckForContinue())
{
}
else
{
return;
}
}
}
21 changes: 21 additions & 0 deletions player.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef PLAYER_H;
#define PLAYER_H;
#include<iostream>
#include<string>
using namespace std;

Class Player
{
Public:
Player()
void ResetTurnScore();
bool CheckForContinue();
void ReturnTotalScore();
void PlayerTurn();

Private:
int TurnScore;
int TotalScore;
};

#endif