online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
from player import Player from game import Game from welcome import Welcome #delay time.sleep(seconden) import time #Clear console en reset color cls() import os def cls(): print("\033[0;37m.") os.system('cls' if os.name=='nt' else 'clear') #TicTacToe start message welcome = Welcome(); welcome.logo(); #Players name and character select cls() player1 = Player() player1.name = input("Player 1, What is your name? \033[1;34m") player1.score = 0 player1.character = input("\033[0;37m" + player1.name + ", which character do you want to play with? \033[1;34m") while len(player1.character) >= 2 or len(player1.character) == 0: cls() print("\033[1;31mYour character may only consist of one letter! \033[0;37mTry again!") player1.character = input(player1.name + ", which character do you want to play with? \033[1;34m") cls() player2 = Player() player2.name = input("Player 2, What is your name? \033[1;34m") player2.score = 0 player2.character = input( "\033[0;37m" + player2.name + ", which character do you want to play with? \033[1;34m") while len(player2.character) >= 2 or len(player2.character) == 0 or player1.character == player2.character: while len(player2.character) >= 2 or len(player2.character) == 0: cls() print("\033[1;31mYour character may only consist of one letter! \033[0;37mTry again!") player2.character = input(player2.name + ", which character do you want to play with? \033[1;34m") cls() while player1.character == player2.character: cls() print("\033[1;31mYou can't have the same sign! \033[0;37mTry again") player2.character = input(player2.name + ", which character do you want to play with? \033[1;34m") cls() #Color player1 if player1.character == "X": player1.character = "\033[1;31mX\033[0;37m" else: if player1.character == "O": player1.character = "\033[1;34mO\033[0;37m" else: player1.character = "\033[1;32m" + player1.character + "\033[0;37m" #Color player2 if player2.character == "X": player2.character = "\033[1;31mX\033[0;37m" else: if player2.character == "O": player2.character = "\033[1;34mO\033[0;37m" else: player2.character = "\033[1;33m" + player2.character + "\033[0;37m" #Ask fot information cls() infoquestion = input("Would you like more information before you start? \033[1;34m") while infoquestion != "Yes" and infoquestion != "yes" and infoquestion != "No" and infoquestion != "no": cls() print("\033[1;31mI don't recognize this answer! \033[0;37mTry again!") infovraag = input("Would you like more information before you start? \033[1;34m") if infoquestion == "yes" or infoquestion == "Yes": cls() welcome.info(); #Start game game = Game(player1, player2); doesPlay = True while doesPlay == True: cls() print("Welcome " + player1.name + " and " + player2.name + "!") input("\nPress Enter to start! ") game.play() #Ask to start again print("The score is: " + str(player1.score) + "-" + str(player2.score)) answer = input("\nDo you want to play again? \033[1;34m") while answer != "Yes" and answer != "yes" and answer != "No" and answer != "no": cls() game.board.print_board() game.check_winner_draw() game.check_winner() print("The score is: " + str(speler1.score) + "-" + str(speler2.score)) print("\n\033[1;31mI don't recognize this answer! \033[0;37mTry again!") antwoord = input("Do you want to play again? \033[1;34m") if answer == "No" or answer == "no": #Stop game doesPlay = False cls() if player1.score == player2.score: #draw print("The final score is: " + str(player1.score) + "-" + str(player2.score)) print("Its a draw") time.sleep(3) print("\nGoodbye!") os._exit(0) else: if player1.score <= player2.score: #Player2 win print("The final score is: " + str(speler1.score) + "-" + str(speler2.score)) print(player2.name + "[" + player2.character + "]" + " has won! Congratulations!") time.sleep(3) print("\nGoodbye!") os._exit(0) else: #speler 1 wint print("The final score is: " + str(speler1.score) + "-" + str(speler2.score)) print(player1.name + "[" + player1.character + "]" + " has won! Congratulations!") time.sleep(3) print("\nGoodbye!") os._exit(0) else: doesPlay = True
class Player: name = "" score = 0 character = "" def ask_input(self): pos = input("Where does " + self.name + "[" + self.character + "] wants to put his character? \033[1;34m") return pos
from player import Player class Welcome: #logo def logo(self): print("\033[1;33m _____ _ _____ _____ \n|_ _(_) __|_ _|_ _ __|_ _|__ ___ \n | | | |/ __|| |/ _` |/ __|| |/ _ \ / _ \ \n | | | | (__ | | (_| | (__ | | (_) | __/ \n |_| |_|\___||_|\__,_|\___||_|\___/ \___|") #wachten op enter input("\n\033[0;37mPress Enter to start.. ") #informatie def info(self): print("To win, of course, you have to get 3 in a row. To put your character in a box you have to enter the coordinate of the box. You do this as follows: X,Y where X is horizontal and Y vertical.\nYou can only enter 0, 1 or 2. This means that with, for example, 1,2 your character will be in the bottom center.") #wachten op Enter input("\nPress Enter to continue..")
class Box: posX = None posY = None value = None def __init__(self, x, y, value): self.posX = x self.posY = y self.value = value
from player import Player from field import Field import time #Clear console en reset color cls() import os def cls(): print("\033[0;37m.") os.system('cls' if os.name=='nt' else 'clear') class Game: players = None currentPlayer = 0 turns = 0 board = None state = "busy" point = True #constructor def __init__(self, player1, player2): #set spelers self.players = [player1, player2] #Bord waarde self.board = Field() def play(self): self.turns = 0 self.state = "busy" self.currentPlayer = 0 self.board = Field() self.point = True while self.state == "busy": cls() self.play_move() self.check_winner_draw() self.check_winner() def play_move(self): #Print current state of the board self.board.print_board() #Setup variables for input validInput = False pos = "" while validInput == False: #Ask player for input pos = self.players[self.currentPlayer].ask_input() #Validate input in the same if statement if self.board.validate_input(pos): #If this is correct then continue validInput = True else: if pos == "0,0" or pos == "0,1" or pos == "0,2" or pos == "1,0" or pos == "1,1" or pos == "1,2" or pos == "2,0" or pos == "2,1" or pos == "2,2": cls() print("\033[1;31mThis space is already occupied! \033[0;37mTry again!") self.board.print_board() else: cls() print("\033[1;31mI don't recognize this! \033[0;37mTry again!") self.board.print_board() self.board.use_input(pos, self.players[self.currentPlayer].character) self.currentPlayer = 1 if self.currentPlayer == 0 else 0 #Check winner def check_winner(self): winner = self.board.get_winner(); for i in range(0, len(self.players)): if self.players[i].character == winner: if self.point == True: self.players[i].score += 1 self.point = False self.state = "over" cls() self.board.print_board() print("Game Over! " + self.players[i].name + "[" + self.players[i].character + "] won this game, congratulations!") #Check draw def check_winner_draw(self): winnerdraw = self.board.get_draw(); if(winnerdraw == "draw"): self.state = "over" cls() self.board.print_board() print("Game Over! It's a draw")
from box import Box class Field: board = [] winPossibilities = [ #vertical [[0, 0], [0, 1], [0, 2]], [[1, 0], [1, 1], [1, 2]], [[2, 0], [2, 1], [2, 2]], #horizontal [[0, 0], [1, 0], [2, 0]], [[0, 1], [1, 1], [2, 1]], [[0, 2], [1, 2], [2, 2]], #diagonal [[0, 0], [1, 1], [2, 2]], [[0, 2], [1, 1], [2, 0]], ] sizeX = 3 sizeY = 3 def __init__(self): self.board = [] for x in range(0,self.sizeX): for y in range(0, self.sizeY): self.board.append(Box(x, y, " ")) def print_board(self): #X for x in range(0, self.sizeX): #setup line line = "" #Y for y in range(0, self.sizeY): #Add value to our line line += "[" + self.op_coord(x, y).value + "]" #Print line print(line) def use_input(self, pos, char): #Split position by ',' raw = pos.split(",") #Get field with x and y and give value self.op_coord(raw[1], raw[0]).value = char def validate_input(self, pos): if pos == "0,0" or pos == "0,1" or pos == "0,2" or pos == "1,0" or pos == "1,1" or pos == "1,2" or pos == "2,0" or pos == "2,1" or pos == "2,2": coord = pos.split(",") field = self.op_coord(coord[1], coord[0]).value #Check if it equals “ “ return False if field != " " or field == None else True else: return False def op_coord(self, x, y): try: for i in range(0, len(self.board)): if int(self.board[i].posX) == int(x) and int(self.board[i].posY) == int(y): return self.board[i] return Box(-1, -1, None) except: return Box(-1, -1, None) def get_winner(self): for i in range(0, len(self.winPossibilities)): pos1 = self.op_coord(self.winPossibilities[i][0][0], self.winPossibilities[i][0][1]).value pos2 = self.op_coord(self.winPossibilities[i][1][0], self.winPossibilities[i][1][1]).value pos3 = self.op_coord(self.winPossibilities[i][2][0], self.winPossibilities[i][2][1]).value if pos1 == pos2 and pos2 == pos3 and pos3 == pos1: return pos1 return None def get_draw(self): amount = 0 for i in range(0, len(self.board)): if self.op_coord(self.board[i].posX, self.board[i].posY).value is not " ": amount = amount + 1 if amount == 9: return "draw"

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue