Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Vladimir Zhukov
cyberlozhkin
Commits
ffc84782
Commit
ffc84782
authored
Jan 02, 2022
by
Vladimir Zhukov
Browse files
add university
parent
43d3a3ed
Pipeline
#1469
passed with stage
in 3 seconds
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
cyberlozhkin/game/config.py
View file @
ffc84782
...
...
@@ -45,3 +45,12 @@ SCIENCE = {
'cost_exp'
:
3
,
},
}
UNIVERSITY
=
{
'university_0'
:
{
'name'
:
'Бакалавры'
,
'description'
:
'Преподавание 3-му курсу Основ кибернетики, пропаганда культа личности Светила.'
,
'task_key'
:
'task_2'
,
'cost'
:
(
10
,
1
),
},
}
cyberlozhkin/game/state.py
View file @
ffc84782
import
copy
import
time
from
.config
import
TASKS
,
SCIENCE
from
.config
import
TASKS
,
SCIENCE
,
UNIVERSITY
from
.models
import
GameState
from
.utils
import
convert_to_exp_amount
,
convert_to_value
...
...
@@ -102,6 +102,33 @@ class ScienceWrapper(JsonWrapper):
return
ratio
class
UniversityWrapper
(
JsonWrapper
):
def
__init__
(
self
,
state
,
key
,
university_json
):
super
().
__init__
(
state
,
key
,
UNIVERSITY
[
key
],
university_json
,
exp_amount
=
True
)
@
property
def
required_resource
(
self
):
return
TASKS
[
self
.
config
[
'task_key'
]].
get
(
'name'
,
''
)
@
property
def
cost
(
self
):
return
self
.
config
[
'cost'
]
@
property
def
avail_resources
(
self
):
task
=
self
.
state
.
task
(
self
.
config
[
'task_key'
])
return
task
.
amount
@
property
def
plis_used
(
self
):
return
self
.
json
.
get
(
'plis_used'
,
0
)
@
plis_used
.
setter
def
plis_used
(
self
,
value
):
self
.
json
[
'plis_used'
]
=
value
class
StateWrapper
:
def
__init__
(
self
,
instance
):
...
...
@@ -123,6 +150,17 @@ class StateWrapper:
convert_to_value
(
task
.
production
)
*
time_delta
)
for
university
in
self
.
university_list
:
task
=
self
.
task
(
university
.
config
[
'task_key'
])
task_amount
=
convert_to_value
(
task
.
amount
)
university_cost
=
convert_to_value
(
university
.
cost
)
max_production
=
task_amount
//
university_cost
real_production
=
min
(
university
.
plis_used
*
time_delta
,
max_production
)
task
.
amount
=
convert_to_exp_amount
(
task_amount
-
real_production
*
university_cost
)
university
.
amount
=
convert_to_exp_amount
(
convert_to_value
(
university
.
amount
)
+
real_production
)
self
.
instance
.
state
[
'timestamp'
]
=
new_timestamp
self
.
instance
.
save
()
...
...
@@ -153,6 +191,15 @@ class StateWrapper:
science
.
amount
+=
1
self
.
instance
.
save
()
def
use_plis_university
(
self
,
university_key
,
amount
):
if
university_key
not
in
UNIVERSITY
:
return
university
=
self
.
university
(
university_key
)
if
amount
<=
self
.
plis_free
and
amount
+
university
.
plis_used
>=
0
:
university
.
plis_used
+=
amount
self
.
instance
.
save
()
def
to_json
(
self
):
data
=
copy
.
deepcopy
(
self
.
instance
.
state
)
data
[
'plis'
]
=
self
.
plis
...
...
@@ -170,6 +217,11 @@ class StateWrapper:
science
[
'avail_resources'
]
=
wrapper
.
avail_resources
science
[
'progress'
]
=
wrapper
.
progress
for
key
,
university
in
data
.
get
(
'university'
,
{}).
items
():
wrapper
=
self
.
university
(
key
)
university
[
'amount'
]
=
wrapper
.
amount
university
[
'avail_resources'
]
=
wrapper
.
avail_resources
return
data
@
property
...
...
@@ -185,6 +237,8 @@ class StateWrapper:
free
=
self
.
plis
for
task
in
self
.
tasks
:
free
-=
task
.
plis_used
for
university
in
self
.
university_list
:
free
-=
university
.
plis_used
return
free
def
task
(
self
,
key
):
...
...
@@ -221,6 +275,23 @@ class StateWrapper:
for
key
in
SCIENCE
]
def
university
(
self
,
key
):
if
'university'
not
in
self
.
instance
.
state
:
self
.
instance
.
state
[
'university'
]
=
{}
university
=
self
.
instance
.
state
[
'university'
]
if
key
not
in
university
:
university
[
key
]
=
{}
return
UniversityWrapper
(
self
,
key
,
university
[
key
])
@
property
def
university_list
(
self
):
return
[
self
.
university
(
key
)
for
key
in
UNIVERSITY
]
def
initial_state
():
return
{
...
...
cyberlozhkin/game/urls.py
View file @
ffc84782
...
...
@@ -9,4 +9,5 @@ urlpatterns = [
path
(
'toggle_char_mode/'
,
views
.
toggle_char_mode
,
name
=
'toggle_char_mode'
),
path
(
'use_plis/<task_key>/<amount>'
,
views
.
use_plis
,
name
=
'use_plis'
),
path
(
'do_research/<science_key>'
,
views
.
do_research
,
name
=
'do_research'
),
path
(
'use_plis_university/<university_key>/<amount>'
,
views
.
use_plis_university
,
name
=
'use_plis_university'
),
]
cyberlozhkin/game/views.py
View file @
ffc84782
...
...
@@ -34,6 +34,14 @@ def use_plis(request, task_key, amount):
return
JsonResponse
(
state
.
to_json
())
@
login_required
def
use_plis_university
(
request
,
university_key
,
amount
):
amount
=
int
(
amount
)
state
=
get_state
(
request
.
user
)
state
.
use_plis_university
(
university_key
,
amount
)
return
JsonResponse
(
state
.
to_json
())
@
login_required
def
do_research
(
request
,
science_key
):
state
=
get_state
(
request
.
user
)
...
...
cyberlozhkin/static/script.js
View file @
ffc84782
...
...
@@ -84,6 +84,18 @@ function renderScience(key, science) {
}
}
function
renderUniversity
(
key
,
university
)
{
if
(
university
.
amount
!=
null
)
{
$
(
"
#universityAmount
"
+
key
).
html
(
renderExpAmount
(
university
.
amount
));
}
if
(
university
.
plis_used
!=
null
)
{
$
(
"
#universityPlisUsed
"
+
key
).
html
(
university
.
plis_used
);
}
if
(
university
.
avail_resources
!=
null
)
{
$
(
"
#universityResources
"
+
key
).
html
(
renderExpAmount
(
university
.
avail_resources
));
}
}
function
renderState
(
state
)
{
if
(
state
.
exp_char_mode
===
true
)
{
EXP_CHAR_MODE
=
true
;
...
...
@@ -114,6 +126,12 @@ function renderState(state) {
renderScience
(
key
,
science
);
}
}
if
(
state
.
university
!=
null
)
{
for
(
const
[
key
,
university
]
of
Object
.
entries
(
state
.
university
))
{
renderUniversity
(
key
,
university
);
}
}
}
function
update
()
{
...
...
@@ -146,6 +164,15 @@ function doResearch(science_key) {
});
}
function
usePlisUniversity
(
university_key
,
amount
)
{
$
.
ajax
({
url
:
"
use_plis_university/
"
+
university_key
+
"
/
"
+
amount
,
success
:
function
(
response
)
{
renderState
(
response
);
},
});
}
$
(
function
()
{
var
popoverTriggerList
=
[].
slice
.
call
(
document
.
querySelectorAll
(
'
[data-bs-toggle="popover"]
'
));
var
popoverList
=
popoverTriggerList
.
map
(
function
(
popoverTriggerEl
)
{
...
...
cyberlozhkin/templates/game.html
View file @
ffc84782
...
...
@@ -36,6 +36,13 @@
>
Наука
</button>
<button
class=
"nav-link"
data-bs-toggle=
"tab"
data-bs-target=
"#nav-university"
>
МГУ
</button>
</div>
</nav>
<div
class=
"tab-content"
id=
"nav-tabContent"
>
...
...
@@ -45,6 +52,9 @@
<div
class=
"tab-pane fade"
id=
"nav-science"
>
{% include 'tabs/science.html' %}
</div>
<div
class=
"tab-pane fade"
id=
"nav-university"
>
{% include 'tabs/university.html' %}
</div>
</div>
</div>
{% endblock %}
...
...
cyberlozhkin/templates/tabs/university.html
0 → 100644
View file @
ffc84782
{% load template_filters %}
<div
class=
"accordion accordion-flush border"
>
{% for university in state.university_list %}
<div
id=
"universityItem{{ university.key }}"
class=
"accordion-item"
>
<h2
class=
"accordion-header"
>
<button
class=
"accordion-button collapsed"
data-bs-toggle=
"collapse"
data-bs-target=
"#collapseUniversity{{ university.key }}"
>
<div
class=
"d-flex align-items-center justify-content-between w-100 me-3"
>
<strong>
{{ university.name }}
</strong>
<span
id=
"universityAmount{{ university.key }}"
class=
"text-nowrap"
>
{% autoescape off %}
{{ university.amount|format_exp_amount:state.exp_char_mode }}
{% endautoescape %}
</span>
</div>
</button>
</h2>
<div
id=
"collapseUniversity{{ university.key }}"
class=
"accordion-collapse collapse"
>
<div
class=
"accordion-body"
>
<div
class=
"d-flex flex-sm-row flex-column align-items-center justify-content-between w-100"
>
<div
class=
"d-flex flex-column"
>
<span>
{{ university.description }}
</span>
<span
class=
"mt-3"
>
ПЛИСины:
<span
id=
"universityPlisUsed{{ university.key }}"
>
{{ university.plis_used }}
</span>
</span>
<span>
Необходимо: {{ university.required_resource }}
</span>
<span>
Количество:
{% autoescape off %}
<span
id=
"universityResources{{ university.key }}"
>
{{ university.avail_resources|format_exp_amount:state.exp_char_mode }}
</span>
/
{{ university.cost|format_exp_amount:state.exp_char_mode }}
{% endautoescape %}
</span>
</div>
<div
class=
"d-flex flex-column mt-3 mt-sm-0"
>
<div
class=
"btn-group ms-sm-3"
>
<button
class=
"btn btn-success"
onclick=
"usePlisUniversity('{{ university.key }}', 1);"
>
+1
</button>
<button
class=
"btn btn-danger"
onclick=
"usePlisUniversity('{{ university.key }}', -1);"
>
-1
</button>
</div>
<div
class=
"btn-group mt-2 ms-sm-3"
>
<button
class=
"btn btn-success"
onclick=
"usePlisUniversity('{{ university.key }}', 10);"
>
+10
</button>
<button
class=
"btn btn-danger"
onclick=
"usePlisUniversity('{{ university.key }}', -10);"
>
-10
</button>
</div>
<div
class=
"btn-group mt-2 ms-sm-3"
>
<button
class=
"btn btn-success"
onclick=
"usePlisUniversity('{{ university.key }}', 100);"
>
+100
</button>
<button
class=
"btn btn-danger"
onclick=
"usePlisUniversity('{{ university.key }}', -100);"
>
-100
</button>
</div>
</div>
</div>
</div>
</div>
</div>
{% endfor %}
</div>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment