def test_crazy_eights_input_invalid(self): input_sys = InputSystem() result = input_sys.handle_crazy_eights_input("345") self.assertEqual(True, "Invalid input" in result)
def test_handle_game_input_incorrect(self): in_sys = InputSystem() result = in_sys.handle_game_input("Go Fish", "1,2") self.assertEqual(True, "Invalid game" in result)
def test_mastermind_wrong_size(self): input_system = InputSystem() result = input_system.handle_game_input("Mastermind", "53255") self.assertEqual(True, "Invalid input" in result)
def test_blackjack_input_help(self): input_sys = InputSystem() result = input_sys.handle_blackjack_input("help") self.assertEqual(True, "If your hand's sum" in result)
def test_handle_game_input_correct(self): in_sys = InputSystem() in_sys.handle_game_input("Minesweeper", "1,2") self.assertEqual([[1, 2]], in_sys.minesweeper_game.game_history)
def test_crazy_eights_input_help(self): input_sys = InputSystem() result = input_sys.handle_crazy_eights_input("help") self.assertEqual(True, "matches either the suit" in result)
def run_pyarcade(): """Method used to start the pyarcade. Logic of navigating the pyarcade and starting selected games as well as output of choices are encapsulated in this method Return: String: output of current state of pyarcade ex: menus, game outputs, etc """ model = Model() input_sys = InputSystem() username_logged_in = None while True: clear() print('Welcome to PyArcade (Enter number)') menu = '(1) Mastermind (2) Minesweeper (3) Crazy Eights (4) Blackjack (5) Create Account (6) Login (7) ' \ 'Exit ' if username_logged_in: menu = '(1) Mastermind (2) Minesweeper (3) Crazy Eights (4) Blackjack (5) Logout (6) Exit (7) Load ' \ 'Save ' print(menu) game_input = input() if game_input == '5' and username_logged_in: username_logged_in = None continue if game_input == '5' and not username_logged_in: print('Username:'******'Password:'******'Confirm password:'******'Failed to create account.') else: print('Account created.') model.authenticate(username, passwd) username_logged_in = username continue if game_input == '6' and username_logged_in: break if game_input == '6' and not username_logged_in: print('Username:'******'Password:'******'Login failed.') else: print('Login success.') username_logged_in = username continue if game_input == '7' and not username_logged_in: break if game_input == '7' and username_logged_in: saves = model.list_saves(username_logged_in) for save in saves: print(save.save_name) print("Enter any key to continue:") input() game_in_play = "" if game_input == "1": game_in_play = "Mastermind" elif game_input == "2": game_in_play = "Minesweeper" elif game_input == "3": game_in_play = "Crazy Eights" elif game_input == "4": game_in_play = "BlackJack" clear() print(input_sys.handle_game_input(game_in_play, "New Game")) while game_in_play: print( "Game Options: \n" "New Game (Start new game)\n" "Reset (Reset game)\n" "Clear (Clear game history)\n" "Save (Save Game)\n" "Load (Load Game)\n" "Help (Game Instructions)\n" "Quit (Leave game)\n" "* The options above can be entered at any time during game play *\n" ) if game_input == "1": print("Please enter your guess (\"####\")") elif game_input == "2": print("Please enter x, y coordinate (\"#,#\")") elif game_input == "3": print( "Please type draw or enter card you wish to play (Ex: Eight,Spades)." ) elif game_input == "4": print("Please enter your move (hit or stand)") else: print("Invalid selection") break user_move = str(input()) clear() if user_move.lower() == "quit": break if user_move.lower() == "save" and username_logged_in: print("Enter save name: ") save_name = str(input()) game_obj = input_sys.handle_game_input(game_in_play, user_move) model.save_game_by_username(game_obj, save_name, username_logged_in) input_sys.handle_game_input(game_in_play, user_move) elif user_move.lower() == "load" and username_logged_in: saves = model.list_saves(username_logged_in) for save in saves: print(save.save_name) print("Type name of save: ") save_name = str(input()) game_save = model.load_game(save_name, username_logged_in) input_sys.set_game_to_load(game_save) print(input_sys.handle_game_input(game_in_play, user_move)) else: print( input_sys.handle_game_input(game_in_play, user_move) + "\n") if input_sys.handle_game_input(game_in_play, "state") == "Game over.": print("Game over. Play again? y/n") if str(input()) != "y": break else: print(input_sys.handle_game_input(game_in_play, "reset"))
def test_valid_minesweeper_choice_invalid_input(self): input_sys = InputSystem() result = input_sys.handle_game_input("Minesweeper", "string") self.assertEqual(True, "Invalid input" in result)
def test_minesweeper_input_reset(self): i_s = InputSystem() i_s.handle_minesweeper_input("4,3") result = i_s.handle_minesweeper_input("Reset") self.assertEqual(True, "Game reset" in result)
def test_mastermind_help(self): input_system = InputSystem() result = input_system.handle_mastermind_input("help") self.assertEqual(True, "bulls are numbers" in result)
def test_mastermind_invalid_input(self): input_system = InputSystem() result = input_system.handle_mastermind_input(1234) self.assertEqual(True, "Invalid input" in result)
def test_mastermind_reset(self): input_system = InputSystem() result = input_system.handle_mastermind_input("reset") self.assertEqual(True, "Game reset" in result)
def test_mastermind_clear(self): input_system = InputSystem() self.assertEqual("History cleared", input_system.handle_mastermind_input("Clear"))
def test_blackjack_game(self): input_sys = InputSystem() result = input_sys.handle_game_input("BlackJack", "stand") self.assertEqual(True, "CURRENT HAND" in result)
def test_crazy_eights_input_clear(self): input_sys = InputSystem() result = input_sys.handle_crazy_eights_input("clear") self.assertEqual(True, "History cleared" in result)
def test_minesweeper_input_clear(self): in_sys = InputSystem() in_sys.handle_minesweeper_input("4,3") self.assertEqual([[4, 3]], in_sys.minesweeper_game.game_history) self.assertEqual([[4, 3]], in_sys.minesweeper_game.game_history)
def test_crazy_eights_game(self): input_sys = InputSystem() result = input_sys.handle_game_input("Crazy Eights", "Eight,Spades") self.assertEqual(True, "Player Hand" in result)
def test_minesweeper_input_invalid(self): in_sys = InputSystem() result = in_sys.handle_minesweeper_input("Mines") self.assertEqual(True, "Invalid input" in result) result = in_sys.handle_minesweeper_input("1,2,3") self.assertEqual(True, "Invalid input" in result)
def test_blackjack_input_invalid(self): input_sys = InputSystem() result = input_sys.handle_blackjack_input("345") self.assertEqual(True, "Invalid input" in result)
def test_minesweeper_input_help(self): i_s = InputSystem() result = i_s.handle_minesweeper_input("help") self.assertEqual(True, "find all the mines" in result)
from flask import request, flash from flask_sqlalchemy import SQLAlchemy from flask_restful import Api, Resource from flask import Flask, render_template, redirect, url_for from flask_bootstrap import Bootstrap from flask_wtf import FlaskForm from wtforms import StringField, PasswordField, BooleanField from wtforms.validators import InputRequired, Length, EqualTo from flask_login import LoginManager, UserMixin, login_user, login_required, \ logout_user, current_user from typing import List from pyarcade.input_system import InputSystem import pickle input_system = InputSystem() app = Flask(__name__) app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.config['SECRET_KEY'] = 'd9eae96b0e36281c7de5759e5d1aa7740426000710b2db47' app.config[ 'SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root@db:3306/pyarcadedb' bootstrap = Bootstrap(app) db = SQLAlchemy(app) api = Api(app) login_manager = LoginManager() login_manager.init_app(app) login_manager.login_view = 'login' class User(UserMixin, db.Model):
def test_blackjack_input_valid(self): input_sys = InputSystem() result = input_sys.handle_blackjack_input("hit") self.assertEqual(True, "CURRENT HAND" in result)