0% found this document useful (0 votes)
21 views

FINAL-PROJECT_COMPROG

The document is a final project report from Batangas State University on a computer programming project titled 'Brain Drain,' which is a game designed to test and improve critical thinking skills using Python. The project aims to provide entertainment while enhancing users' cognitive abilities through three games: Hangman, a Trivia Game, and Tic-Tac-Toe. The report outlines the objectives, methodology, and functions used in the development of the game, emphasizing the importance of technology and programming in education.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

FINAL-PROJECT_COMPROG

The document is a final project report from Batangas State University on a computer programming project titled 'Brain Drain,' which is a game designed to test and improve critical thinking skills using Python. The project aims to provide entertainment while enhancing users' cognitive abilities through three games: Hangman, a Trivia Game, and Tic-Tac-Toe. The report outlines the objectives, methodology, and functions used in the development of the game, emphasizing the importance of technology and programming in education.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

Republic of the Philippines

BATANGAS STATE UNIVERSITY


The National Engineering University
Alangilan Campus
Golden Country Homes, Alangilan Batangas City, Batangas, Philippines 4200
Tel Nos.: (+63 43) 425-0139 local 2121 / 2221
E-mail Address: [email protected] | Website Address: http://www.batstate-u.edu.ph

Department of Electronics Engineering

FINAL PROJECT REPORT


CpE 401: Computer Programming
2nd Semester, A.Y 2023-2024

Brain Drain

by:
ACAR, ZAIRA KAE L.
UNTALAN, JOHN PRINCELEE
PEREZ, ARIAN JOY C.

Instructor
Mariefel T. Basibas

MAY 2024

Leading Innovations, Transforming Lives, Building the Nation


Republic of the Philippines
BATANGAS STATE UNIVERSITY
The National Engineering University
Alangilan Campus
Golden Country Homes, Alangilan Batangas City, Batangas, Philippines 4200
Tel Nos.: (+63 43) 425-0139 local 2121 / 2221
E-mail Address: [email protected] | Website Address: http://www.batstate-u.edu.ph

Department of Electronics Engineering

OVERVIEW

Technology was created and one of the most advanced tools as it plays an important part in

society and with that, the world changes from time to time as the people make life a lot easier and

convenient. According to Mickeel Allen (2019), technology has been made in order to improve

the learnings of human beings as well as to enhance its immersiveness and engagement with others.

Technology allows the people to have a better communication with the content they are learning

as well as the purpose of it is in order to enhance the knowledge as well as to entertain the people

around the world.

As technology keeps innovating, computer programming itself is also innovating as the

world today is full of automated machines. Computer programming uses different languages as

well as software for different categories that the developers intended to create. One of the impacts

that happened is Python as it is a programming language that is known for being the easiest

programming tool that was created for beginners. Python can be used for a variety of purposes and

as a result, it can be used to build or create it both in desktop and mobile applications. Python can

also be used to build sophisticated theoretical and numerical applications and built with features

that creates data processing and visualization easier. According to Abhishek Jaiswal (2013),

Python can run on a wide variety of technological devices and maintain a reliable user interface

for all platforms. Thus, python is an excellent language with an immersive mode that allows users

to input data from a simulator directly into the language, facilitating interactive analysis and

debugging of code snippets. The rapid advancement of technology has resulted in a high demand

for computer programming in a variety of areas, including medicine, education, and, most notably,

entertainment. Many apps, such as gaming, are created online and are used by many people to

amuse themselves and to take a break from the stressful and exhausting world. With these

considerations in mind, the programmers devised a plan to create a simple and user-friendly game

Leading Innovations, Transforming Lives, Building the Nation


Republic of the Philippines
BATANGAS STATE UNIVERSITY
The National Engineering University
Alangilan Campus
Golden Country Homes, Alangilan Batangas City, Batangas, Philippines 4200
Tel Nos.: (+63 43) 425-0139 local 2121 / 2221
E-mail Address: [email protected] | Website Address: http://www.batstate-u.edu.ph

Department of Electronics Engineering

that anyone of any age might enjoy. The Brain Drain is a game that is created in order to know the

individual's limitation to think that will actually make your brain drain.

This game is powered by Python, a high-level programming language that is easy to use,

understand, and execute. It is an environmentally friendly and user-friendly application game that

will stimulate and measure a person's capacity and capability to think, as well as improve their

awareness of critical thinking. Basically, the game Brain Drain can be used in a variety of fields

since it can be easily changed using simple programming codes, and one example is using it for

educational purposes. The game number one entitled “Hangman” can be used as an icebreaker and

an energizer to start every lesson. In this game, the users will guess the word with which they are

given five chances to think of a letter that may be included in the spelling of the said word. The

"Trivia Game" is the title of the second game. It's just a simple true or false question with

interesting facts and trivias that will teach the users new information or even test their memory.

Last but not least, the "Tic-Tac-Toe," a two-player game that stimulates the users' critical thinking

ability and skill. It is similar to the traditional tic tac toe game. The game is played on a three-by-

three-square grid, with player one using X and player two using O. The winner is the first player

to get three of her marks in a row (up, down, across, or diagonally) and the game is over when all

nine squares are filled.

OBJECTIVE

Brain Drain is a game in which it will test the credibility of an individual to know

their own capacity to think. The goal of this project are as follows:

● To allow the users to discover and appreciate the power and value of technology.

and computer programming in the world today.

● To improve the functionality of one's wisdom or knowledge.

● To be used in order for the intellectual beings to think critically.

● To provide fun and entertainment to the users.


Republic of the Philippines
BATANGAS STATE UNIVERSITY
The National Engineering University
Alangilan Campus
Golden Country Homes, Alangilan Batangas City, Batangas, Philippines 4200
Tel Nos.: (+63 43) 425-0139 local 2121 / 2221
E-mail Address: [email protected] | Website Address: http://www.batstate-u.edu.ph

Department of Electronics Engineering

● To be a creative platform that can be used in different fields of education.

● To make learning an enjoyable way to acquire skills and form an emotional attachment to

learning and the subject matter.

● To create a relation and negative free environment for both users and programmers.

● To serve as an aid in advancing and enhancing the student’s level of understanding without

stressing.

METHODOLOGY

The input–process–output (IPO) model, or input-process-output pattern, is a widely used

approach in systems analysis and software engineering for describing the structure of an

information processing program or other process. Many introductory programming and systems

analysis texts introduce this as the most basic structure for describing a process.

The inputs represent the flow of data and materials into the process from the outside. The

processing step includes all tasks required to effect a transformation of the inputs. Outputs, on the

other hand, are the data and materials flowing out of the transformation process.(Schembri, 2012).

The table below shows the IPO model that must be followed by the program. For the first

part, ask the users for their respective names, and let them choose the game they want to play,

through the use of if elif else-statement(Input). Then, the user will play and answer as per

conditions given by the game he/she picked (Process). After that, the program will display if the

user has successfully won or lost the game (Output).

Leading Innovations, Transforming Lives, Building the Nation


Republic of the Philippines
BATANGAS STATE UNIVERSITY
The National Engineering University
Alangilan Campus
Golden Country Homes, Alangilan Batangas City, Batangas, Philippines 4200
Tel Nos.: (+63 43) 425-0139 local 2121 / 2221
E-mail Address: [email protected] | Website Address: http://www.batstate-u.edu.ph

Department of Electronics Engineering

Table 1

Input-Process-Output

Input Process Output

Name of the user - Identify the name of - Display the name

the player/user. of the user as a

greeting before

starting the game.

Game number - Show the game the - Options for the game

user picked. will be provided.

- If the user entered an

invalid response, the

game will not open.

a. Game 1 - Show the intro of the - Showing the the player

game that welcomes the instruction

him/her to that game. - Asking for the mystery

- The player has 5 word

chances to guess the - If the player got the

word. correct answer, a

greetings “You won!”

will show.

b. Game 2 - If the user input the - Showing the

right answer , it will instruction the game


Republic of the Philippines
BATANGAS STATE UNIVERSITY
The National Engineering University
Alangilan Campus
Golden Country Homes, Alangilan Batangas City, Batangas, Philippines 4200
Tel Nos.: (+63 43) 425-0139 local 2121 / 2221
E-mail Address: [email protected] | Website Address: http://www.batstate-u.edu.ph

Department of Electronics Engineering

greet you or wrong it consisted of 10 rounds

will move to the next and the questions were

question. The process answerable by true or

will repeat until the false .

last question of the

game.

c. Game 3 - Tic Tac Toe is a game - Shows a 9 by 9 board,

that consists of 2 this is where the

players. Every player players will put ‘X’ or

has time to mark “O” ‘O’ by just putting the

and the other one is number where they

“X”. want to be marked.

- The first who makes a

line will win the game.

Functions

Brain Drain is a program that is designed to give entertainment to its users. The following are the

functions used in the program as it provides three sets of games the user can choose to play.

1. main() - Main function to initiate the game.

Parameters:

Name Type Description

player_name str This is the displayed name

given by the programmer

Leading Innovations, Transforming Lives, Building the Nation


Republic of the Philippines
BATANGAS STATE UNIVERSITY
The National Engineering University
Alangilan Campus
Golden Country Homes, Alangilan Batangas City, Batangas, Philippines 4200
Tel Nos.: (+63 43) 425-0139 local 2121 / 2221
E-mail Address: [email protected] | Website Address: http://www.batstate-u.edu.ph

Department of Electronics Engineering

get_player_name str This is where the user will

input their name

Table (number). Parameters of main ()

2. get_player_name() - Function to get player’s name.

Parameters:

Name Type Description

name str This is where the user input

their name

alt_name str This is the displayed name

given by the programmer

answer str This is where the player or

user will confirm if his or

her name is given by the

programmer or not

Table (number). Parameters of get_player_name ()

3. intro() - Function to introduce and prompt game selection.

Parameters:

Name Type Description

print This is where the mechanics

or flow of the game is

displayed.

game_picked str It represents a variable or


Republic of the Philippines
BATANGAS STATE UNIVERSITY
The National Engineering University
Alangilan Campus
Golden Country Homes, Alangilan Batangas City, Batangas, Philippines 4200
Tel Nos.: (+63 43) 425-0139 local 2121 / 2221
E-mail Address: [email protected] | Website Address: http://www.batstate-u.edu.ph

Department of Electronics Engineering

attribute storing the name or

identifier of a game that has

been selected or picked.

This could be used to

determine which game-

related actions or content to

display or interact with.

Table (number). Parameters of intro ()

4. game_1() - Function for the hangman game.

Parameters:

Name Type Description

print This is where the mechanics

or flow of the game is

displayed.

word str This variable stores a string

data type in Python,

typically used to hold a

sequence of characters

representing text.

guesses int This variable stores an

integer data type in Python,

likely used to keep track of

the number of guesses made

Leading Innovations, Transforming Lives, Building the Nation


Republic of the Philippines
BATANGAS STATE UNIVERSITY
The National Engineering University
Alangilan Campus
Golden Country Homes, Alangilan Batangas City, Batangas, Philippines 4200
Tel Nos.: (+63 43) 425-0139 local 2121 / 2221
E-mail Address: [email protected] | Website Address: http://www.batstate-u.edu.ph

Department of Electronics Engineering

in a guessing game or a

similar application.

guess str This variable stores a string

data type in Python, often

used to hold user input

representing their guess in a

game or interactive

program.

turns int This variable stores an

integer data type in Python,

commonly used to track the

number of turns taken in a

game or loop iteration.

failed int This variable stores an

integer data type in Python,

frequently used to count the

number of failed attempts or

errors encountered in a

program.

next_move int This variable stores an

integer data type in Python,

possibly used to indicate the

next action or decision in a

game or algorithmic
Republic of the Philippines
BATANGAS STATE UNIVERSITY
The National Engineering University
Alangilan Campus
Golden Country Homes, Alangilan Batangas City, Batangas, Philippines 4200
Tel Nos.: (+63 43) 425-0139 local 2121 / 2221
E-mail Address: [email protected] | Website Address: http://www.batstate-u.edu.ph

Department of Electronics Engineering

process.

Table (number). Parameters of of game_1()

5. game_2() - Function for the Trivia game.

Parameters:

Name Type Description

print This is where the mechanics

or flow of the game is

displayed.

choice str This is where the game

consists of 10 questions that

have two choices, true or

false.

true str This is a string representing

true values. It can be “True,

T, and t”.

false str This is a string representing

true values. It can be “False,

F, and f”.

correct int This is stores the number of

the correct answered

question by the player in the

trivia game

Leading Innovations, Transforming Lives, Building the Nation


Republic of the Philippines
BATANGAS STATE UNIVERSITY
The National Engineering University
Alangilan Campus
Golden Country Homes, Alangilan Batangas City, Batangas, Philippines 4200
Tel Nos.: (+63 43) 425-0139 local 2121 / 2221
E-mail Address: [email protected] | Website Address: http://www.batstate-u.edu.ph

Department of Electronics Engineering

next_move int This variable stores an

integer data type in Python,

possibly used to indicate the

next action or decision

Table (number). Parameters of game_2()

6. game_3() - Function for the Tic-Tac-Toe game.

Parameters:

Name Type Description

print This is where the mechanics

or flow of the game is

displayed.

blankboard int This is A dictionary

representing the Tic-Tac-

Toe board with keys '1' to '9'

as the positions and initial

values as ' '.

board_keys str This is a list containing the

keys of the blankboard

dictionary.

Turn(X,O) str This is a variable

representing the current

player's symbol ('X' or 'O').


Republic of the Philippines
BATANGAS STATE UNIVERSITY
The National Engineering University
Alangilan Campus
Golden Country Homes, Alangilan Batangas City, Batangas, Philippines 4200
Tel Nos.: (+63 43) 425-0139 local 2121 / 2221
E-mail Address: [email protected] | Website Address: http://www.batstate-u.edu.ph

Department of Electronics Engineering

count int This is a variable to keep

track of the number of

moves made.

move str This is a variable showing

the available slot where the

player can make a move.

next_move int This variable stores an

integer data type in Python,

possibly used to indicate the

next action or decision

Table (number). Parameters of of game_3()

Leading Innovations, Transforming Lives, Building the Nation


Republic of the Philippines
BATANGAS STATE UNIVERSITY
The National Engineering University
Alangilan Campus
Golden Country Homes, Alangilan Batangas City, Batangas, Philippines 4200
Tel Nos.: (+63 43) 425-0139 local 2121 / 2221
E-mail Address: [email protected] | Website Address: http://www.batstate-u.edu.ph

Department of Electronics Engineering

PROJECT FEATURES

Below are the screenshots of the valid inputs and outputs that are acknowledged by the

program.

Figure 1A Character

As shown in Figure 1A, in the game environment of "BrainDrain," users are greeted with

a warm welcome message displayed through the `print()` function, inviting them to explore the

array of games prepared for their entertainment. Following the welcoming message, the code

prompts users to make a selection from the available games by inputting their desired choice. This

input is then stored in the `game_picked` variable, enabling subsequent processing to determine

the specific game to launch or to tailor the presentation of game content based on the user's

selection. This interaction mechanism provides users with an engaging entry point into the gaming

experience, facilitating their immersion and enjoyment within the "BrainDrain" universe.

Figure 2A Game Number

Figure 2A presents a conditional structure that executes different functions based on the

value of the variable game_picked. When game_picked is converted to uppercase, if it matches


Republic of the Philippines
BATANGAS STATE UNIVERSITY
The National Engineering University
Alangilan Campus
Golden Country Homes, Alangilan Batangas City, Batangas, Philippines 4200
Tel Nos.: (+63 43) 425-0139 local 2121 / 2221
E-mail Address: [email protected] | Website Address: http://www.batstate-u.edu.ph

Department of Electronics Engineering

"G1", the function game_1() is called; if it matches "G2", game_2() is executed; and if it matches

"G3", game_3() is invoked. If game_picked does not match any of these values, a message "Sorry,

it's either 'G1' or 'G2' or 'G3' as the answer. Goodbye!" is printed, indicating that the user provided

an invalid input. This code segment effectively controls the flow of the program, directing it to

different game functions depending on the user's choice or informing them of an incorrect input.

Figure 3A Hangman

Figure 3A is a Python code containing a simple text-based Hangman Game. The code

features the following function definitions: intro() – prints a welcome message and prompts the

player to select a game: Hangman, Trivia, or Tic-Tac-Toe; game_1() – actual Hangman game;

game_2() – actual Trivia game; game_3() – actual Tic-Tac-Toe game; get_player_name() – asks

the user to provide their name and offers to rename the player to Pretty. The word in game_1() to

be guessed is ‘python,’ and the player has five attempts to guess it. The player takes turns guessing

words by letter. If the player guessed a letter correctly, all its occurrences are revealed in the word.

Leading Innovations, Transforming Lives, Building the Nation


Republic of the Philippines
BATANGAS STATE UNIVERSITY
The National Engineering University
Alangilan Campus
Golden Country Homes, Alangilan Batangas City, Batangas, Philippines 4200
Tel Nos.: (+63 43) 425-0139 local 2121 / 2221
E-mail Address: [email protected] | Website Address: http://www.batstate-u.edu.ph

Department of Electronics Engineering

If he guessed wrong, the player lost an attempt. The game pranks the player until he guesses the

word or runs out of attempts.

Figure 4A Trivia Game

Figure 4A provided Python code outlines a straightforward text-based Trivia Game with several

key features. It starts by warmly welcoming players and providing clear instructions on how to

engage with the game. Through a series of ten true or false questions, players are prompted to input

their answers, with the code ensuring input validation for accuracy. Correct answers are rewarded

with points, and immediate feedback is provided after each response, enhancing the interactive

experience. At the game's conclusion, the total number of correct answers out of ten is displayed,

giving players a sense of accomplishment. They're then offered choices for the next action, whether

it's to replay the trivia game, explore other games, or exit. The game loop ensures smooth

progression through questions, maintaining engagement until completion. With its modular design

and seamless integration into the main menu, the trivia game offers both structure and flexibility,

contributing to an enjoyable and immersive gaming experience.


Republic of the Philippines
BATANGAS STATE UNIVERSITY
The National Engineering University
Alangilan Campus
Golden Country Homes, Alangilan Batangas City, Batangas, Philippines 4200
Tel Nos.: (+63 43) 425-0139 local 2121 / 2221
E-mail Address: [email protected] | Website Address: http://www.batstate-u.edu.ph

Department of Electronics Engineering

Figure 5A Tic-Tac-toe

Leading Innovations, Transforming Lives, Building the Nation


Republic of the Philippines
BATANGAS STATE UNIVERSITY
The National Engineering University
Alangilan Campus
Golden Country Homes, Alangilan Batangas City, Batangas, Philippines 4200
Tel Nos.: (+63 43) 425-0139 local 2121 / 2221
E-mail Address: [email protected] | Website Address: http://www.batstate-u.edu.ph

Department of Electronics Engineering

Figure 5A shows a comprehensive overview of the Tic Tac Toe game code, highlighting its

various features and functionalities. The game begins with a welcoming message and clear

instructions on how to play, ensuring that players understand the objectives and rules. It then

initializes a blank 3x3 grid where players take turns marking spaces with their symbols. The code

includes validations to ensure moves are valid and checks for winning conditions after each turn.

Additionally, it provides options for players at the end of the game, allowing them to retry the

same game, start a new one, or exit. The recursive functionality enables continuous gameplay

without restarting the program, seamlessly integrating with the main menu for a unified gaming

experience. Overall, the code facilitates user interaction at various stages, ensuring an engaging

and enjoyable gameplay experience.

Figure 6B Number

Figure 6B shows that users are presented with a prompt asking them what they would like

to do next after engaging with the game. They are given three options: to try again, to play another

game, or to indicate that they are finished playing. Users are then instructed to input their choice,

selecting either option 1, 2, or 3. Once their choice is registered, a message of gratitude is

displayed, thanking them for their participation in the game. This interaction structure not only

provides users with a clear pathway to continue or conclude their gaming experience but also

expresses appreciation for their engagement, fostering a positive connection between the player

and the game environment.


Republic of the Philippines
BATANGAS STATE UNIVERSITY
The National Engineering University
Alangilan Campus
Golden Country Homes, Alangilan Batangas City, Batangas, Philippines 4200
Tel Nos.: (+63 43) 425-0139 local 2121 / 2221
E-mail Address: [email protected] | Website Address: http://www.batstate-u.edu.ph

Department of Electronics Engineering

Source Code

def intro(): turns = 5

print("")

print("\t\t\t\t Hello! Welcome to BRAIN DRAIN!") while turns > 0:

print("\t\t\t\t We prepared some games for you!") failed = 0

print("Game 1 - Hangman \nGame 2 - Trivia Questions for char in word:

\nGame 3 - Tic-Tac-Toe") if char in guesses:

game_picked = input("What game would you like to play? print(char, end=' ')

[G1/G2/G3] > ") else:

print("_", end=' ')

# Pick a game and we will play that game failed += 1

if game_picked.upper() == "G1": if failed == 0:

game_1() print("\nYou won!")

elif game_picked.upper() == "G2": next_move = input("What do you want to do next?\n

game_2() 1. I want to try again.\n 2. I want to play another game. \n 3.

elif game_picked.upper() == "G3": I'm done playing. (1/2/3)\n> ")

game_3() if "1" in next_move:

else: game_1()

print("Sorry, it's either 'G1' or 'G2' or 'G3' as the answer. elif "2" in next_move:

Goodbye!") intro()

else:

def game_1(): print("\n Okay then, thank you for playing with

print("") us!")

print("\t\t\t\t\tWelcome to Hangman!") break

print("This is a guessing game where you suggest a letter

until you guess the correct word.") guess = input("\nGuess a character: ")

print("You only have five tries! Use lowercase letters guesses += guess

only.") if guess not in word:

print("") turns -= 1

print("Are you ready? Okay, here's the mystery word!") print("Wrong!")

print("You have", turns, "more guesses")

word = "python" if turns == 0:

guesses = '' print("You Lose")

Leading Innovations, Transforming Lives, Building the Nation


Republic of the Philippines
BATANGAS STATE UNIVERSITY
The National Engineering University
Alangilan Campus
Golden Country Homes, Alangilan Batangas City, Batangas, Philippines 4200
Tel Nos.: (+63 43) 425-0139 local 2121 / 2221
E-mail Address: [email protected] | Website Address: http://www.batstate-u.edu.ph

Department of Electronics Engineering

next_move = input("What do you want to do "Dictionary data type is used to store a collection of

next?\n 1. I want to try again.\n 2. I want to play another different data types of elements in the form of key-value

game. \n 3. I'm done playing. (1/2/3)\n> ") pairs; it is mutable and stores the unique key.",

if "1" in next_move: "Complex number is a number with two distinct

game_1() components: a real part and an imaginary part.",

elif "2" in next_move: "Tuple is used to stores a collection of different data

intro() types of elements, and it is mutable.",

else: "String is used to stores a collection of different data

print("\n Okay then, thank you for playing with types of elements, and it is immutable.",

us!") "User-Defined Data Types is the data types, which can

be created by the programmer itself are called User-defined

def game_2(): data types.",

print("") "Complex number is a number with three distinct

print("Welcome to the Trivia Game!") components.",

print("This game consists of 10 rounds. The following "Robot is a machine resembling a human being and able

trivia is answerable only by True or False.") to replicate certain human movements and functions

print("Okay, let's get started. Good luck!") automatically"

true = ["T", "t", "True"] ]

false = ["F", "f", "False"]

correct = 0 answers = [True, False, False, True, True, False, False,

incorrect_attempts = 0 True, False, True]

questions = [ for i in range(10):

"An integrated development environment is a software while True: # Loop until the player gives a valid

application that provides comprehensive facilities for answer

software development.", print("\n" + questions[i])

"OnlineGDB.com is a dedicated Python Integrated choice = input(">>> ")

Development Environment (IDE) providing a wide range of if (choice.upper() in true and answers[i]) or

essential tools for Python developers, tightly integrated to (choice.upper() in false and not answers[i]):

create a convenient environment for productive Python, correct += 1

web, and data science development.", print("You got it right!")

"Python is not interpreted, object-oriented, high-level break # Break out of the loop if the answer is

programming language with dynamic semantics.", correct

else:

print("You got it wrong, try again!")


Republic of the Philippines
BATANGAS STATE UNIVERSITY
The National Engineering University
Alangilan Campus
Golden Country Homes, Alangilan Batangas City, Batangas, Philippines 4200
Tel Nos.: (+63 43) 425-0139 local 2121 / 2221
E-mail Address: [email protected] | Website Address: http://www.batstate-u.edu.ph

Department of Electronics Engineering

incorrect_attempts += 1 print("Use numbers 1-9 to mark your turn. The first to get

their symbol three times in a row wins!")

print("\nCongratulations! You got", correct, "out of 10 print("Are you ready? Let's go!\n")

correct.")

print("You made", incorrect_attempts, "incorrect # Initialize the blank board

attempts.") blankboard = {

'1': ' ', '2': ' ', '3': ' ',

# Display correct answers '4': ' ', '5': ' ', '6': ' ',

print("\nCorrect answers:") '7': ' ', '8': ' ', '9': ' ',

for i in range(10): }

print(f"{i+1}. {questions[i]} - {'True' if answers[i] else

'False'}") # Board keys for reference

board_keys = list(blankboard.keys())

next_move = input("What do you want to do next?\n 1. I

want to try again.\n 2. I want to play another game. \n 3. I'm # Function to print the board

done playing. (1/2/3)\n> ") def printBoard(board):

if "1" in next_move: print(board['1'] + '|' + board['2'] + '|' + board['3'])

game_2() print('-+-+-')

elif "2" in next_move: print(board['4'] + '|' + board['5'] + '|' + board['6'])

intro() print('-+-+-')

else: print(board['7'] + '|' + board['8'] + '|' + board['9'])

print("\nOkay then, thank you for playing with us!")

# Initialize variables for the game

# The Tic-Tac-Toe game turn = 'X'

def game_3(): count = 0

# Introduction to the Tic-Tac-Toe game

print("\n\t\t\t\t\tWelcome to the Tic-Tac-Toe Game!") # Main game loop

print("Tic Tac Toe is a two-player game where the first for i in range(10):

player is represented by the letter 'X'") printBoard(blankboard)

print("while the second player represents the symbol '0'. print("It's your turn, " + turn + ". Move to which

The board is numbered as:") place?")

print("\t\t1 | 2 | 3") move = input(">")

print("\t\t4 | 5 | 6")

print("\t\t7 | 8 | 9") # Check if the move is valid and update the board

if blankboard[move] == ' ':

Leading Innovations, Transforming Lives, Building the Nation


Republic of the Philippines
BATANGAS STATE UNIVERSITY
The National Engineering University
Alangilan Campus
Golden Country Homes, Alangilan Batangas City, Batangas, Philippines 4200
Tel Nos.: (+63 43) 425-0139 local 2121 / 2221
E-mail Address: [email protected] | Website Address: http://www.batstate-u.edu.ph

Department of Electronics Engineering

blankboard[move] = turn # Switch player turn

count += 1 if turn == 'X':

else: turn = 'O'

print("That place is already filled. Move to which else:

place?") turn = 'X'

continue

# Prompt for next action

# Check for win or tie conditions next_move = input("What do you want to do next?\n 1. I

if count >= 5: want to try again.\n 2. I want to play another game. \n 3. I'm

if (blankboard['1'] == blankboard['2'] == done playing. (1/2/3)\n> ")

blankboard['3'] != ' ' or

blankboard['4'] == blankboard['5'] == # Process next action

blankboard['6'] != ' ' or if "1" in next_move:

blankboard['7'] == blankboard['8'] == game_3()

blankboard['9'] != ' ' or elif "2" in next_move:

blankboard['1'] == blankboard['4'] == intro()

blankboard['7'] != ' ' or else:

blankboard['2'] == blankboard['5'] == print("\nOkay then, thank you for playing with us!")

blankboard['8'] != ' ' or

blankboard['3'] == blankboard['6'] == # Function to get player's name

blankboard['9'] != ' ' or def get_player_name():

blankboard['7'] == blankboard['5'] == name = input("What's your name? ")

blankboard['3'] != ' ' or

blankboard['1'] == blankboard['5'] == # Offer an alternative name with confirmation

blankboard['9'] != ' '): alt_name = "Pretty"

printBoard(blankboard) answer = input(f"Your name is {alt_name.upper()}, is that

print("\nGame Over.\n") correct? [Y|N] > ")

print(turn + " won. Congratulations!")

break if answer.lower() in ["y", "yes"]:

name = alt_name

if count == 9: print(f"You are fun, {name.upper()}! Let's begin our

print("\nGame Over.\n") game!")

print("It's a Tie!!") elif answer.lower() in ["n", "no"]:

break print(f"Ok, picky. {name.upper()} it is. Let's get started

on our game.")
Republic of the Philippines
BATANGAS STATE UNIVERSITY
The National Engineering University
Alangilan Campus
Golden Country Homes, Alangilan Batangas City, Batangas, Philippines 4200
Tel Nos.: (+63 43) 425-0139 local 2121 / 2221
E-mail Address: [email protected] | Website Address: http://www.batstate-u.edu.ph

Department of Electronics Engineering

else: # Main function to start the game

print(f"Trying to be funny? Well, you will now be def main():

called {alt_name.upper()} anyway.") player_name = get_player_name()

name = alt_name intro()

return name if __name__ == '__main__':

main()

Leading Innovations, Transforming Lives, Building the Nation


Republic of the Philippines
BATANGAS STATE UNIVERSITY
The National Engineering University
Alangilan Campus
Golden Country Homes, Alangilan Batangas City, Batangas, Philippines 4200
Tel Nos.: (+63 43) 425-0139 local 2121 / 2221
E-mail Address: [email protected] | Website Address: http://www.batstate-u.edu.ph

Department of Electronics Engineering

PROJECT TEAM RESPONSIBILITY

NAME OF MEMBERS TASK AND RESPONSIBILITIES

ACAR, ZAIRA KAE L. Methodology, Functions, Project Features,

Programmer

PEREZ, ARIAN JOY C. Leader, Overview, Objective, Methodology, Project

Features (Screenshot), Programmer

UNTALAN, JOHN PRINCELEE C. Methodology, Project Features (Screenshot),

Function, Programmer

You might also like