From 96fbc59f8a4effa1c177dc7bfb64fc737e98358f Mon Sep 17 00:00:00 2001
From: Antti Niemi <antjni@utu.fi>
Date: Tue, 14 May 2024 04:06:58 +0300
Subject: [PATCH] Kommentoinnit

---
 Games/Gamefiles/2048loadgame.txt |  8 ++++----
 Games/Snake.py                   | 19 ++++++++++++-------
 main.py                          | 12 +++++++++++-
 3 files changed, 27 insertions(+), 12 deletions(-)

diff --git a/Games/Gamefiles/2048loadgame.txt b/Games/Gamefiles/2048loadgame.txt
index a6e83db..6cbf70d 100644
--- a/Games/Gamefiles/2048loadgame.txt
+++ b/Games/Gamefiles/2048loadgame.txt
@@ -1,4 +1,4 @@
-0 0 0 0
-0 2 0 0
-0 0 0 0
-0 2 0 0
+2 16 2 0
+128 16 0 0
+4 8 32 0
+4 64 0 0
diff --git a/Games/Snake.py b/Games/Snake.py
index c86aedf..7a773bd 100644
--- a/Games/Snake.py
+++ b/Games/Snake.py
@@ -1,6 +1,8 @@
 import pygame
 import random
 from pygame.math import Vector2
+
+#Kaikki käärmeeseen liittyvä
 class SNAKE:
     def __init__(self):
         self.body = [Vector2(10, 10),Vector2(9, 10), Vector2(8, 10)]
@@ -18,17 +20,19 @@ class SNAKE:
             else:
                 pygame.draw.rect(screen,"purple", block_rect)
 
+    #Liikuttaa käärmettä
     def move_snake(self):
         body_copy = self.body[:-1]
         new_head = body_copy[0]+self.direction
         body_copy.insert(0,body_copy[0]+ self.direction)
         self.body = body_copy[:]
 
-
+#Braumin pää
 class FRUIT:
     def __init__(self):
         self.respawn()
 
+    #Tekee uuden "hedelmän"
     def respawn(self):
         self.x = random.randint(0, pixel_number - 1)
         self.y = random.randint(0, pixel_number - 1)
@@ -45,7 +49,7 @@ class MAIN:
         self.snake = SNAKE()
         self.fruit = FRUIT()
 
-
+    #Game over screen
     def game_over(self, score):
         screen.fill("black")
         game_over = pygame.font.SysFont(f"Helvetica", 60).render("You lose!", True, (200, 0 ,0))
@@ -78,7 +82,7 @@ class MAIN:
                     with open("Games/Gamefiles/Snake_highscore.txt", "w") as file:
                         file.write(str(score))
   
-  
+    #Biisin looppaus
     def music(self):
         biisi.play(-1, 0)
 
@@ -113,27 +117,28 @@ while running:
     snake = SNAKE()
     fruit = FRUIT()
     while game_on:
+        #Hedelmän syönti
         if snake.body[0] == fruit.pos:
             fruit.respawn()
             snake.body.append(fruit.pos)
-
+        # Snaken sisällä
         for segment in snake.body[1:]:
             if snake.body[0] == segment:
                 print("You lose 3!")
                 main.save_score(len(snake.body))
                 game_on = False
-
+        #Ettei hedelmä spawnaa käärmeen sisään
         for segment in snake.body[1:-1]:
             if fruit.pos == segment:
                 fruit.respawn()
                 print("now")
-
+        #Seinää päin
         if snake.body[0].x < 0 or snake.body[0].x > 19:
             print("You lose 1")
             main.save_score(len(snake.body))
             game_on = False
 
-
+        #
         if snake.body[0].y < 0 or snake.body[0].y > 19:
             print("You lose 2")
             main.save_score(len(snake.body))
diff --git a/main.py b/main.py
index 75620c1..a480d7e 100644
--- a/main.py
+++ b/main.py
@@ -7,6 +7,8 @@ class App(tk.Frame):
         self.master = master
         self.Hub()
 
+    #Luo aloitusruudun 
+
     def Hub(self):
         self.bg = tk.PhotoImage(file='Photos/Menu2.png')
         label1 = tk.Label(root, image=self.bg) 
@@ -22,18 +24,21 @@ class App(tk.Frame):
         self.bj_button = tk.Button(text="Blackjack", command=self.BJ, bg='pink', font=("Times new roman", 50), width = 8)
         self.bj_button.place(relx=0.8, rely=0.5, anchor="center")
 
+    #Tuhoaa kaikki widgetit
     def destroy_all(self):
         for widget in root.winfo_children():
             widget.destroy()
-    
+   
     def Menu(self):
         self.destroy_all()
         self.Hub()
 
+    #Luo Menu nappulan
     def game_menu(self):
         self.menu_button = tk.Button(text="Menu", command=self.Menu, bg='teal', font=("Times new roman", 50))
         self.menu_button.place(relx=1.0, rely=0.0, anchor="ne")
     
+    #Luo Snake pelin valikko ruudun
     def snake(self):
         self.destroy_all()
         self.bg = tk.PhotoImage(file='Photos/snake.png')
@@ -48,6 +53,7 @@ class App(tk.Frame):
         self.rules_button.place(relx=0.7, rely=0.7, anchor="center")
         self.game_menu()
 
+    #Luo 2048 pelin valikko ruudun
     def peli(self):
         self.destroy_all()
         self.bg = tk.PhotoImage(file='Photos/2048.png')
@@ -64,6 +70,7 @@ class App(tk.Frame):
         self.rules_button.place(relx=0.7, rely=0.85, anchor="center")
         self.game_menu()
     
+    #Luo Blackjack pelin valikko ruudun
     def BJ(self):
         self.destroy_all()
         self.bg = tk.PhotoImage(file='Photos/Blackjack.png')
@@ -84,15 +91,18 @@ class App(tk.Frame):
         self.menu_button.place(relx=1.0, rely=0.0, anchor="ne")
         self.open_file("Rules/" + game_name +"_rules.txt")
 
+    #Avaa tekstitiedoston jossa on pelien säännöt
     def open_file(self, text_file):
         with open (text_file) as f:
             content = f.read()
             lab= tk.Label(root,text=str(content).encode("latin-1").decode("utf-8"), font= ('arial 20'), fg = "white", bg = "green")
             lab.place(relx=0.5, rely=0.5, anchor="center")
 
+    #Avaa pelit
     def open_game(self, game_file):
         call(["python", "Games/" + game_file +".py"])
     
+      
     def new_2048_game(self):
         with open("Games/Gamefiles/2048havewon.txt", "w") as file:
                         file.write(str("2"))
-- 
GitLab