-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgame.lua
112 lines (102 loc) · 2.75 KB
/
game.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
Vulnerability = require "lib.Vulnerability"
Os = require "lib.Os"
Configuration = require "lib.Configuration"
Service = require "lib.Service"
Outcome = require "lib.Outcome"
Virus = require "lib.Virus"
Rootkit = require "lib.Rootkit"
Action = require "lib.Action"
Tool = require "lib.Tool"
Domain = require "lib.Domain"
Network = require "lib.Network"
NetworkInterface = require "lib.NetworkInterface"
AddrPortListenningService = require "lib.AddrPortListenningService"
Host = require "lib.Host"
AI = require "lib.AI"
dns_resolver = require "lib.dns_resolver"
map = require "map"
map_convertor = require "lib.map_convertor"
require "lib.cheatings"
game = {}
game.score = 0
game.map = map
game.map_save_path = "save/map.json"
game.map_pathes = {
tutorial = "maps/tutorial.json",
example = "maps/example.json"
}
game.selected_host = nil
game.selected_ai = nil
game.loading = require "state.loading"
game.main_menu = require "state.main_menu"
game.message_modal = require "state.message_modal"
game.play = require "state.play"
game.view_point = {x=0,y=0}
function game:load()
loveframes.util.SetActiveSkin("Hack_Menu")
loveframes.SetState("main_menu")
game.loading:load()
game.main_menu:load()
game.message_modal:load()
end
function game.update(dt)
local gamestate = loveframes.GetState()
if gamestate == "play" then
game.play.update(dt)
end
end
function game.draw()
local gamestate = loveframes.GetState()
if gamestate == "play" then
game.play.draw()
end
end
function game.mousepressed(x, y, button)
local gamestate = loveframes.GetState()
if gamestate == "play" then
game.play.mousepressed(x, y, button)
end
end
function game.mousereleased(x, y, button)
local gamestate = loveframes.GetState()
if gamestate == "play" then
game.play.mousereleased(x, y, button)
end
end
function game:save_map()
local json_str = map_convertor:encode(self.map)
local map_file = io.open(self.map_save_path, "w")
map_file:write(json_str)
map_file:close()
end
function game:load_map(...)
self.map:reset()
local arg = {...}
-- loading map
local map_file
if arg[1] == nil then
map_file = io.open(self.map_save_path, "r")
else
map_file = io.open(self.map_pathes[arg[1]], "r")
end
local json_str = map_file:read()
map_file:close()
local tmp_map = map_convertor:decode(json_str)
self.map.domains = tmp_map.domains
self.map.networks = tmp_map.networks
self.map.hosts = tmp_map.hosts
if arg[1] ~= nil then
local now = os.time()
self.map.start_time = now - now % 60
end
game.started = true
game.play:load()
for _,host in ipairs(self.map.hosts) do
if host.state == Host.State.Mine then
game.view_point.x = host.ui.abs_x - 300
game.view_point.y = host.ui.abs_y - 200
break
end
end
end
return game