Skip to content

Commit

Permalink
Добавлен компьютер с сапёром для ЗК. (#13794)
Browse files Browse the repository at this point in the history
* Добавлен компьютер с сапёром для ЗК.

Добавлен компьютер с сапёром.
Небольшие доработки кода сапёра.

* Добавлен эффект от емагга.

Добавлен емаг-эффект.

* Убрал возможность умереть первым ходом.

Сделал перемещение мины если ты наступил на неё первым ходом.

* Небольшая переделка логики сапёра.

Теперь генерация поля и население его минами в двух раздельных функциях и сначала генерируется абсолютно пустое поле, а потом после первого нажатия оно населяется минами так, чтобы нажатая кнопка не имела под собой мины.
  • Loading branch information
DarthSidiousPalpatine authored Mar 1, 2025
1 parent bb627c0 commit 16a8fff
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 2 deletions.
82 changes: 82 additions & 0 deletions code/game/machinery/computer/prison.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/obj/machinery/computer/prison
name = "Prison Computer"
density = TRUE
anchored = TRUE
icon_state = "computer_old"
state_broken_preset = "computer_oldb"
state_nopower_preset = "computer_old0"
light_color = "#315ab4"

var/datum/minigame/minesweeper/Game

/obj/machinery/computer/prison/atom_init()
. = ..()

Game = new()
Game.setup_game()

/obj/machinery/computer/prison/attack_hand(mob/user)
tgui_interact(user)

/obj/machinery/computer/prison/tgui_interact(mob/user, datum/tgui/ui)
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
ui = new(user, src, "Minesweeper")
ui.open()

/obj/machinery/computer/prison/tgui_data(mob/user)
var/list/data = list()

data["grid"] = Game.grid
data["width"] = Game.grid_x*30
data["height"] = Game.grid_y*30
data["mines"] = "Сапёр. [num2text(Game.grid_mines)] мин."

return data

/obj/machinery/computer/prison/tgui_act(action, params)
. = ..()
if(.)
return
if(action == "button_press")
if(Game.button_press(text2num(params["choice_y"]), text2num(params["choice_x"])))
playsound(src, 'sound/items/buttonclick.ogg', VOL_EFFECTS_MASTER, 100, TRUE)
else
lost()
return TRUE

if(action == "button_flag")
if(Game.button_flag(text2num(params["choice_y"]), text2num(params["choice_x"])))
playsound(src, 'sound/items/buttonswitch.ogg', VOL_EFFECTS_MASTER, 100, TRUE)


if(Game.check_complete())
won()

return TRUE

/obj/machinery/computer/prison/proc/won()
playsound(src, 'sound/machines/arcade/e_death.ogg', VOL_EFFECTS_MASTER, 80, FALSE, null, -6)
Game.setup_game()
SStgui.close_uis(src)

if(emagged)
empulse(loc, 10, 15, custom_effects = EMP_SEBB)
emagged = FALSE

/obj/machinery/computer/prison/proc/lost()
playsound(src, pick('sound/machines/arcade/gethit1.ogg', 'sound/machines/arcade/gethit2.ogg'), VOL_EFFECTS_MASTER, 80, FALSE, null, -6)
Game.setup_game()
SStgui.close_uis(src)

if(emagged)
explosion(loc, 0, 1, 7)
emagged = FALSE

/obj/machinery/computer/prison/emag_act(mob/user)
if(emagged)
return FALSE

playsound(src, 'sound/machines/buzz-two.ogg', VOL_EFFECTS_MASTER, 80, FALSE, null, -6)
to_chat(user, "<span class='warning'>Новый уровень сложности разблокирован!</span>")
emagged = TRUE
13 changes: 13 additions & 0 deletions code/modules/minigames/minesweeper.dm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
)

/datum/minigame/minesweeper/proc/button_press(y, x)
if(!grid_pressed)
populate_mines(y, x) //We pressed first button, lets populate minefield
if(grid[y][x]["flag"])
return TRUE //We fake pressed a button with a flag
if(grid[y][x]["state"] == STATE_MINE)
Expand All @@ -24,6 +26,9 @@
return TRUE //We pressed a button

/datum/minigame/minesweeper/proc/button_flag(y, x)
if(!grid_pressed)
return FALSE

var/list/L = grid[y][x]
if(L["state"] != STATE_EMPTY)
L["flag"] = !L["flag"]
Expand All @@ -34,6 +39,8 @@
grid_y = rand(7,10)

grid_mines = rand(7,17)
grid_blanks = 0
grid_pressed = 0

grid = new/list(grid_y, grid_x)

Expand All @@ -43,10 +50,13 @@
Line[j] = list("state" = STATE_BLANK, "x" = j, "y" = i, "nearest" = "", "flag" = FALSE)
grid_blanks++

/datum/minigame/minesweeper/proc/populate_mines(pressedY, pressedX)
for(var/i = 1 to grid_mines)
while(TRUE)
var/y = rand(1,grid_y)
var/x = rand(1,grid_x)
if(pressedX == x && pressedY == y)
continue
var/list/L = grid[y][x]
if(L["state"] == STATE_MINE)
continue
Expand Down Expand Up @@ -91,6 +101,9 @@
/datum/minigame/minesweeper/proc/check_complete()
return grid_pressed == grid_blanks

/datum/minigame/minesweeper/proc/get_difficulty()
return grid ? grid_mines/grid_blanks : 0

#undef STATE_EMPTY
#undef STATE_BLANK
#undef STATE_MINE
2 changes: 1 addition & 1 deletion code/modules/mining/abandonedcrates.dm
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
return TRUE

/obj/structure/closet/crate/secure/loot/proc/won()
var/loot_quality = 2 * Game.grid_mines/Game.grid_blanks
var/loot_quality = 2 * Game.get_difficulty()
if(prob(loot_quality * 100))
SpawnGoodLoot()
else
Expand Down
5 changes: 4 additions & 1 deletion maps/boxstation/boxstation.dmm
Original file line number Diff line number Diff line change
Expand Up @@ -9161,6 +9161,7 @@
"aoY" = (
/obj/structure/table,
/obj/item/weapon/dice/d20,
/obj/item/weapon/book/manual/wiki/security_space_law,
/turf/simulated/floor,
/area/station/security/prison)
"aoZ" = (
Expand All @@ -9186,7 +9187,9 @@
/area/station/security/detectives_office)
"apc" = (
/obj/structure/table,
/obj/item/weapon/book/manual/wiki/security_space_law,
/obj/machinery/computer/prison{
pixel_y = 7
},
/turf/simulated/floor,
/area/station/security/prison)
"apd" = (
Expand Down
1 change: 1 addition & 0 deletions taucetistation.dme
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,7 @@
#include "code\game\machinery\computer\Operating.dm"
#include "code\game\machinery\computer\pod.dm"
#include "code\game\machinery\computer\power.dm"
#include "code\game\machinery\computer\prison.dm"
#include "code\game\machinery\computer\prisoner.dm"
#include "code\game\machinery\computer\robot.dm"
#include "code\game\machinery\computer\security.dm"
Expand Down

0 comments on commit 16a8fff

Please sign in to comment.