diff --git a/Node.gd b/Node.gd new file mode 100644 index 0000000..a32e0b8 --- /dev/null +++ b/Node.gd @@ -0,0 +1,271 @@ +extends Node + +@export var piesa_neagra_scene: PackedScene +@export var piesa_alba_scene: PackedScene +@export var cadran_negru_scene: PackedScene + + +var player : int +var pasi : int +var piesa : int +var board_size : int +var cell_size : int +var grid_pos : Vector2i +var grid_data : Array # matrice 8 pe 8 +var start_pos : Vector2i # retine primul click dat / piesa pe care se doreste a muta +var start_piesa : int +var temp_marker + +# Called when the node enters the scene tree for the first time. +func _ready(): + board_size = 788 + # imparte board_size la 8 pentru a obtine dimensiunea fiecarei celule + cell_size = board_size / 8 + new_game() + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + pass + +func _input(event): + + if event is InputEventMouseButton : + if event.button_index == MOUSE_BUTTON_LEFT and event.pressed : + #verifica daca mouse-ul e pe tabla de joc + if event.position.x < board_size: + #convertire pozitie mouse in locatie grid + grid_pos = Vector2i(event.position / cell_size) # grid_pos memoreza [coloana, linie] + + if player == 1 : + if grid_data[grid_pos.y][grid_pos.x][0] == 1 and pasi == 1 : + start_piesa = grid_data[grid_pos.y][grid_pos.x][0] + start_pos = grid_pos + print("player", player, "a apasat pe chenarul ", grid_pos ) + print("a fost selectata piesa ", start_piesa) + pasi = 2 + # cmiscare pe diagonala un patratel piesa neagra + + elif grid_pos.x == start_pos.x + 2 and grid_pos.y == start_pos.y + 2 : capturare_diagonala_jos_negru() + elif grid_pos.x == start_pos.x + 2 and grid_pos.y == start_pos.y - 2 : capturare_diagonala_sus_negru() + else : deplasare_diagonala_negru() + + elif player == -1 : + if grid_data[grid_pos.y][grid_pos.x][0] < 0 and pasi == 1 : + start_piesa = grid_data[grid_pos.y][grid_pos.x][0] + start_pos = grid_pos + print("player ", player, " a apasat pe chenarul ", grid_pos ) + print("a fost selectata piesa ", start_piesa) + pasi = 2 + elif grid_pos.x == start_pos.x - 2 and grid_pos.y == start_pos.y - 2 : capturare_diagonala_jos_alb() + elif grid_pos.x == start_pos.x - 2 and grid_pos.y == start_pos.y + 2 : capturare_diagonala_sus_alb() + else : deplasare_diagonala_alb() + #capturare piesa de catre pion negru pe diagonala + elif grid_pos != start_pos and grid_data[grid_pos.y][grid_pos.x][0] >= 0 : + if grid_pos.x == start_pos.x - 1 and grid_pos.y == start_pos.y + 1 or grid_pos.x == start_pos.x - 1 and grid_pos.y == start_pos.y - 1 : + if pasi == 2: + print("trece de primul if") + #marcare noua pozitie a piesei + grid_data[grid_pos.y][grid_pos.x][0] = start_piesa + create_marker(-1, grid_pos * cell_size + Vector2i(cell_size /2, cell_size /2 + 5 )) + #demarcare vechea pozitie a piesei + create_marker(grid_data[start_pos.y][start_pos.x][1], start_pos * cell_size + Vector2i(cell_size /2, cell_size /2) ) + grid_data[start_pos.y][start_pos.x][0] = 0 + print(grid_pos) + print(grid_data) + pasi = 1 + player = 1 + + + + + +func new_game(): + player = 1 + # [5,1] a doua valoare marcheaza culoarea chenarului tablei de joc, 7 = negru, 8 = alb + grid_data = [ + [[1,7], [0,8], [0,7], [0,8], [0,7], [0,8], [-1,7], [0,8]], + [[0,8], [1,7], [0,8], [0,7], [0,8], [0,7], [0,8], [-1,7]], + [[1,7], [0,8], [0,7], [0,8], [0,7], [0,8], [-1,7], [0,8]], + [[0,8], [1,7], [0,8], [0,7], [0,8], [0,7], [0,8], [-1,7]], + [[1,7], [0,8], [0,7], [0,8], [0,7], [0,8], [-1,7], [0,8]], + [[0,8], [1,7], [0,8], [0,7], [0,8], [0,7], [0,8], [-1,7]], + [[1,7], [0,8], [0,7], [0,8], [0,7], [0,8], [-1,7], [0,8]], + [[0,8], [1,7], [0,8], [0,7], [0,8], [0,7], [0,8], [-1,7]] + ] + pasi = 1 + #punerea pieselor negre (player1) + create_marker(1, Vector2i(0,0) * cell_size + Vector2i(cell_size /2, cell_size /2)) + create_marker(1, Vector2i(0,2) * cell_size + Vector2i(cell_size /2, cell_size /2)) + create_marker(1, Vector2i(0,4) * cell_size + Vector2i(cell_size /2, cell_size /2)) + create_marker(1, Vector2i(0,6) * cell_size + Vector2i(cell_size /2, cell_size /2)) + create_marker(1, Vector2i(1,1) * cell_size + Vector2i(cell_size /2, cell_size /2)) + create_marker(1, Vector2i(1,3) * cell_size + Vector2i(cell_size /2, cell_size /2)) + create_marker(1, Vector2i(1,5) * cell_size + Vector2i(cell_size /2, cell_size /2)) + create_marker(1, Vector2i(1,7) * cell_size + Vector2i(cell_size /2, cell_size /2)) + + #punerea pieselor albe(player2) + create_marker(-1, Vector2i(6,0) * cell_size + Vector2i(cell_size /2, cell_size /2)) + create_marker(-1, Vector2i(6,2) * cell_size + Vector2i(cell_size /2, cell_size /2)) + create_marker(-1, Vector2i(6,4) * cell_size + Vector2i(cell_size /2, cell_size /2)) + create_marker(-1, Vector2i(6,6) * cell_size + Vector2i(cell_size /2, cell_size /2)) + create_marker(-1, Vector2i(7,1) * cell_size + Vector2i(cell_size /2, cell_size /2)) + create_marker(-1, Vector2i(7,3) * cell_size + Vector2i(cell_size /2, cell_size /2)) + create_marker(-1, Vector2i(7,5) * cell_size + Vector2i(cell_size /2, cell_size /2)) + create_marker(-1, Vector2i(7,7) * cell_size + Vector2i(cell_size /2, cell_size /2)) +func create_marker(piesa, position) : + #creaza un marcker node si il adauga ca un child + if piesa==1: + var piesa_neagra = piesa_neagra_scene.instantiate() + piesa_neagra.position=position + add_child(piesa_neagra) + if piesa==-1: + var piesa_alba=piesa_alba_scene.instantiate() + piesa_alba.position=position + add_child(piesa_alba) + + if piesa == 7: + var cadran_negru = cadran_negru_scene.instantiate() + cadran_negru.position = position + add_child(cadran_negru) + +func deplasare_diagonala_negru(): + if grid_pos != start_pos and grid_data[grid_pos.y][grid_pos.x][0] == 0 : + if grid_pos.x == start_pos.x + 1 and grid_pos.y == start_pos.y + 1 or grid_pos.x == start_pos.x + 1 and grid_pos.y == start_pos.y - 1 : + if pasi == 2: + print("trece de primul if") + #marcare noua pozitie a piesei + grid_data[grid_pos.y][grid_pos.x][0] = start_piesa + create_marker(1, grid_pos * cell_size + Vector2i(cell_size /2, cell_size /2 + 5 )) + #demarcare vechea pozitie a piesei + create_marker(grid_data[start_pos.y][start_pos.x][1], start_pos * cell_size + Vector2i(cell_size /2, cell_size /2) ) + grid_data[start_pos.y][start_pos.x][0] = 0 + print(grid_pos) + print(grid_data) + pasi = 1 + player = -1 + +func capturare_diagonala_jos_negru(): + print("punct control1") + if grid_pos != start_pos and grid_data[grid_pos.y][grid_pos.x][0] == 0 : + print("punct control 2") + if grid_pos.x == start_pos.x + 2 and grid_pos.y == start_pos.y + 2 : + print("punct control 3") + print(start_pos.x + 1, start_pos.y + 1) + if grid_data[start_pos.y + 1][start_pos.x + 1][0] <= 0 : + print("punct control 4") + if pasi == 2: + print("trece de primul if") + #marcare noua pozitie a piesei + grid_data[grid_pos.y][grid_pos.x][0] = start_piesa + create_marker(1, grid_pos * cell_size + Vector2i(cell_size /2, cell_size /2 + 5 )) + #demarcare vechea pozitie a piesei + create_marker(grid_data[start_pos.y][start_pos.x][1], start_pos * cell_size + Vector2i(cell_size /2, cell_size /2) ) + grid_data[start_pos.y][start_pos.x][0] = 0 + #demarcare piesa capturata + start_pos.x +=1 + start_pos.y +=1 + create_marker(7, start_pos * cell_size + Vector2i(cell_size /2, cell_size /2) ) + grid_data[start_pos.y + 1][start_pos.x + 1][0] = 0 + print(grid_pos) + print(grid_data) + pasi = 1 + player = -1 + +func capturare_diagonala_sus_negru(): + print("punct control1") + if grid_pos != start_pos and grid_data[grid_pos.y][grid_pos.x][0] == 0 : + print("punct control 2") + if grid_pos.x == start_pos.x + 2 and grid_pos.y == start_pos.y - 2 : + print("punct control 3") + print(start_pos.x + 1, start_pos.y - 1) + if grid_data[start_pos.y - 1][start_pos.x + 1][0] <= 0 : + print("punct control 4") + if pasi == 2: + print("trece de primul if") + #marcare noua pozitie a piesei + grid_data[grid_pos.y][grid_pos.x][0] = start_piesa + create_marker(1, grid_pos * cell_size + Vector2i(cell_size /2, cell_size /2 + 5 )) + #demarcare vechea pozitie a piesei + create_marker(grid_data[start_pos.y][start_pos.x][1], start_pos * cell_size + Vector2i(cell_size /2, cell_size /2) ) + grid_data[start_pos.y][start_pos.x][0] = 0 + #demarcare piesa capturata + start_pos.x +=1 + start_pos.y -=1 + create_marker(7, start_pos * cell_size + Vector2i(cell_size /2, cell_size /2) ) + grid_data[start_pos.y -1 ][start_pos.x + 1][0] = 0 + print(grid_pos) + print(grid_data) + pasi = 1 + player = -1 + +func capturare_diagonala_sus_alb(): + print("punct control1") + if grid_pos != start_pos and grid_data[grid_pos.y][grid_pos.x][0] == 0 : + print("punct control 2") + if grid_pos.x == start_pos.x - 2 and grid_pos.y == start_pos.y + 2 : + print("punct control 3") + print(start_pos.x - 1, start_pos.y + 1) + if grid_data[start_pos.y + 1][start_pos.x - 1][0] > 0 : + print("punct control 4") + if pasi == 2: + print("trece de primul if") + #marcare noua pozitie a piesei + grid_data[grid_pos.y][grid_pos.x][0] = start_piesa + create_marker(-1, grid_pos * cell_size + Vector2i(cell_size /2, cell_size /2 + 5 )) + #demarcare vechea pozitie a piesei + create_marker(grid_data[start_pos.y][start_pos.x][1], start_pos * cell_size + Vector2i(cell_size /2, cell_size /2) ) + grid_data[start_pos.y][start_pos.x][0] = 0 + #demarcare piesa capturata + start_pos.x -=1 + start_pos.y +=1 + create_marker(7, start_pos * cell_size + Vector2i(cell_size /2, cell_size /2) ) + grid_data[start_pos.y + 1][start_pos.x - 1][0] = 0 + print(grid_pos) + print(grid_data) + pasi = 1 + player = 1 + +func capturare_diagonala_jos_alb(): + print("punct control1") + print(grid_data[grid_pos.y][grid_pos.x][0]) + if grid_pos != start_pos and grid_data[grid_pos.y][grid_pos.x][0] == 0 : + print("punct control 2") + if grid_pos.x == start_pos.x - 2 and grid_pos.y == start_pos.y - 2 : + print("punct control 3") + print(start_pos.x - 1, start_pos.y - 1) + if grid_data[start_pos.y - 1][start_pos.x - 1][0] > 0 : + print("punct control 4") + if pasi == 2: + print("trece de primul if") + #marcare noua pozitie a piesei + grid_data[grid_pos.y][grid_pos.x][0] = start_piesa + create_marker(-1, grid_pos * cell_size + Vector2i(cell_size /2, cell_size /2 + 5 )) + #demarcare vechea pozitie a piesei + create_marker(grid_data[start_pos.y][start_pos.x][1], start_pos * cell_size + Vector2i(cell_size /2, cell_size /2) ) + grid_data[start_pos.y][start_pos.x][0] = 0 + #demarcare piesa capturata + start_pos.x -=1 + start_pos.y -=1 + create_marker(7, start_pos * cell_size + Vector2i(cell_size /2, cell_size /2) ) + grid_data[start_pos.y + 1][start_pos.x + 1][0] = 0 + print(grid_pos) + print(grid_data) + pasi = 1 + player = 1 + +func deplasare_diagonala_alb(): + if grid_pos != start_pos and grid_data[grid_pos.y][grid_pos.x][0] == 0 : + if grid_pos.x == start_pos.x - 1 and grid_pos.y == start_pos.y - 1 or grid_pos.x == start_pos.x - 1 and grid_pos.y == start_pos.y + 1 : + if pasi == 2: + print("trece de primul if") + #marcare noua pozitie a piesei + grid_data[grid_pos.y][grid_pos.x][0] = start_piesa + create_marker(-1, grid_pos * cell_size + Vector2i(cell_size /2, cell_size /2 + 5 )) + #demarcare vechea pozitie a piesei + create_marker(grid_data[start_pos.y][start_pos.x][1], start_pos * cell_size + Vector2i(cell_size /2, cell_size /2) ) + grid_data[start_pos.y][start_pos.x][0] = 0 + print(grid_pos) + print(grid_data) + pasi = 1 + player = 1 diff --git a/main.tscn b/main.tscn new file mode 100644 index 0000000..73036a7 --- /dev/null +++ b/main.tscn @@ -0,0 +1,15 @@ +[gd_scene load_steps=6 format=3 uid="uid://d3fe3x8i4thex"] + +[ext_resource type="Script" path="res://Node.gd" id="1_ox6fu"] +[ext_resource type="PackedScene" uid="uid://cuyfyvmjadgfe" path="res://piesa_neagra.tscn" id="2_n2mde"] +[ext_resource type="PackedScene" uid="uid://dta6hda8c28c" path="res://piesa_alba.tscn" id="3_7i2qb"] +[ext_resource type="PackedScene" uid="uid://dwmjduf28jj5n" path="res://cadran_negru.tscn" id="4_dn6gu"] +[ext_resource type="PackedScene" uid="uid://8obda0sgowyv" path="res://tabla.tscn" id="5_f6dqy"] + +[node name="Main" type="Node"] +script = ExtResource("1_ox6fu") +piesa_neagra_scene = ExtResource("2_n2mde") +piesa_alba_scene = ExtResource("3_7i2qb") +cadran_negru_scene = ExtResource("4_dn6gu") + +[node name="Randuri" parent="." instance=ExtResource("5_f6dqy")] diff --git a/patrat.gd b/patrat.gd new file mode 100644 index 0000000..f17fea3 --- /dev/null +++ b/patrat.gd @@ -0,0 +1,16 @@ +@tool +extends ColorRect +@export var dark :bool= false : + set(v): + dark=v + color=Color.BLACK if dark else Color.WHITE + + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + pass diff --git a/patrat.tscn b/patrat.tscn new file mode 100644 index 0000000..18cc88a --- /dev/null +++ b/patrat.tscn @@ -0,0 +1,7 @@ +[gd_scene format=3 uid="uid://b5ubq4m4stdr5"] + +[node name="Pătrat" type="ColorRect"] +custom_minimum_size = Vector2(95, 95) +offset_right = 48.0 +offset_bottom = 48.0 +color = Color(1, 0.843137, 0, 1) diff --git a/piesa_alba.tscn b/piesa_alba.tscn new file mode 100644 index 0000000..5cb216e --- /dev/null +++ b/piesa_alba.tscn @@ -0,0 +1,7 @@ +[gd_scene load_steps=2 format=3 uid="uid://dta6hda8c28c"] + +[ext_resource type="Texture2D" uid="uid://dgttlohxxwndc" path="res://Asset/piesaDameAlbaCropped.png" id="1_loii0"] + +[node name="Sprite2D" type="Sprite2D"] +scale = Vector2(0.8, 0.8) +texture = ExtResource("1_loii0")