gtheler 5 лет назад
Родитель
Сommit
eb571b8548
7 измененных файлов: 59 добавлений и 25 удалений
  1. +2
    -1
      Makefile.am
  2. +0
    -0
      doc/libreblackjack.texi
  3. +2
    -15
      src/blackjack.cpp
  4. +17
    -7
      src/blackjack.h
  5. +6
    -2
      src/main.cpp
  6. +20
    -0
      src/stdinout.cpp
  7. +12
    -0
      src/stdinout.h

+ 2
- 1
Makefile.am Просмотреть файл



blackjack_SOURCES = \ blackjack_SOURCES = \
src/main.cpp \ src/main.cpp \
src/blackjack.cpp
src/blackjack.cpp \
src/stdinout.cpp

+ 0
- 0
doc/libreblackjack.texi Просмотреть файл


+ 2
- 15
src/blackjack.cpp Просмотреть файл

setInputNeeded(true); setInputNeeded(true);
} }


void Blackjack::ask() {
std::string input_buffer;
std::cout << "what do you want to do?" << std::endl;
std::cin >> input_buffer;
if (input_buffer == "hit" || input_buffer == "h") {
player_command = Command::Hit;
} else {
player_command = Command::None;
}
}

// returns zero if it is a common command and we need to ask again // returns zero if it is a common command and we need to ask again
// returns positive if what was asked was answered // returns positive if what was asked was answered
// returns negative if what was aked was not asnwered or the command does not apply // returns negative if what was aked was not asnwered or the command does not apply
int Blackjack::process() {
int Blackjack::process(Command command) {
switch (player_command) {
switch (command) {
case Command::Hit: case Command::Hit:
std::cout << "ok, you hit" << std::endl; std::cout << "ok, you hit" << std::endl;
finished(true); finished(true);

+ 17
- 7
src/blackjack.h Просмотреть файл

*------------------- ------------ ---- -------- -- - - - *------------------- ------------ ---- -------- -- - - -
*/ */


#ifndef BLACKJACK_H
#define BLACKJACK_H

enum class DealerAction { enum class DealerAction {
None, None,
StartNewHand, StartNewHand,


void deal(); void deal();
void ask(); void ask();
int process();
int process(Command);
void setNextAction(DealerAction a) { void setNextAction(DealerAction a) {
double insurance = 0; double insurance = 0;
int bet = 0; int bet = 0;
};

class Player {
public:
Player() = default;
~Player() = default;
// delete copy and move constructors
Player(Player&) = delete;
Player(const Player&) = delete;
Player(Player &&) = delete;
Player(const Player &&) = delete;
virtual int play(Command *, int *) = 0;
}; };


#endif

+ 6
- 2
src/main.cpp Просмотреть файл

#include <iostream> #include <iostream>


#include "blackjack.h" #include "blackjack.h"
#include "stdinout.h"


int main(int argc, char **argv) { int main(int argc, char **argv) {
// TODO: pass args/conf to the constructor // TODO: pass args/conf to the constructor
Blackjack dealer; Blackjack dealer;
StdInOut player;
std::cout << "Let's play" << std::endl; std::cout << "Let's play" << std::endl;
dealer.setNextAction(DealerAction::StartNewHand); dealer.setNextAction(DealerAction::StartNewHand);
Command command = Command::None;
while (!dealer.finished()) { while (!dealer.finished()) {
dealer.setInputNeeded(false); dealer.setInputNeeded(false);
// TODO: clean buffers // TODO: clean buffers
if (dealer.getInputNeeded()) { if (dealer.getInputNeeded()) {
do { do {
// TODO: check for too many errors meaning dealer and player do not understand each other // TODO: check for too many errors meaning dealer and player do not understand each other
dealer.ask();
} while (dealer.process() <= 0);
player.play(&command, nullptr);
} while (dealer.process(command) <= 0);
} }
} }

+ 20
- 0
src/stdinout.cpp Просмотреть файл

#include <iostream>

#include "blackjack.h"
#include "stdinout.h"

int StdInOut::play(Command *command, int *param) {
std::cout << "what do you want to do" << std::endl;
std::string input_buffer;
std::cin >> input_buffer;
if (input_buffer == "hit" || input_buffer == "h") {
*command = Command::Hit;
} else {
*command = Command::None;
}
return 0;
}

+ 12
- 0
src/stdinout.h Просмотреть файл

#ifndef STDINOUT_H
#define STDINOUT_H
#include "blackjack.h"

class StdInOut : Player {
public:
StdInOut() { };
~StdInOut() { };
int play(Command *, int *) override;
};
#endif

Загрузка…
Отмена
Сохранить