You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.0KB

  1. /*------------ -------------- -------- --- ----- --- -- - -
  2. * Libre Blackjack - standard blackjack dealer
  3. *
  4. * Copyright (C) 2020 jeremy theler
  5. *
  6. * This file is part of Libre Blackjack.
  7. *
  8. * Libre Blackjack is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * Libre Blackjack is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with Libre Blackjack. If not, see <http://www.gnu.org/licenses/>.
  20. *------------------- ------------ ---- -------- -- - - -
  21. */
  22. #include <iostream>
  23. #include "blackjack.h"
  24. Blackjack::Blackjack() {
  25. std::cout << "I'm your dealer" << std::endl;
  26. }
  27. Blackjack::~Blackjack() {
  28. std::cout << "Bye bye" << std::endl;
  29. }
  30. void Blackjack::deal() {
  31. std::cout << "here are your cards" << std::endl;
  32. setInputNeeded(true);
  33. }
  34. void Blackjack::ask() {
  35. std::string input_buffer;
  36. std::cout << "what do you want to do?" << std::endl;
  37. std::cin >> input_buffer;
  38. if (input_buffer == "hit" || input_buffer == "h") {
  39. player_command = Command::Hit;
  40. } else {
  41. player_command = Command::None;
  42. }
  43. }
  44. // returns zero if it is a common command and we need to ask again
  45. // returns positive if what was asked was answered
  46. // returns negative if what was aked was not asnwered or the command does not apply
  47. int Blackjack::process() {
  48. switch (player_command) {
  49. case Command::Hit:
  50. std::cout << "ok, you hit" << std::endl;
  51. finished(true);
  52. return 1;
  53. break;
  54. case Command::None:
  55. std::cout << "I don't undertand you" << std::endl;
  56. return 0;
  57. break;
  58. }
  59. return 0;
  60. }