Skip to content

Commit

Permalink
rename files
Browse files Browse the repository at this point in the history
  • Loading branch information
sera619 committed Nov 26, 2022
1 parent 2563e05 commit 469eb20
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 141 deletions.
137 changes: 0 additions & 137 deletions game_layout.kv

This file was deleted.

151 changes: 151 additions & 0 deletions main.kv
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@


# create a base Layout
MDScreen:
MDFloatLayout:
# MDTopAppBar:
# title: "App bar"
# create a header text

MDLabel:
id: header
font_size: "20sp"
color: "yellow"
text: "Tic Tac Toe"
halign: "center"
pos_hint: {"center_y": .95 }

MDLabel:
id: copyright
font_size: "14sp"
color: "yellow"
text: "2022 © by S3R43o3"
halign: "center"
pos_hint: {"center_y": .9 }

# create the gamefield
MDGridLayout:
id: gameField
size_hint: .75,.5
pos_hint: {'center_x': .5, 'center_y': .6}
cols: 3
rows: 3
opacity: 1

#create the buttons for X or O
Button:
id: btn1
text:''
font_size: "45sp"
background_color: "green"
on_release: app.presser(btn1)
elevation: 6

Button:
id: btn2
text:''
font_size: "45sp"
background_color: "green"
on_release: app.presser(btn2)
elevation: 6

Button:
id: btn3
text:''
font_size: "45sp"
background_color: "green"
on_release: app.presser(btn3)
elevation: 6

Button:
id: btn4
text:''
font_size: "45sp"
on_release: app.presser(btn4)
background_color: "green"
elevation: 6

Button:
id: btn5
text:''
font_size: "45sp"
on_release: app.presser(btn5)
background_color: "green"
elevation: 6

Button:
id: btn6
text:''
font_size: "45sp"
on_release: app.presser(btn6)
background_color: "green"
elevation: 6

Button:
id: btn7
text:''
font_size: "45sp"
on_release: app.presser(btn7)
background_color: "green"
elevation: 6

Button:
id: btn8
text:''
font_size: "45sp"
on_release: app.presser(btn8)
background_color: "green"
elevation: 6

Button:
id: btn9
text:''
font_size: "45sp"
on_release: app.presser(btn9)
background_color: "green"
elevation: 6

# create the score label
MDLabel:
id: score
font_size: "18sp"
text: "X goes first!"
halign: "center"
pos_hint: {"center_y": .25 }

MDBoxLayout:
orientation: 'horizontal'
adaptive_size: True
spacing: '3sp'
padding: ('3sp', '3sp', '3sp', '3sp')
pos_hint: {"center_x": .5}
MDRaisedButton:
id: restart
font_size: "12sp"
text: "Restart Game"
on_release: app.restart()

MDRaisedButton:
id: resetScore
font_size: "12sp"
text: "Reset Score"
#pos_hint: {'center_x': .65, 'center_y': .15}
on_release: app.reset_score()

MDRaisedButton:
id: exit
font_size: "12sp"
text: "Exit Game"
#pos_hint: {'center_x': .65, 'center_y': .15}
on_release: app.exit_game()

MDLabel:
id: game
font_size: "16sp"
color: "grey"
text: "X-Wins: 0 | O-Wins: 0"
halign: "center"
pos_hint: {"center_x": .5, "center_y": .325 }



15 changes: 11 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@
# make sure you run "pip install kivymd" before run the main.py file
# feel free to edit
# greetings S3R43o3 © 2022
import kivy
kivy.require("2.2.0")
from kivy.lang import Builder
from kivy.factory import Factory
from kivymd.app import MDApp
from kivy.utils import platform
from kivy.core.window import Window

defaultScreen = "main.kv"

class GameApp(MDApp):
def build(self):
# build the basic app and set colorthemes
self.defaultScreen = "game_layout.kv"
self.title = "Tic Tac Toe"
self.theme_cls.theme_style = "Dark"
self.theme_cls.primary_palette = "Orange"
return Builder.load_file(self.defaultScreen)
return Builder.load_file(defaultScreen)


# define whos turn it is
turn = "X"
# track win or lose
Expand Down Expand Up @@ -170,10 +171,16 @@ def end_game(self, a, b, c):
a.color = "green"
b.color = "green"
c.color = "green"
a.elevation = 6
b.elevation = 6
c.elevation = 6
c.background_color = "yellow"
a.background_color = "yellow"
b.background_color = "yellow"
self.winner = True
self.disable_all_buttons()
self.root.ids.score.color = "green"
self.root.ids.score.text = f"{a.text} Wins!"
self.root.ids.score.text = f"{a.text} Wins!\nClick 'Restart Game' to start a new round."

if (a.text == "X"):
self.X_win += 1
Expand Down

0 comments on commit 469eb20

Please sign in to comment.