Upload files to "/"

This commit is contained in:
Dragos Stefan Cirstian 2024-07-16 16:57:57 +03:00
parent 9a90d89899
commit 8bf307d33b
5 changed files with 818 additions and 0 deletions

781
Node.gd Normal file
View File

@ -0,0 +1,781 @@
extends Node
@export var pion_alb_scene : PackedScene
@export var pion_negru_scene : PackedScene
@export var cadran_negru_scene : PackedScene
@export var cadran_alb_scene : PackedScene
@export var tura_neagra_scene: PackedScene
@export var cal_negru_scene: PackedScene
@export var nebun_negru_scene: PackedScene
@export var regina_neagra_scene: PackedScene
@export var rege_negru_scene: PackedScene
@export var tura_alba_scene: PackedScene
@export var cal_alb_scene: PackedScene
@export var nebun_alb_scene: PackedScene
@export var regina_alba_scene: PackedScene
@export var rege_alb_scene: PackedScene
var player : int
var piesa_panel_pos: Vector2i
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
var enemy : Vector2i # ajuta la retinerea valorilor pieselor inamice
var ally : Vector2i
var piesa_mutare : int
var transformare_pion = false
var rege_alb = false # nu stiu daca trebuie puse aici
var rege_negru = false
# 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
piesa_panel_pos=$PanelPiesa.get_position()
new_game()
piesa_mutare = 100 # valoare aberanta
enemy = Vector2i(-6,-1)
ally = Vector2i(1,6)
func _input(event):
cauta_regii()
if event is InputEventMouseButton :
if event.button_index == MOUSE_BUTTON_RIGHT and event.pressed :
piesa_mutare = 99
create_marker(8, piesa_panel_pos+ Vector2i(cell_size/2+24, cell_size/2+25),true)
get_node("LabelNumePiesa").text=""
pasi = 1
print("ATENTIE CLICK DREAPTA DE LA MOUSE ANULEAZA PIESA SELECTATA")
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]
rege_alb = false
rege_negru = false
if player == 1 :
transformare_pion = false
#miscari pentru pion
if grid_data[grid_pos.y][grid_pos.x][0] == 6 and pasi == 1 :
selectare_piesa()
get_node("LabelNumePiesa").text=str(start_pos)
piesa_mutare = grid_data[grid_pos.y][grid_pos.x][0]
create_marker(6, piesa_panel_pos+ Vector2i(cell_size/2+24, cell_size/2+25),true)
#deplasare pion alb in fata
elif grid_pos != start_pos and grid_data[grid_pos.y][grid_pos.x][0] == 0 and piesa_mutare == 6:
deplasare_inainte_pion_alb()
# capturare piesa de catre pion alb pe diagonala
elif grid_pos != start_pos and grid_data[grid_pos.y][grid_pos.x][0] < 0 and piesa_mutare == 6:
capturare_diagonala_pion_alb()
#miscari pentru tura
if grid_data[grid_pos.y][grid_pos.x][0] == 5 and pasi == 1 :
selectare_piesa()
get_node("LabelNumePiesa").text=str(start_pos)
piesa_mutare = grid_data[grid_pos.y][grid_pos.x][0]
create_marker(5, piesa_panel_pos+ Vector2i(cell_size/2+24, cell_size/2+25),true)
#deplasare tura
elif grid_pos != start_pos and grid_data[grid_pos.y][grid_pos.x][0] <= 0 and piesa_mutare == 5:
if pasi == 2:
luare_piesa_linie_coloana()
#miscare pentru cal
if grid_data[grid_pos.y][grid_pos.x][0] == 4 and pasi == 1 :
selectare_piesa()
get_node("LabelNumePiesa").text=str(start_pos)
piesa_mutare = grid_data[grid_pos.y][grid_pos.x][0]
create_marker(4, piesa_panel_pos+ Vector2i(cell_size/2+24, cell_size/2+25),true)
#deplasare cal
elif grid_pos != start_pos and grid_data[grid_pos.y][grid_pos.x][0] <= 0 and piesa_mutare == 4:
if pasi == 2:
deplasare_cal()
#miscari pentru nebuni
if grid_data[grid_pos.y][grid_pos.x][0] == 3 and pasi == 1 :
selectare_piesa()
get_node("LabelNumePiesa").text=str(start_pos)
piesa_mutare = grid_data[grid_pos.y][grid_pos.x][0]
create_marker(3, piesa_panel_pos+ Vector2i(cell_size/2+24, cell_size/2+25),true)
#deplasare nebun
elif grid_pos != start_pos and grid_data[grid_pos.y][grid_pos.x][0] <= 0 and piesa_mutare == 3:
if pasi == 2:
luare_piesa_diagonala()
#miscari pentru regina
if grid_data[grid_pos.y][grid_pos.x][0] == 1 and pasi == 1 and transformare_pion == false :
selectare_piesa()
get_node("LabelNumePiesa").text=str(start_pos)
piesa_mutare = grid_data[grid_pos.y][grid_pos.x][0]
create_marker(1, piesa_panel_pos+ Vector2i(cell_size/2+24, cell_size/2+25),true)
#deplasare regina
elif grid_pos != start_pos and grid_data[grid_pos.y][grid_pos.x][0] <= 0 and piesa_mutare == 1:
if pasi == 2:
deplasare_regina()
#miscari pentru rege
if grid_data[grid_pos.y][grid_pos.x][0] == 2 and pasi == 1:
selectare_piesa()
get_node("LabelNumePiesa").text=str(start_pos)
piesa_mutare = grid_data[grid_pos.y][grid_pos.x][0]
create_marker(2, piesa_panel_pos+ Vector2i(cell_size/2+24, cell_size/2+25),true)
#deplasare rege
elif grid_pos != start_pos and grid_data[grid_pos.y][grid_pos.x][0] <= 0 and piesa_mutare == 2:
if pasi == 2:
deplasare_rege()
elif player == -1 :
transformare_pion = false
if grid_data[grid_pos.y][grid_pos.x][0] == -6 and pasi == 1 :
selectare_piesa()
get_node("LabelNumePiesa").text=str(start_pos)
create_marker(-6, piesa_panel_pos+ Vector2i(cell_size/2+24, cell_size/2+25),true)
piesa_mutare = grid_data[grid_pos.y][grid_pos.x][0]
#deplasare pion negru in fata
elif grid_pos != start_pos and grid_data[grid_pos.y][grid_pos.x][0] == 0 and piesa_mutare == -6:
deplasare_inainte_pion_negru()
#capturare piesa de catre pion negru pe diagonala
elif grid_pos != start_pos and grid_data[grid_pos.y][grid_pos.x][0] > 0 and piesa_mutare == -6:
capturare_diagonala_pion_negru()
#miscari pentru tura
if grid_data[grid_pos.y][grid_pos.x][0] == -5 and pasi == 1 :
selectare_piesa()
get_node("LabelNumePiesa").text=str(start_pos)
piesa_mutare = grid_data[grid_pos.y][grid_pos.x][0]
create_marker(-5, piesa_panel_pos+ Vector2i(cell_size/2+24, cell_size/2+25),true)
#deplasare tura
elif grid_pos != start_pos and grid_data[grid_pos.y][grid_pos.x][0] >= 0 and piesa_mutare == -5:
if pasi == 2:
luare_piesa_linie_coloana()
#miscarre pentru cal
if grid_data[grid_pos.y][grid_pos.x][0] == -4 and pasi == 1 :
selectare_piesa()
get_node("LabelNumePiesa").text=str(start_pos)
piesa_mutare = grid_data[grid_pos.y][grid_pos.x][0]
create_marker(-4, piesa_panel_pos+ Vector2i(cell_size/2+24, cell_size/2+25),true)
#deplasare cal
elif grid_pos != start_pos and grid_data[grid_pos.y][grid_pos.x][0] >= 0 and piesa_mutare == -4:
if pasi == 2:
deplasare_cal()
#miscare pentru nebuni
if grid_data[grid_pos.y][grid_pos.x][0] == -3 and pasi == 1 :
selectare_piesa()
get_node("LabelNumePiesa").text=str(start_pos)
piesa_mutare = grid_data[grid_pos.y][grid_pos.x][0]
create_marker(-3, piesa_panel_pos+ Vector2i(cell_size/2+24, cell_size/2+25),true)
#deplasare nebun
elif grid_pos != start_pos and grid_data[grid_pos.y][grid_pos.x][0] >= 0 and piesa_mutare == -3:
if pasi == 2:
luare_piesa_diagonala()
#miscare pentru regina
if grid_data[grid_pos.y][grid_pos.x][0] == -1 and pasi == 1 and transformare_pion == false:
selectare_piesa()
get_node("LabelNumePiesa").text=str(start_pos)
piesa_mutare = grid_data[grid_pos.y][grid_pos.x][0]
create_marker(-1, piesa_panel_pos+ Vector2i(cell_size/2+24, cell_size/2+25),true)
#deplasare regina
elif grid_pos != start_pos and grid_data[grid_pos.y][grid_pos.x][0] >= 0 and piesa_mutare == -1:
if pasi == 2:
deplasare_regina()
#miscare pentru rege
if grid_data[grid_pos.y][grid_pos.x][0] == -2 and pasi == 1 :
selectare_piesa()
get_node("LabelNumePiesa").text=str(start_pos)
piesa_mutare = grid_data[grid_pos.y][grid_pos.x][0]
create_marker(-2, piesa_panel_pos+ Vector2i(cell_size/2+24, cell_size/2+25),true)
#deplasare tura
elif grid_pos != start_pos and grid_data[grid_pos.y][grid_pos.x][0] >= 0 and piesa_mutare == -2:
if pasi == 2:
deplasare_rege()
func new_game():
player = 1
enemy = Vector2i(-6, -1)
get_node("LabelJucator").text="Alb"
# [5,1] a doua valoare marcheaza culoarea chenarului tablei de joc, 7 = negru, 8 = alb
grid_data = [
[[5,7], [6,8], [0,7], [0,8], [0,7], [0,8], [-6,7], [-5,8]],
[[4,8], [6,7], [0,8], [0,7], [0,8], [0,7], [-6,8], [-4,7]],
[[3,7], [6,8], [0,7], [0,8], [0,7], [0,8], [-6,7], [-3,8]],
[[1,8], [6,7], [0,8], [0,7], [0,8], [0,7], [-6,8], [-1,7]],
[[2,7], [6,8], [0,7], [0,8], [0,7], [0,8], [-6,7], [-2,8]],
[[3,8], [6,7], [0,8], [0,7], [0,8], [0,7], [-6,8], [-3,7]],
[[4,7], [6,8], [0,7], [0,8], [0,7], [0,8], [-6,7], [-4,8]],
[[5,8], [6,7], [0,8], [0,7], [0,8], [0,7], [-6,8], [-5,7]]
]
pasi = 1
get_tree().call_group("pioni_albi","queue_free")
get_tree().call_group("ture_albe","queue_free")
get_tree().call_group("nebuni_albi","queue_free")
get_tree().call_group("cai_albi","queue_free")
get_tree().call_group("regina_alba","queue_free")
get_tree().call_group("rege_alb","queue_free")
get_tree().call_group("pioni_negri","queue_free")
get_tree().call_group("ture_negre","queue_free")
get_tree().call_group("nebuni_negri","queue_free")
get_tree().call_group("cai_negri","queue_free")
get_tree().call_group("regina_neagra","queue_free")
get_tree().call_group("rege_negru","queue_free")
$MeniuGameOver.hide()
get_tree().paused=false
# punerea pionilor albi pe tabla
create_marker(6, Vector2i(1,0) * cell_size + Vector2i(cell_size /2, cell_size /2 ))
create_marker(6, Vector2i(1,1) * cell_size + Vector2i(cell_size /2, cell_size /2 ))
create_marker(6, Vector2i(1,2) * cell_size + Vector2i(cell_size /2, cell_size /2 ))
create_marker(6, Vector2i(1,3) * cell_size + Vector2i(cell_size /2, cell_size /2 ))
create_marker(6, Vector2i(1,4) * cell_size + Vector2i(cell_size /2, cell_size /2 ))
create_marker(6, Vector2i(1,5) * cell_size + Vector2i(cell_size /2, cell_size /2 ))
create_marker(6, Vector2i(1,6) * cell_size + Vector2i(cell_size /2, cell_size /2 ))
create_marker(6, Vector2i(1,7) * cell_size + Vector2i(cell_size /2, cell_size /2 ))
#punerea pionilor negri pe tabla
create_marker(-6, Vector2i(6,0) * cell_size + Vector2i(cell_size /2, cell_size /2 ))
create_marker(-6, Vector2i(6,1) * cell_size + Vector2i(cell_size /2, cell_size /2 ))
create_marker(-6, Vector2i(6,2) * cell_size + Vector2i(cell_size /2, cell_size /2 ))
create_marker(-6, Vector2i(6,3) * cell_size + Vector2i(cell_size /2, cell_size /2 ))
create_marker(-6, Vector2i(6,4) * cell_size + Vector2i(cell_size /2, cell_size /2 ))
create_marker(-6, Vector2i(6,5) * cell_size + Vector2i(cell_size /2, cell_size /2 ))
create_marker(-6, Vector2i(6,6) * cell_size + Vector2i(cell_size /2, cell_size /2 ))
create_marker(-6, Vector2i(6,7) * cell_size + Vector2i(cell_size /2, cell_size /2 ))
#punerea turelor negre
create_marker(-5, Vector2i(7,0) * cell_size + Vector2i(cell_size /2, cell_size /2))
create_marker(-5, Vector2i(7,7) * cell_size + Vector2i(cell_size /2, cell_size /2))
#punerea cailor negri
create_marker(-4, Vector2i(7,1) * cell_size + Vector2i(cell_size /2, cell_size /2))
create_marker(-4, Vector2i(7,6) * cell_size + Vector2i(cell_size /2, cell_size /2))
#punerea nebunilor negri
create_marker(-3, Vector2i(7,2) * cell_size + Vector2i(cell_size /2, cell_size /2))
create_marker(-3, Vector2i(7,5) * cell_size + Vector2i(cell_size /2, cell_size /2))
#punerea regelui si a reginei negre
create_marker(-1, Vector2i(7,3) * cell_size + Vector2i(cell_size /2, cell_size /2))
create_marker(-2, Vector2i(7,4) * cell_size + Vector2i(cell_size /2, cell_size /2))
#punerea turelor albe
create_marker(5, Vector2i(0,0) * cell_size + Vector2i(cell_size /2, cell_size /2))
create_marker(5, Vector2i(0,7) * cell_size + Vector2i(cell_size /2, cell_size /2))
#punerea cailor albi
create_marker(4, Vector2i(0,1) * cell_size + Vector2i(cell_size /2, cell_size /2))
create_marker(4, Vector2i(0,6) * cell_size + Vector2i(cell_size /2, cell_size /2))
#punerea nebunilor albi
create_marker(3, Vector2i(0,2) * cell_size + Vector2i(cell_size /2, cell_size /2))
create_marker(3, Vector2i(0,5) * cell_size + Vector2i(cell_size /2, cell_size /2))
#punerea regelui si a reginei albe
create_marker(1, Vector2i(0,3) * cell_size + Vector2i(cell_size /2, cell_size /2))
create_marker(2, Vector2i(0,4) * cell_size + Vector2i(cell_size /2, cell_size /2))
func create_marker(piesa, position, temp=false) :
#creaza un marcker node si il adauga ca un child
if piesa==-1:
var regina_neagra = regina_neagra_scene.instantiate()
regina_neagra.position=position
add_child(regina_neagra)
if temp: temp_marker=regina_neagra
if piesa==-2:
var rege_negru = rege_negru_scene.instantiate()
rege_negru.position=position
add_child(rege_negru)
if temp: temp_marker=rege_negru
if piesa==-3:
var nebun_negru = nebun_negru_scene.instantiate()
nebun_negru.position=position
add_child(nebun_negru)
if temp: temp_marker=nebun_negru
if piesa ==-4:
var cal_negru = cal_negru_scene.instantiate()
cal_negru.position=position
add_child(cal_negru)
if temp: temp_marker=cal_negru
if piesa == -5:
var tura_neagra = tura_neagra_scene.instantiate()
tura_neagra.position = position
add_child(tura_neagra)
if temp: temp_marker=tura_neagra
if piesa == -6 :
var pion_negru = pion_negru_scene.instantiate()
pion_negru.position = position
add_child(pion_negru)
if temp: temp_marker=pion_negru
if piesa==1:
var regina_alba=regina_alba_scene.instantiate()
regina_alba.position=position
add_child(regina_alba)
if temp: temp_marker=regina_alba
if piesa==2:
var rege_alb=rege_alb_scene.instantiate()
rege_alb.position=position
add_child(rege_alb)
if temp: temp_marker=rege_alb
if piesa==3:
var nebun_alb=nebun_alb_scene.instantiate()
nebun_alb.position=position
add_child(nebun_alb)
if temp: temp_marker=nebun_alb
if piesa==4:
var cal_alb=cal_alb_scene.instantiate()
cal_alb.position=position
add_child(cal_alb)
if temp: temp_marker=cal_alb
if piesa == 5:
var tura_alba = tura_alba_scene.instantiate()
tura_alba.position=position
add_child(tura_alba)
if temp: temp_marker=tura_alba
if piesa == 6 :
var pion_alb = pion_alb_scene.instantiate()
pion_alb.position = position
add_child(pion_alb)
if temp: temp_marker=pion_alb
if piesa == 7 :
var cadran_negru = cadran_negru_scene.instantiate()
cadran_negru.position = position
add_child((cadran_negru))
if piesa == 8 :
var cadran_alb = cadran_alb_scene.instantiate()
cadran_alb.position = position
add_child((cadran_alb))
func deplasare_inainte_pion_alb():
if grid_pos.x == start_pos.x + 1 and grid_pos.y == start_pos.y :
if pasi == 2:
deplasare_piesa()
if grid_pos.x == 7:
create_marker(grid_data[grid_pos.y][grid_pos.x][1], grid_pos * cell_size + Vector2i(cell_size /2, cell_size /2) )
create_marker(1, grid_pos * cell_size + Vector2i(cell_size /2, cell_size /2) )
grid_data[grid_pos.y][grid_pos.x][0] = 1
transformare_pion = true
elif grid_pos.x == start_pos.x + 2 and grid_pos.y == start_pos.y and start_pos.x == 1 and grid_data[start_pos.y][start_pos.x + 1][0] == 0 :
if pasi == 2 :
deplasare_piesa()
func capturare_diagonala_pion_alb():
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:
deplasare_piesa()
if grid_pos.x == 7:
create_marker(grid_data[grid_pos.y][grid_pos.x][1], grid_pos * cell_size + Vector2i(cell_size /2, cell_size /2) )
create_marker(1, grid_pos * cell_size + Vector2i(cell_size /2, cell_size /2) )
grid_data[grid_pos.y][grid_pos.x][0] = 1
transformare_pion = true
func deplasare_inainte_pion_negru():
if grid_pos.x == start_pos.x - 1 and grid_pos.y == start_pos.y :
if pasi == 2:
deplasare_piesa()
if grid_pos.x == 0:
create_marker(grid_data[grid_pos.y][grid_pos.x][1], grid_pos * cell_size + Vector2i(cell_size /2, cell_size /2) )
create_marker(-1, grid_pos * cell_size + Vector2i(cell_size /2, cell_size /2) )
grid_data[grid_pos.y][grid_pos.x][0] = -1
transformare_pion = true
elif grid_pos.x == start_pos.x - 2 and grid_pos.y == start_pos.y and start_pos.x == 6 and grid_data[start_pos.y][start_pos.x - 1][0] == 0 :
if pasi == 2 :
deplasare_piesa()
func capturare_diagonala_pion_negru():
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 :
deplasare_piesa()
if grid_pos.x == 0:
create_marker(grid_data[grid_pos.y][grid_pos.x][1], grid_pos * cell_size + Vector2i(cell_size /2, cell_size /2) )
create_marker(-1, grid_pos * cell_size + Vector2i(cell_size /2, cell_size /2) )
grid_data[grid_pos.y][grid_pos.x][0] = -1
transformare_pion = true
func luare_piesa_linie():
# capturare piesa adversa pe linie
var sens = 0
if grid_pos.y == start_pos.y:
print("esti in fucntia luare_piesa_linie")
if grid_pos.x >= start_pos.x:
sens = 1
print("Sensul este ", sens)
print("aliati player-ului ",player, " sunt ", ally )
for i in range(start_pos.x + 1,grid_pos.x + 1, sens):
print(i)
print("esti in for loop")
# detecteaza inamici pe
if grid_data[grid_pos.y][i][0] >= enemy.x and grid_data[grid_pos.y][i][0] <= enemy.y :
grid_pos.x = i
print("Tura a intalnit un inamic in drum")
print("tura ramane pe pozitia cu grid_pos.x = ", i, " si grid_pos.y = ", grid_pos.y)
break
if grid_data[grid_pos.y][i][0] >= ally.x and grid_data[grid_pos.y][i][0] <= ally.y :
grid_pos.x = i - 1
print("Tura a intalnic un aliat in drum")
print("tura ramane pe pozitia cu grid_pos.x = ", i, " si grid_pos.y = ", grid_pos.y)
break
else:
sens = -1
print("Sensul este ", sens)
print("aliati player-ului ",player, " sunt ", ally )
for i in range(start_pos.x-1 ,grid_pos.x - 1, sens):
print(i)
print("Esti in for loop")
# detecteaza inamici pe
if grid_data[grid_pos.y][i][0] >= enemy.x and grid_data[grid_pos.y][i][0] <= enemy.y :
grid_pos.x = i
print("Tura a intalnit un inamic in drum")
print("tura ramane pe pozitia cu grid_pos.x = ", i, " si grid_pos.y = ", grid_pos.y)
break
if grid_data[grid_pos.y][i][0] >= ally.x and grid_data[grid_pos.y][i][0] <= ally.y :
grid_pos.x = i + 1
print("Tura a intalnic un aliat in drum")
print("tura ramane pe pozitia cu grid_pos.x = ", i, " si grid_pos.y = ", grid_pos.y)
break
if grid_pos != start_pos:
deplasare_piesa()
else:
pasi = 2 # se permite iar mutarea deoarece prima nu a produs nici-o miscare
print("parasire functie luare_piesa_linie")
func luare_piesa_coloana():
#capturare piesa pe coloanna
var sens = 0
if grid_pos.x == start_pos.x:
print("esti in functia luare_piesa_coloana")
if grid_pos.y >= start_pos.y:
sens = 1
print("Sensul este ", sens)
print("aliati player-ului ",player, " sunt ", ally )
for i in range(start_pos.y + 1,grid_pos.y + 1, sens):
print(i)
print("esti in for loop")
if grid_data[i][grid_pos.x][0] >= enemy.x and grid_data[i][grid_pos.x][0] <= enemy.y :
grid_pos.y = i
print("Tura a intalnit un inamic in drum")
print("tura ramane pe pozitia cu grid_pos.x = ", grid_pos.x, " si grid_pos.y = ", i)
break
if grid_data[i][grid_pos.x][0] >= ally.x and grid_data[i][grid_pos.x][0] <= ally.y :
grid_pos.x = i - 1
print("Tura a intalnic un aliat in drum")
print("tura ramane pe pozitia cu grid_pos.x = ", grid_pos.x, " si grid_pos.y= ", i)
break
else:
sens = -1
print("Sensul este ", sens)
print("aliati player-ului ",player, " sunt ", ally )
for i in range(start_pos.y - 1,grid_pos.y -1,sens):
print(i)
print("Esti in for loop")
if grid_data[i][grid_pos.x][0] >= enemy.x and grid_data[i][grid_pos.x][0] <= enemy.y :
grid_pos.y = i
print("Tura a intalnit un inamic in drum")
print("tura ramane pe pozitia cu grid_pos.x = ", grid_pos.x, " si grid_pos.y = ", i)
break
if grid_data[i][grid_pos.x][0] >= ally.x and grid_data[i][grid_pos.x][0] <= ally.y :
grid_pos.y = i + 1
print("tura ramane pe pozitia cu grid_pos.x = ", grid_pos.x, " si grid_pos.y = ", i)
print("Tura a intalnic un aliat in drum")
break
if grid_pos != start_pos:
deplasare_piesa()
else:
pasi = 2 # se permite iar mutarea deoarece prima nu a produs nici-o miscare
print("parasirea functie luare_piesa_coloana")
func luare_piesa_linie_coloana():
luare_piesa_linie()
luare_piesa_coloana()
print("parasier functie luare_piesa_linie_coloana")
func selectare_piesa():
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
func set_ally_and_enemy():
if player == 1:
enemy = Vector2i(-6,-1)
ally = Vector2i(1,6)
else :
enemy = Vector2i(1,6)
ally = Vector2i(-6,-1)
#deplasare_piesa este folosita in functia deplasare_cal si deplasare_piesa_diagonala
func deplasare_piesa():
#marcare noua pozitie a piesei
grid_data[grid_pos.y][grid_pos.x][0] = start_piesa
create_marker(start_piesa, 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
if player==1:
get_node("LabelJucator").text="Alb"
get_node("LabelNumePiesa").text=""
elif player==-1:
get_node("LabelJucator").text="Negru"
get_node("LabelNumePiesa").text=""
set_ally_and_enemy()
create_marker(8, piesa_panel_pos+ Vector2i(cell_size/2+24, cell_size/2+25),true)
func deplasare_cal():
var sens = 1 # deplasare la dreapta de poz initiala cal
print(" ")
print("intrare infunctia deplasare_cal")
#verificare mutare ca fiind pe tabla
if grid_pos.x >= 0 and grid_pos.x <=7 and grid_pos.y >= 0 and grid_pos.y <=7 :
print("Mutarea apare pe tabla: (linie,coloana) ", grid_pos.y, " ", grid_pos.x )
#verificare mutari partea dreapta fata de poz initiala cal
#verificare mutare (linie , coloana) (-2, +1)
if grid_pos.x == start_pos.x + (1*sens) and grid_pos.y == start_pos.y -2 :
print("calul este mutat la pozitia (linie,coloana) ", grid_pos.y, " ", grid_pos.x )
deplasare_piesa()
#verificare mutare (-1, +2)
if grid_pos.x == start_pos.x + (2*sens) and grid_pos.y == start_pos.y -1 :
print("calul este mutat la pozitia (linie,coloana) ", grid_pos.y, " ", grid_pos.x )
deplasare_piesa()
#verificare mutare (+1, +2)
if grid_pos.x == start_pos.x + (2*sens) and grid_pos.y == start_pos.y +1 :
print("calul este mutat la pozitia (linie,coloana) ", grid_pos.y, " ", grid_pos.x )
deplasare_piesa()
#verificare mutare(+2,+1)
if grid_pos.x == start_pos.x + (1*sens) and grid_pos.y == start_pos.y +2 :
print("calul este mutat la pozitia (linie,coloana) ", grid_pos.y, " ", grid_pos.x )
deplasare_piesa()
sens = -1
#verificare mutari partea stanga
#verificare mutare (linie , coloana) (-2, -1)
if grid_pos.x == start_pos.x + (1*sens) and grid_pos.y == start_pos.y -2 :
print("calul este mutat la pozitia (linie,coloana) ", grid_pos.y, " ", grid_pos.x )
deplasare_piesa()
#verificare mutare (-1, -2)
if grid_pos.x == start_pos.x + (2*sens) and grid_pos.y == start_pos.y -1 :
print("calul este mutat la pozitia (linie,coloana) ", grid_pos.y, " ", grid_pos.x )
deplasare_piesa()
#verificare mutare (+1, -2)
if grid_pos.x == start_pos.x + (2*sens) and grid_pos.y == start_pos.y +1 :
print("calul este mutat la pozitia (linie,coloana) ", grid_pos.y, " ", grid_pos.x )
deplasare_piesa()
#verificare mutare(+2,-1)
if grid_pos.x == start_pos.x + (1*sens) and grid_pos.y == start_pos.y +2 :
print("calul este mutat la pozitia (linie,coloana) ", grid_pos.y, " ", grid_pos.x )
deplasare_piesa()
func luare_piesa_diagonala():
var dx = abs(grid_pos.x - start_pos.x)
var dy = abs(grid_pos.y - start_pos.y)
#verific daca pozitia data este pe diagonala cu pozitia initiala
if dx == dy and dx > 0 :
if grid_pos.y < start_pos.y and grid_pos.x > start_pos.x :
print("pozitie initiala la diagonala dreapta sus")
print("esti in for loop")
for i in range(1,8):
if(start_pos.x + i > 7):
print(" break deoarece start_pos.x + i > 7")
break
if(start_pos.x + i > grid_pos.x):
print("break deoarece start_pos.x + i > grid_pos.x")
break
if(start_pos.y - i < 0):
print(" break deoarece start_pos.y - i < 0")
break
if(start_pos.y - i < grid_pos.y):
print("break deoarece start_pos.y - i < grid_pos.y")
break
print(i)
# detecteaza inamici
if grid_data[start_pos.y - i][start_pos.x + i][0] >= enemy.x and grid_data[start_pos.y - i][start_pos.x + i][0] <= enemy.y :
grid_pos.x = start_pos.x + i
grid_pos.y = start_pos.y - i
print("Nebunul a intalnit un inamic in drum")
print("Nebunul ramane pe pozitia cu grid_pos.x = ", grid_pos.x, " si grid_pos.y = ", grid_pos.y)
break
#detecteaza aliat
if grid_data[start_pos.y - i][start_pos.x + i][0] >= ally.x and grid_data[start_pos.y - i][start_pos.x + i][0] <= ally.y :
grid_pos.x = start_pos.x + i - 1
grid_pos.y = start_pos.y - i + 1
print("Nebunul a intalnic un aliat in drum")
print("Nebunul ramane pe pozitia cu grid_pos.x = ", grid_pos.x, " si grid_pos.y = ", grid_pos.y)
break
elif grid_pos.y > start_pos.y and grid_pos.x < start_pos.x: # pozitie initiala la diagonala stanga jos
print("pozitie initiala la diagonala stanga jos")
print("esti in for loop")
for i in range(1,8):
if(start_pos.y + i > 7):
print(" break deoarece start_pos.y + i > 7")
break
if(start_pos.y + i > grid_pos.y):
print("break deoarece start_pos.y + i > grid_pos.x")
break
if(start_pos.x - i < 0):
print(" break deoarece start_pos.x - i < 0")
break
if(start_pos.x - i < grid_pos.x):
print("break deoarece start_pos.x - i < grid_pos.x")
break
print(i)
# detecteaza inamici
if grid_data[start_pos.y + i][start_pos.x - i][0] >= enemy.x and grid_data[start_pos.y + i][start_pos.x - i][0] <= enemy.y :
grid_pos.x = start_pos.x - i
grid_pos.y = start_pos.y + i
print("Nebunul a intalnit un inamic in drum")
print("Nebunul ramane pe pozitia cu grid_pos.x = ", grid_pos.x, " si grid_pos.y = ", grid_pos.y)
break
#detecteaza aliat
if grid_data[start_pos.y + i][start_pos.x - i][0] >= ally.x and grid_data[start_pos.y + i][start_pos.x - i][0] <= ally.y :
grid_pos.x = start_pos.x - i + 1
grid_pos.y = start_pos.y + i - 1
print("Nebunul a intalnic un aliat in drum")
print("Nebunul ramane pe pozitia cu grid_pos.x = ", grid_pos.x, " si grid_pos.y = ", grid_pos.y)
break
elif grid_pos.y > start_pos.y and grid_pos.x > start_pos.x :
print("pozitie initiala la diagonala dreapta jos")
print("esti in for loop")
for i in range(1,8):
if(start_pos.x + i > 7):
print(" break deoarece start_pos.x + i > 7")
break
if(start_pos.x + i > grid_pos.x):
print("break deoarece start_pos.x + i > grid_pos.x")
break
print(i)
# detecteaza inamici
if grid_data[start_pos.y + i][start_pos.x + i][0] >= enemy.x and grid_data[start_pos.y + i][start_pos.x + i][0] <= enemy.y :
grid_pos.x = start_pos.x + i
grid_pos.y = start_pos.y + i
print("Nebunul a intalnit un inamic in drum")
print("Nebunul ramane pe pozitia cu grid_pos.x = ", grid_pos.x, " si grid_pos.y = ", grid_pos.y)
break
#detecteaza aliat
if grid_data[start_pos.y + i][start_pos.x + i][0] >= ally.x and grid_data[start_pos.y + i][start_pos.x + i][0] <= ally.y :
grid_pos.x = start_pos.x + i - 1
grid_pos.y = start_pos.y + i - 1
print("Nebunul a intalnic un aliat in drum")
print("Nebunul ramane pe pozitia cu grid_pos.x = ", grid_pos.x, " si grid_pos.y = ", grid_pos.y)
break
elif grid_pos.y < start_pos.y and grid_pos.x < start_pos.x:
print("pozitie initiala la diagonala stanga sus")
print("esti in for loop")
for i in range(1,8):
if(start_pos.x - i < 0):
print(" break deoarece start_pos.x - i < 0")
break
if(start_pos.x - i < grid_pos.x):
print("break deoarece start_pos.x - i < grid_pos.x")
break
print(i)
# detecteaza inamici
if grid_data[start_pos.y - i][start_pos.x - i][0] >= enemy.x and grid_data[start_pos.y - i][start_pos.x - i][0] <= enemy.y :
grid_pos.x = start_pos.x - i
grid_pos.y = start_pos.y - i
print("Nebunul a intalnit un inamic in drum")
print("Nebunul ramane pe pozitia cu grid_pos.x = ", grid_pos.x, " si grid_pos.y = ", grid_pos.y)
break
#detecteaza aliat
if grid_data[start_pos.y - i][start_pos.x - i][0] >= ally.x and grid_data[start_pos.y - i][start_pos.x - i][0] <= ally.y :
grid_pos.x = start_pos.x - i + 1
grid_pos.y = start_pos.y - i + 1
print("Nebunul a intalnic un aliat in drum")
print("Nebunul ramane pe pozitia cu grid_pos.x = ", grid_pos.x, " si grid_pos.y = ", grid_pos.y)
break
if grid_pos != start_pos:
deplasare_piesa()
else:
pasi = 2 # se permite iar mutarea deoarece prima nu a produs nici-o miscare
print("parasire functie luare_piesa_diagonala")
func deplasare_regina():
luare_piesa_linie_coloana()
luare_piesa_diagonala()
func deplasare_rege():
print(" ")
print("Ai intrat in functia deplasare_rege")
var sens
sens = 1
# verificare pozitie dreapta sus
if grid_pos.y == start_pos.y - 1 and grid_pos.x == start_pos.x + (1 * sens):
print("Regele mutat la pozitia grid_pos.x = ", grid_pos.x, " si grid_pos.y = ", grid_pos.y)
deplasare_piesa()
# verificare pozitie dreapta
if grid_pos.y == start_pos.y and grid_pos.x == start_pos.x + (1 * sens):
print("Regele mutat la pozitia grid_pos.x = ", grid_pos.x, " si grid_pos.y = ", grid_pos.y)
deplasare_piesa()
#verificare pozitie dreapta jos
if grid_pos.y == start_pos.y + 1 and grid_pos.x == start_pos.x + (1 * sens):
print("Regele mutat la pozitia grid_pos.x = ", grid_pos.x, " si grid_pos.y = ", grid_pos.y)
deplasare_piesa()
#verificare pozitie jos
if grid_pos.y == start_pos.y + (1 * sens) and grid_pos.x == start_pos.x:
print("Regele mutat la pozitia grid_pos.x = ", grid_pos.x, " si grid_pos.y = ", grid_pos.y)
deplasare_piesa()
sens = - 1 # pastea stanga si sus de poitii
#verificare pozitie stanga sus
if grid_pos.y == start_pos.y - 1 and grid_pos.x == start_pos.x + (1 * sens):
print("Regele mutat la pozitia grid_pos.x = ", grid_pos.x, " si grid_pos.y = ", grid_pos.y)
deplasare_piesa()
# verificare pozitie stanga
if grid_pos.y == start_pos.y and grid_pos.x == start_pos.x + (1 * sens):
print("Regele mutat la pozitia grid_pos.x = ", grid_pos.x, " si grid_pos.y = ", grid_pos.y)
deplasare_piesa()
#verificare pozitie stanga jos
if grid_pos.y == start_pos.y + 1 and grid_pos.x == start_pos.x + (1 * sens):
print("Regele mutat la pozitia grid_pos.x = ", grid_pos.x, " si grid_pos.y = ", grid_pos.y)
deplasare_piesa()
#verificare pozitie sus
if grid_pos.y == start_pos.y + (1 * sens) and grid_pos.x == start_pos.x:
print("Regele mutat la pozitia grid_pos.x = ", grid_pos.x, " si grid_pos.y = ", grid_pos.y)
deplasare_piesa()
func cauta_regii():
for i in range (0,8):
for j in range(0,8):
if grid_data[i][j][0] == 2:
rege_alb = true
if grid_data[i][j][0] == - 2:
rege_negru = true
if rege_alb == false :
print( "REGELE ALB A FOST CAPTURAT< NU SE MAI POATE CONTINUA!")
$MeniuGameOver.show()
$MeniuGameOver/LabelCastigator.text="Player 2 a câștigat!"
get_tree().paused=true
if rege_negru == false :
print("REGELE NEGRU A FOST CAPTURAT< NU SE MAI POATE CONTINUA!")
$MeniuGameOver.show()
$MeniuGameOver/LabelCastigator.text="Player 1 a câștigat!"
get_tree().paused=true
func _on_meniu_game_over_restart():
new_game()

7
nebun_negru.tscn Normal file
View File

@ -0,0 +1,7 @@
[gd_scene load_steps=2 format=3 uid="uid://cyfend41hs8ql"]
[ext_resource type="Texture2D" uid="uid://b8s2ba8dxoewg" path="res://Asset/nebun_negru.jpg" id="1_qyk88"]
[node name="Sprite2D" type="Sprite2D" groups=["nebuni_negri"]]
scale = Vector2(0.6, 0.6)
texture = ExtResource("1_qyk88")

16
patrat.gd Normal file
View File

@ -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

7
patrat.tscn Normal file
View File

@ -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)

7
pion_alb.tscn Normal file
View File

@ -0,0 +1,7 @@
[gd_scene load_steps=2 format=3 uid="uid://dsgf3iy1cj7vd"]
[ext_resource type="Texture2D" uid="uid://i3yvfhq53pk8" path="res://Asset/Pion_alb.jpeg" id="1_enrlx"]
[node name="Pion_alb" type="Sprite2D" groups=["pioni_albi"]]
scale = Vector2(0.6, 0.6)
texture = ExtResource("1_enrlx")