diff --git a/codewars/Adding Big Numbers/AddingBigNumber.js b/codewars/Adding Big Numbers/AddingBigNumber.js new file mode 100644 index 000000000..b0d2f87d6 --- /dev/null +++ b/codewars/Adding Big Numbers/AddingBigNumber.js @@ -0,0 +1,16 @@ +function add(a, b) { + let total = ''; + let base = 0; + let i = a.length - 1; + let j = b.length - 1; + while (i >= 0 || j >= 0 || base > 0) { + const num1 = i >= 0 ? parseInt(a[i], 10) : 0; + const num2 = j >= 0 ? parseInt(b[j], 10) : 0; + const sum = num1 + num2 + base; + base = Math.floor(sum / 10); + total += (sum % 10).toString(); + i--; + j--; + } + return total.split('').reverse().join(''); +} \ No newline at end of file diff --git "a/codewars/Anagram difference/\320\235\320\276\320\274\320\265\321\200 11 - Anagram difference.py" "b/codewars/Anagram difference/\320\235\320\276\320\274\320\265\321\200 11 - Anagram difference.py" new file mode 100644 index 000000000..5103ecf71 --- /dev/null +++ "b/codewars/Anagram difference/\320\235\320\276\320\274\320\265\321\200 11 - Anagram difference.py" @@ -0,0 +1,13 @@ +def anagram_difference(w1, w2): + if type(w1) == str: + w1 = list(w1) + if type(w2) == str: + w2 = list(w2) + ln_w1 = len(w1) + ln_w2 = len(w2) + len_anagram = 0 + for i in w1: + if i in w2: + len_anagram += 1 + w2.remove(i) + return ln_w1 - len_anagram + ln_w2 - len_anagram \ No newline at end of file diff --git "a/codewars/Array Deep Count/\320\235\320\276\320\274\320\265\321\200 7 - Array Deep Count.py" "b/codewars/Array Deep Count/\320\235\320\276\320\274\320\265\321\200 7 - Array Deep Count.py" new file mode 100644 index 000000000..4ea317d0f --- /dev/null +++ "b/codewars/Array Deep Count/\320\235\320\276\320\274\320\265\321\200 7 - Array Deep Count.py" @@ -0,0 +1,6 @@ +def deep_count(a): + answer = len(a) + for i in a: + if type(i) == list: + answer += deep_count(i) + return answer \ No newline at end of file diff --git "a/codewars/Build Tower/\320\235\320\276\320\274\320\265\321\200 6 - Build Tower.py" "b/codewars/Build Tower/\320\235\320\276\320\274\320\265\321\200 6 - Build Tower.py" new file mode 100644 index 000000000..42d85c7be --- /dev/null +++ "b/codewars/Build Tower/\320\235\320\276\320\274\320\265\321\200 6 - Build Tower.py" @@ -0,0 +1,11 @@ +def tower_builder(n_floors): + answer = [] + mx = 1 + 2 * (n_floors - 1) + for i in range(n_floors): + if i == 0: + count_star = 1 + else: + count_star = 1 + 2 * i + count_space = (mx - count_star) // 2 + answer.append(' ' * count_space + '*' * count_star + ' ' * count_space) + return answer \ No newline at end of file diff --git "a/codewars/Convert string to camel case/\320\235\320\276\320\274\320\265\321\200 4 - Convert string to camel case.py" "b/codewars/Convert string to camel case/\320\235\320\276\320\274\320\265\321\200 4 - Convert string to camel case.py" new file mode 100644 index 000000000..a66a299dc --- /dev/null +++ "b/codewars/Convert string to camel case/\320\235\320\276\320\274\320\265\321\200 4 - Convert string to camel case.py" @@ -0,0 +1,12 @@ +def to_camel_case(text): + answer = '' + k = False + for i in range(len(text)): + if text[i] == '_' or text[i] == '-': + k = True + elif k: + answer += text[i].upper() + k = False + else: + answer += text[i] + return answer diff --git "a/codewars/Duplicate Encoder/\320\235\320\276\320\274\320\265\321\200 1 - Duplicate Encoder.py" "b/codewars/Duplicate Encoder/\320\235\320\276\320\274\320\265\321\200 1 - Duplicate Encoder.py" new file mode 100644 index 000000000..02a487ec7 --- /dev/null +++ "b/codewars/Duplicate Encoder/\320\235\320\276\320\274\320\265\321\200 1 - Duplicate Encoder.py" @@ -0,0 +1,12 @@ +def duplicate_encode(word): + word_lower = word.lower() + count_letter = {} + answer = '' + for i in word_lower: + if i not in count_letter: + count_letter[i] = word_lower.count(i) + if count_letter[i] > 1: + answer += ')' + else: + answer += '(' + return answer \ No newline at end of file diff --git "a/codewars/Find the missing letter/\320\235\320\276\320\274\320\265\321\200 2 - Find the missing letter.py" "b/codewars/Find the missing letter/\320\235\320\276\320\274\320\265\321\200 2 - Find the missing letter.py" new file mode 100644 index 000000000..0177b539e --- /dev/null +++ "b/codewars/Find the missing letter/\320\235\320\276\320\274\320\265\321\200 2 - Find the missing letter.py" @@ -0,0 +1,6 @@ +def find_missing_letter(chars): + print(ord('a')) + print(ord('b')) + for i in range(len(chars) - 1): + if ord(chars[i + 1]) - ord(chars[i]) != 1: + return chr(ord(chars[i]) + 1) \ No newline at end of file diff --git a/codewars/Flatten a Nested Map/FlattenANestedMap.js b/codewars/Flatten a Nested Map/FlattenANestedMap.js new file mode 100644 index 000000000..1757a08c0 --- /dev/null +++ b/codewars/Flatten a Nested Map/FlattenANestedMap.js @@ -0,0 +1,13 @@ +function flattenMap(object) { + function iter(part, keys) { + Object.keys(part).forEach(function (k) { + if (part[k] !== null && !Array.isArray(part[k]) && typeof part[k] === 'object') { + return iter(part[k], keys.concat(k)); + } + flat[keys.concat(k).join('/')] = part[k]; + }); + } + var flat = {}; + iter(object, []); + return flat; +} \ No newline at end of file diff --git "a/codewars/Fun with tree - max sum/\320\235\320\276\320\274\320\265\321\200 20 - Fun with trees max sum.py" "b/codewars/Fun with tree - max sum/\320\235\320\276\320\274\320\265\321\200 20 - Fun with trees max sum.py" new file mode 100644 index 000000000..0295a66ee --- /dev/null +++ "b/codewars/Fun with tree - max sum/\320\235\320\276\320\274\320\265\321\200 20 - Fun with trees max sum.py" @@ -0,0 +1,14 @@ +from preloaded import TreeNode + +def max_sum(root: TreeNode): + answer = 0 + if root is None: + return answer + answer += root.value + left_root = max_sum(root.left) + right_root = max_sum(root.right) + if left_root == 0 and right_root != 0: + return answer + right_root + elif right_root == 0 and left_root != 0: + return answer + left_root + return answer + max(left_root, right_root) \ No newline at end of file diff --git "a/codewars/Linked Lists - Sorted Insert/\320\235\320\276\320\274\320\265\321\200 21 - Linked Lists - Sorted Insert.py" "b/codewars/Linked Lists - Sorted Insert/\320\235\320\276\320\274\320\265\321\200 21 - Linked Lists - Sorted Insert.py" new file mode 100644 index 000000000..48a34d985 --- /dev/null +++ "b/codewars/Linked Lists - Sorted Insert/\320\235\320\276\320\274\320\265\321\200 21 - Linked Lists - Sorted Insert.py" @@ -0,0 +1,23 @@ +""" For your information: +class Node(object): + def __init__(self, data): + self.data = data + self.next = None +""" + +def sorted_insert(head, data): + x = head + print(data) + print(head) + if not head: + return Node(data) + while True: + print(head.data) + if head.data > data: + head.data, data = data, head.data + print(head.data, data) + if head.next is None: + head.next = Node(data) + break + head = head.next + return x \ No newline at end of file diff --git a/codewars/Merge two arrays/MergeTwoArrays.js b/codewars/Merge two arrays/MergeTwoArrays.js new file mode 100644 index 000000000..fd7c0e757 --- /dev/null +++ b/codewars/Merge two arrays/MergeTwoArrays.js @@ -0,0 +1,21 @@ +function mergeArrays(a, b) { + console.log(a, b); + console.log(a.length, b.length); + let i = 0; + let answer = []; + while (i < a.length && i < b.length) { + answer.push(a[i]); + answer.push(b[i]); + i++; + } + while (i < a.length) { + answer.push(a[i]); + i++; + } + while (i < b.length) { + answer.push(b[i]) + i++; + } + console.log(answer); + return answer; + } \ No newline at end of file diff --git "a/codewars/Moving Zeros To The End/\320\235\320\276\320\274\320\265\321\200 3 - Moving Zeros To The End.py" "b/codewars/Moving Zeros To The End/\320\235\320\276\320\274\320\265\321\200 3 - Moving Zeros To The End.py" new file mode 100644 index 000000000..7893747d9 --- /dev/null +++ "b/codewars/Moving Zeros To The End/\320\235\320\276\320\274\320\265\321\200 3 - Moving Zeros To The End.py" @@ -0,0 +1,9 @@ +def move_zeros(lst): + arr_no_zero = [] + arr_zero = [] + for i in lst: + if i == 0: + arr_zero.append(i) + else: + arr_no_zero.append(i) + return arr_no_zero + arr_zero \ No newline at end of file diff --git "a/codewars/Permutations/\320\235\320\276\320\274\320\265\321\200 8 - So Many Permutations!.py" "b/codewars/Permutations/\320\235\320\276\320\274\320\265\321\200 8 - So Many Permutations!.py" new file mode 100644 index 000000000..8a5e01d57 --- /dev/null +++ "b/codewars/Permutations/\320\235\320\276\320\274\320\265\321\200 8 - So Many Permutations!.py" @@ -0,0 +1,7 @@ +import itertools +def permutations(s): + answer = [] + a = itertools.permutations(s) + for i in a: + answer.append(''.join(i)) + return list(set(answer)) diff --git "a/codewars/Product of consecutive Fib numbers/\320\235\320\276\320\274\320\265\321\200 14 - Product of consecutive Fib numbers.py" "b/codewars/Product of consecutive Fib numbers/\320\235\320\276\320\274\320\265\321\200 14 - Product of consecutive Fib numbers.py" new file mode 100644 index 000000000..a3c17620d --- /dev/null +++ "b/codewars/Product of consecutive Fib numbers/\320\235\320\276\320\274\320\265\321\200 14 - Product of consecutive Fib numbers.py" @@ -0,0 +1,32 @@ +from math import sqrt + + +def fib_number(n): + if n > 0: + n += 1 + a = 0 + b = 1 + if n < 0: + print("Incorrect input") + elif n == 0: + return a + elif n == 1: + return b + else: + for i in range(2, n): + c = a + b + a = b + b = c + return b + + +def product_fib(_prod): + print(_prod) + k = 0 + while True: + if fib_number(k) * fib_number(k + 1) == _prod: + return [fib_number(k), fib_number(k + 1), True] + elif fib_number(k) * fib_number(k + 1) > _prod: + return [fib_number(k), fib_number(k + 1), False] + else: + k += 1 \ No newline at end of file diff --git "a/codewars/Simple Pig Latin/\320\235\320\276\320\274\320\265\321\200 18 - Simple Pig Latin.py" "b/codewars/Simple Pig Latin/\320\235\320\276\320\274\320\265\321\200 18 - Simple Pig Latin.py" new file mode 100644 index 000000000..9bdfff59b --- /dev/null +++ "b/codewars/Simple Pig Latin/\320\235\320\276\320\274\320\265\321\200 18 - Simple Pig Latin.py" @@ -0,0 +1,15 @@ +def pig_it(text): + arr_letter = [chr(i) for i in range(97, 123)] + x = '' + answer = '' + for i in range(len(text)): + if text[i].lower() in arr_letter: + x += text[i] + if i == len(text) - 1: + answer += x[1:] + x[0] + 'ay' + else: + if text[i].lower() not in arr_letter and x: + answer += x[1:] + x[0] + 'ay' + x = '' + answer += text[i] + return answer diff --git "a/codewars/Snail/\320\235\320\276\320\274\320\265\321\200 16 - Snail.py" "b/codewars/Snail/\320\235\320\276\320\274\320\265\321\200 16 - Snail.py" new file mode 100644 index 000000000..37153fdd6 --- /dev/null +++ "b/codewars/Snail/\320\235\320\276\320\274\320\265\321\200 16 - Snail.py" @@ -0,0 +1,30 @@ +def snail(snail_map): + print(snail_map) + if snail_map == [[]]: + return [] + answer = [] + x_mn, y_mn = 0, 0 + x_mx, y_mx = len(snail_map) - 1, len(snail_map) - 1 + y_now, x_now = 0, 0 + while True: + answer.append(snail_map[y_now][x_now]) + y_mn += 1 + while x_now < x_mx: + x_now += 1 + answer.append(snail_map[y_now][x_now]) + x_mx -= 1 + while y_now < y_mx: + y_now += 1 + answer.append(snail_map[y_now][x_now]) + y_mx -= 1 + while x_now > x_mn: + x_now -= 1 + answer.append(snail_map[y_now][x_now]) + x_mn += 1 + while y_now > y_mn: + y_now -= 1 + answer.append(snail_map[y_now][x_now]) + if x_mn > x_mx or y_mn > y_mx: + break + x_now += 1 + return answer \ No newline at end of file diff --git "a/codewars/Sum of Digits - Digital Root/\320\235\320\276\320\274\320\265\321\200 5 - Sum of Digits.py" "b/codewars/Sum of Digits - Digital Root/\320\235\320\276\320\274\320\265\321\200 5 - Sum of Digits.py" new file mode 100644 index 000000000..e293b8f52 --- /dev/null +++ "b/codewars/Sum of Digits - Digital Root/\320\235\320\276\320\274\320\265\321\200 5 - Sum of Digits.py" @@ -0,0 +1,8 @@ +def digital_root(n): + answer = 0 + while n > 0: + answer += n % 10 + n //= 10 + if answer // 10 != 0: + answer = digital_root(answer) + return answer diff --git "a/codewars/Sum of Intervals/\320\235\320\276\320\274\320\265\321\200 10 - Sum of Intervals.py" "b/codewars/Sum of Intervals/\320\235\320\276\320\274\320\265\321\200 10 - Sum of Intervals.py" new file mode 100644 index 000000000..87c093ed2 --- /dev/null +++ "b/codewars/Sum of Intervals/\320\235\320\276\320\274\320\265\321\200 10 - Sum of Intervals.py" @@ -0,0 +1,13 @@ +def sum_of_intervals(intervals): + sum_intervals = 0 + intervals = sorted(intervals, key=lambda x: x[0]) + interval_arr = [] + for i in intervals: + if not interval_arr or interval_arr[-1][1] < i[0]: + interval_arr.append([i[0], i[1]]) + else: + if interval_arr[-1][1] < i[1]: + interval_arr[-1][1] = i[1] + for i in interval_arr: + sum_intervals += i[1] - i[0] + return sum_intervals \ No newline at end of file diff --git "a/codewars/Sum of pairs/\320\235\320\276\320\274\320\265\321\200 12 - Sum of Pairs.py" "b/codewars/Sum of pairs/\320\235\320\276\320\274\320\265\321\200 12 - Sum of Pairs.py" new file mode 100644 index 000000000..626a3292b --- /dev/null +++ "b/codewars/Sum of pairs/\320\235\320\276\320\274\320\265\321\200 12 - Sum of Pairs.py" @@ -0,0 +1,6 @@ +def sum_pairs(ints, s): + answer = {} + for i in ints: + if s - i in answer: + return [s - i, i] + answer[i] = True \ No newline at end of file diff --git "a/codewars/Tic-Tac-Toe Checker/\320\235\320\276\320\274\320\265\321\200 22 - Tic-Tac-Toe Checker.py" "b/codewars/Tic-Tac-Toe Checker/\320\235\320\276\320\274\320\265\321\200 22 - Tic-Tac-Toe Checker.py" new file mode 100644 index 000000000..911eae074 --- /dev/null +++ "b/codewars/Tic-Tac-Toe Checker/\320\235\320\276\320\274\320\265\321\200 22 - Tic-Tac-Toe Checker.py" @@ -0,0 +1,20 @@ +def is_solved(board): + if board[0][0] == board[0][1] == board[0][2] and board[0][0] != 0: + return board[0][0] + if board[1][0] == board[1][1] == board[1][2] and board[1][0] != 0: + return board[1][0] + if board[2][0] == board[2][1] == board[2][2] and board[2][0] != 0: + return board[2][0] + if board[0][0] == board[1][0] == board[2][0] and board[0][0] != 0: + return board[0][0] + if board[0][1] == board[1][1] == board[2][1] and board[0][1] != 0: + return board[0][1] + if board[0][2] == board[1][2] == board[2][2] and board[0][2] != 0: + return board[0][2] + if board[0][0] == board[1][1] == board[2][2] and board[0][0] != 0: + return board[0][0] + if board[0][2] == board[1][1] == board[2][0] and board[0][2] != 0: + return board[0][2] + if 0 in board[0] or 0 in board[1] or 0 in board[2]: + return -1 + return 0 \ No newline at end of file diff --git "a/codewars/Valid Parentheses/\320\235\320\276\320\274\320\265\321\200 13 - Valid Parentheses.py" "b/codewars/Valid Parentheses/\320\235\320\276\320\274\320\265\321\200 13 - Valid Parentheses.py" new file mode 100644 index 000000000..4d3db0b48 --- /dev/null +++ "b/codewars/Valid Parentheses/\320\235\320\276\320\274\320\265\321\200 13 - Valid Parentheses.py" @@ -0,0 +1,12 @@ +def valid_parentheses(string): + count_open_brackets = 0 + for i in string: + if i == '(': + count_open_brackets += 1 + elif i == ')': + if count_open_brackets == 0: + return False + count_open_brackets -= 1 + if count_open_brackets == 0: + return True + return False \ No newline at end of file diff --git "a/codewars/Where my anagrams at/\320\235\320\276\320\274\320\265\321\200 15 - Where my anagrams at.py" "b/codewars/Where my anagrams at/\320\235\320\276\320\274\320\265\321\200 15 - Where my anagrams at.py" new file mode 100644 index 000000000..539c7306c --- /dev/null +++ "b/codewars/Where my anagrams at/\320\235\320\276\320\274\320\265\321\200 15 - Where my anagrams at.py" @@ -0,0 +1,15 @@ +def anagram_difference(w1, w2): + if type(w1) == str: + w1 = list(w1) + if type(w2) == str: + w2 = list(w2) + ln_w1 = len(w1) + ln_w2 = len(w2) + len_anagram = 0 + for i in w1: + if i in w2: + len_anagram += 1 + w2.remove(i) + if len_anagram == ln_w1 and len_anagram == ln_w2: + return True + return False \ No newline at end of file diff --git a/rpgsaga/saga/src/Lab1/formuls.ts b/rpgsaga/saga/src/Lab1/formuls.ts new file mode 100644 index 000000000..06624f907 --- /dev/null +++ b/rpgsaga/saga/src/Lab1/formuls.ts @@ -0,0 +1,19 @@ +export function formula(x: number, a: number = 1.6): number { + return Math.pow(a, (Math.pow(x, 2) - 1)) - Math.log10(Math.pow(x, 2) - 1) + Math.pow((Math.pow(x, 2) - 1), (1/3)); +} + +export function taskA(a: number, xstart: number, xend: number, xstep: number): number[] { + const y: number[] = []; + for (let i = xstart; i <= xend; i += xstep) { + y.push(formula(i, a)); + } + return y; +} + +export function taskB(a: number, arr: number[]): number[] { + const y: number[] = []; + for (let i of arr) { + y.push(formula(i, a)); + } + return y; +} \ No newline at end of file diff --git a/rpgsaga/saga/src/Lab1/output_lab1.ts b/rpgsaga/saga/src/Lab1/output_lab1.ts new file mode 100644 index 000000000..10224f217 --- /dev/null +++ b/rpgsaga/saga/src/Lab1/output_lab1.ts @@ -0,0 +1,19 @@ +import { formula, taskA, taskB } from "./formuls"; + +const a: number = 1.6; +console.log("Задача А"); +let xstart: number = 1.2; +let xend: number = 3.7; +let xstep: number = 0.5; +let yTaskA: number[] = taskA(a, xstart, xend, xstep); +for (let i of yTaskA) { + console.log(`y = ${i}`); +} + +console.log("Задача B"); +let arr: number[] = [1.28, 1.36, 2.47, 3.68, 4.56]; +let yTaskB: number[] = taskB(a, arr); +for (let i of yTaskB) { + console.log(`y = ${i}`); +} +console.log(formula(4.56)) \ No newline at end of file diff --git a/rpgsaga/saga/src/Lab2/Person_Class.ts b/rpgsaga/saga/src/Lab2/Person_Class.ts new file mode 100644 index 000000000..9119d5816 --- /dev/null +++ b/rpgsaga/saga/src/Lab2/Person_Class.ts @@ -0,0 +1,56 @@ +export abstract class Person { + private _name: String; + private _age: number; + private _gender: String; + private _height: number; + private _weight: number; + constructor( + name: String, + age: number, + gender: String, + height: number, + weight: number + ) { + this._name = name; + this.age = age; + this.gender = gender; + this._height = height; + this._weight = weight; + } + + public set age(value: number) { + if (value < 0 || value > 110) { + throw new Error(`Incorrect age`); + } else { + this._age = value; + } + } + + public set gender(value: String) { + if (value == "m" || value == "man" || value == "w" || value == "woman") { + this._gender = value; + } else { + throw new Error(`Incorrect gender`); + } + } + + public get name(): String { + return this._name; + } + + public get age(): number { + return this._age; + } + + public get gender(): String { + return this._gender; + } + + public get height(): number { + return this._height; + } + + public get weight(): number { + return this._weight; + } +} diff --git a/rpgsaga/saga/src/Lab2/Volleyball_player_Class.ts b/rpgsaga/saga/src/Lab2/Volleyball_player_Class.ts new file mode 100644 index 000000000..67c5cdbe1 --- /dev/null +++ b/rpgsaga/saga/src/Lab2/Volleyball_player_Class.ts @@ -0,0 +1,63 @@ +import { Person } from "./Person_Class"; + +export class Volleyball_Player extends Person{ + private _position: String; + private _place_jumping: number; + private _running_jumping: number; + private _team: String; + constructor( + name: String, + age: number, + gender: String, + height: number, + weight: number, + position: String, + place_jumping: number, + running_jumping: number, + team: String + ) { + super(name, age, gender, height, weight) + this._position = position; + this.place_jumping = place_jumping; + this.running_jumping = running_jumping; + this._team = team; + } + + public set place_jumping(value: number) { + if (value > this.height) { + this._place_jumping = value; + } else { + throw new Error(`Incorrect place_jumping`) + } + } + + public set running_jumping(value: number) { + if (value > this.height) { + this._running_jumping = value; + } else { + throw new Error(`Incorrect running_jumping`) + } + } + + public get position(): String { + return this._position; + } + + public get running_jumping(): number { + return this._running_jumping; + } + + public get place_jumping(): number { + return this._place_jumping; + } + + public get team(): String { + return this._team; + } + + public view_player_parameters(): String { + return `Player ${this.name}:\n + Takeoff from a standing jump: ${this._place_jumping - this.height}\n + Takeoff on a running jump: ${this._running_jumping - this.height}` + } +} \ No newline at end of file diff --git a/rpgsaga/saga/src/Lab2/output_lab2.ts b/rpgsaga/saga/src/Lab2/output_lab2.ts new file mode 100644 index 000000000..e58a7e581 --- /dev/null +++ b/rpgsaga/saga/src/Lab2/output_lab2.ts @@ -0,0 +1,9 @@ +import { Volleyball_Player } from "./Volleyball_player_Class"; + +const human_1 = new Volleyball_Player("Ivan", 19, 'm', 181, 70, "Setter", 295, 320, "ISUCT"); +const humsn_2 = new Volleyball_Player("Maria", 17, "woman", 170, 55, "Libero", 210, 240, 'ISUCT'); +console.log(human_1.view_player_parameters()); +console.log(humsn_2.view_player_parameters()); +humsn_2.place_jumping = 220; +humsn_2.running_jumping = 250; +console.log(humsn_2.view_player_parameters()); \ No newline at end of file diff --git a/rpgsaga/saga/src/index.ts b/rpgsaga/saga/src/index.ts deleted file mode 100644 index 7bc4a71de..000000000 --- a/rpgsaga/saga/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -console.log('Hello world'); diff --git a/rpgsaga/saga/src/lab3/Clasees/Class_hit.ts b/rpgsaga/saga/src/lab3/Clasees/Class_hit.ts new file mode 100644 index 000000000..2901bed2a --- /dev/null +++ b/rpgsaga/saga/src/lab3/Clasees/Class_hit.ts @@ -0,0 +1,45 @@ +import { Debuff } from "./Classes_debuff/Debuff"; + +export class Hit{ + private _damage: number; + private _type_damage: String; + private _control: boolean; + private _debuff: Debuff + constructor ( + damage: number, + type_damage: String, + control: boolean, + ) { + this._damage = damage; + this._type_damage = type_damage; + this._control = control; + }; + + public set damage(value: number) { + this._damage = value; + } + + public set control(value: boolean) { + this._control = value; + } + + public set debuff(value: Debuff) { + this._debuff = value; + } + + public get damage(): number { + return this._damage; + } + + public get type_damage(): String { + return this._type_damage; + } + + public get control(): boolean { + return this._control; + } + + public get debuff(): Debuff { + return this._debuff + } +} \ No newline at end of file diff --git a/rpgsaga/saga/src/lab3/Clasees/Classes_Battle.ts b/rpgsaga/saga/src/lab3/Clasees/Classes_Battle.ts new file mode 100644 index 000000000..04724c0dc --- /dev/null +++ b/rpgsaga/saga/src/lab3/Clasees/Classes_Battle.ts @@ -0,0 +1,93 @@ +import { Player } from "./Classes_players/Player"; +import { Hit } from "./Class_hit"; +import { create_player } from "../Utils/create_player"; + +export class battle{ + private _count_players: number; + private _arr_players: (Player)[] = []; + constructor( + count_players: number + ) { + this._count_players = count_players; + for (let i = 0; i < count_players; i++) { + let player: Player = create_player() + console.log(`Игрок номер ${i + 1}: ${player.view_info()}`) + this._arr_players.push(player) + } + } + + public start_game() { + let count: number = 0; + while (this._arr_players.length != 1) { + count++; + console.log(); + console.log(`--------------Раунд номер ${count}--------------`); + console.log(); + let winner: Player[] = []; + for (let i = 0; i < this._count_players - 1; i += 2) { + winner.push(this.fight(this._arr_players[i], this._arr_players[i + 1])) + } + if (this._count_players % 2 != 0) { + winner.push(this._arr_players[this._count_players - 1]) + } + this._arr_players = winner; + this._count_players = this._arr_players.length; + for (let player of this._arr_players) { + player.clear_hero(); + } + + } + console.log(); + console.log(`${this._arr_players[0].role_name()} - единственный выживший`); + } + + public fight(pers_1: Player, pers_2: Player) { + console.log(); + console.log(`${pers_1.role_name()} VS ${pers_2.role_name()}`); + console.log(); + let count: number = 1; + while (true) { + if (count % 2 != 0) { + count = this.one_hit(count, pers_1, pers_2); + } else { + count = this.one_hit(count, pers_2, pers_1); + } + if (count == -1) { + if (pers_1.health <= 0) { + return pers_2; + } else { + return pers_1; + } + } else { + count++; + } + } + } + + private one_hit(count: number, attacker: Player, defending: Player): number { + console.log(); + console.log(`-------Ход ${count}-------`); + console.log(); + attacker.activate_debaffs(); + if (attacker.health <= 0) { + console.log(`${attacker.role} '${attacker.name}' умер`) + return -1; + } + if (attacker.stuuned_states == false) { + console.log(`${attacker.role} '${attacker.name}' (${attacker.health} HP) атакует ${defending.role} '${defending.name}' (${defending.health} HP)`); + let attack: Hit = attacker.attack(); + console.log(`${attacker.role} '${attacker.name}' наносит ${attack.damage} оружием '${attacker.name_weapon}'`) + console.log(); + defending.taking_damage(attack); + if (defending.health <= 0) { + console.log(`${defending.role} '${defending.name}' умер`); + return -1; + } + } else { + attacker.stuuned_states = false; + console.log(`${attacker.role} '${attacker.name}' (${attacker.health}) пропускает ход`) + defending.activate_debaffs(); + } + return count; + } +} \ No newline at end of file diff --git a/rpgsaga/saga/src/lab3/Clasees/Classes_abilities/Abilities/Archer_ability.ts b/rpgsaga/saga/src/lab3/Clasees/Classes_abilities/Abilities/Archer_ability.ts new file mode 100644 index 000000000..467532813 --- /dev/null +++ b/rpgsaga/saga/src/lab3/Clasees/Classes_abilities/Abilities/Archer_ability.ts @@ -0,0 +1,9 @@ +import { Player } from "../../Classes_players/Player"; +import { Hit } from "../../Class_hit"; +import { ability_names } from "../../../Enums/enum_abilities"; + +export function activation_archer_ability(player: Player, hit: Hit): Hit { + hit.damage = Math.floor(hit.damage * 1.5); + console.log(`${player.role} активирует способность ${ability_names.archer_ability}`) + return hit; +} diff --git a/rpgsaga/saga/src/lab3/Clasees/Classes_abilities/Abilities/Mage_ability.ts b/rpgsaga/saga/src/lab3/Clasees/Classes_abilities/Abilities/Mage_ability.ts new file mode 100644 index 000000000..022081ae7 --- /dev/null +++ b/rpgsaga/saga/src/lab3/Clasees/Classes_abilities/Abilities/Mage_ability.ts @@ -0,0 +1,10 @@ +import { Player } from "../../Classes_players/Player"; +import { Hit } from "../../Class_hit"; +import { Burning } from "../../Classes_debuff/Debuffs/Burning"; +import { ability_names } from "../../../Enums/enum_abilities"; + +export function activation_mage_ability(player: Player, hit: Hit): Hit { + hit.debuff = new Burning(); + console.log(`${player.role} активирует способность ${ability_names.mage_ability}`) + return hit; +} \ No newline at end of file diff --git a/rpgsaga/saga/src/lab3/Clasees/Classes_abilities/Abilities/Staff_Santa_ability.ts b/rpgsaga/saga/src/lab3/Clasees/Classes_abilities/Abilities/Staff_Santa_ability.ts new file mode 100644 index 000000000..c3ef75880 --- /dev/null +++ b/rpgsaga/saga/src/lab3/Clasees/Classes_abilities/Abilities/Staff_Santa_ability.ts @@ -0,0 +1,9 @@ +import { Player } from "../../Classes_players/Player"; +import { Hit } from "../../Class_hit"; +import { ability_names } from "../../../Enums/enum_abilities"; + +export function activation_staff_santa_ability(player: Player, hit: Hit): Hit { + hit.control = true; + console.log(`${player.role} активирует способность ${ability_names.staff_santa}`) + return hit; +} \ No newline at end of file diff --git a/rpgsaga/saga/src/lab3/Clasees/Classes_abilities/Abilities/Warrior_ability.ts b/rpgsaga/saga/src/lab3/Clasees/Classes_abilities/Abilities/Warrior_ability.ts new file mode 100644 index 000000000..7e2cc0f77 --- /dev/null +++ b/rpgsaga/saga/src/lab3/Clasees/Classes_abilities/Abilities/Warrior_ability.ts @@ -0,0 +1,9 @@ +import { Player } from "../../Classes_players/Player"; +import { Hit } from "../../Class_hit"; +import { ability_names } from "../../../Enums/enum_abilities"; + +export function activation_warriro_ability(player: Player, hit: Hit): Hit { + hit.damage = hit.damage + Math.floor((player.physical_resistance + player.magic_resistance) * 0.5); + console.log(`${player.role} активирует способность ${ability_names.warrior_ability}`) + return hit; +} \ No newline at end of file diff --git a/rpgsaga/saga/src/lab3/Clasees/Classes_abilities/Ability.ts b/rpgsaga/saga/src/lab3/Clasees/Classes_abilities/Ability.ts new file mode 100644 index 000000000..403512a0c --- /dev/null +++ b/rpgsaga/saga/src/lab3/Clasees/Classes_abilities/Ability.ts @@ -0,0 +1,19 @@ +export class Ability{ + private _change: number; + private _name_ability: String; + constructor( + change: number, + name_ability: string + ) { + this._change = change; + this._name_ability = name_ability; + } + + public get change_ability(): number { + return this._change + } + + public get name_ability(): String { + return this._name_ability + } +} \ No newline at end of file diff --git a/rpgsaga/saga/src/lab3/Clasees/Classes_abilities/using_abilities.ts b/rpgsaga/saga/src/lab3/Clasees/Classes_abilities/using_abilities.ts new file mode 100644 index 000000000..9c29ca9de --- /dev/null +++ b/rpgsaga/saga/src/lab3/Clasees/Classes_abilities/using_abilities.ts @@ -0,0 +1,26 @@ +import { Ability } from "./Ability"; +import { Player } from "../Classes_players/Player"; +import { Hit } from "../Class_hit"; +import { check_operation } from "../../Utils/check_operation"; +import { activation_archer_ability } from "./Abilities/Archer_ability"; +import { activation_mage_ability } from "./Abilities/Mage_ability"; +import { activation_staff_santa_ability } from "./Abilities/Staff_Santa_ability"; +import { activation_warriro_ability } from "./Abilities/Warrior_ability"; +import { ability_names } from "../../Enums/enum_abilities"; + +export function activation_ability(abilities: (Ability)[], player: Player, hit: Hit) { + for (let ability of abilities) { + if (check_operation(ability.change_ability)) { + if (ability.name_ability == ability_names.archer_ability) { + hit = activation_archer_ability(player, hit); + } else if (ability.name_ability == ability_names.warrior_ability) { + hit = activation_warriro_ability(player, hit); + } else if (ability.name_ability == ability_names.mage_ability) { + hit = activation_mage_ability(player, hit); + } else if (ability.name_ability == ability_names.staff_santa) { + hit = activation_staff_santa_ability(player, hit); + } + } + } + return hit; +} \ No newline at end of file diff --git a/rpgsaga/saga/src/lab3/Clasees/Classes_debuff/Debuff.ts b/rpgsaga/saga/src/lab3/Clasees/Classes_debuff/Debuff.ts new file mode 100644 index 000000000..d0fa5fd7f --- /dev/null +++ b/rpgsaga/saga/src/lab3/Clasees/Classes_debuff/Debuff.ts @@ -0,0 +1,53 @@ +import { Hit } from "../Class_hit"; + +export class Debuff{ + private _name_debuff: String; + private _total_duration: number; + private _duration: number; + private _damage: number; + private _type_damage: String; + private _stunning: boolean; + constructor( + name_debuff: String, + duration: number, + damage: number, + type_damage: String, + stunning: boolean + ) { + this._name_debuff = name_debuff; + this._total_duration = duration; + this._duration = duration; + this._damage = damage; + this._type_damage = type_damage; + this._stunning = stunning; + } + + public set duration(value: number) { + this._duration = value; + } + + public get name_debuff(): String { + return this._name_debuff; + } + + public get total_duration(): number { + return this._total_duration; + } + + public get duration(): number { + return this._duration; + } + + public get damage(): number { + return this._damage + } + + public get type_damage(): String { + return this._type_damage + } + + public activate_debuff(): Hit { + const hit = new Hit(this._damage, this._type_damage, this._stunning); + return hit; + } +} \ No newline at end of file diff --git a/rpgsaga/saga/src/lab3/Clasees/Classes_debuff/Debuffs/Burning.ts b/rpgsaga/saga/src/lab3/Clasees/Classes_debuff/Debuffs/Burning.ts new file mode 100644 index 000000000..65e12a5ea --- /dev/null +++ b/rpgsaga/saga/src/lab3/Clasees/Classes_debuff/Debuffs/Burning.ts @@ -0,0 +1,9 @@ +import { Debuff } from "../Debuff"; +import { damage_types } from "../../../Enums/enum_damage_types"; +import { debuff_names } from "../../../Enums/enum_debuff"; + +export class Burning extends Debuff{ + constructor() { + super(debuff_names.burning, 3, 15, damage_types.mag, false); + } +} \ No newline at end of file diff --git a/rpgsaga/saga/src/lab3/Clasees/Classes_players/Player.ts b/rpgsaga/saga/src/lab3/Clasees/Classes_players/Player.ts new file mode 100644 index 000000000..ea0026af2 --- /dev/null +++ b/rpgsaga/saga/src/lab3/Clasees/Classes_players/Player.ts @@ -0,0 +1,163 @@ +import { Weapon } from "../Classes_weapons/Weapon"; +import { Hit } from "../Class_hit"; +import { Ability } from "../Classes_abilities/Ability"; +import { activation_ability } from "../Classes_abilities/using_abilities"; +import { Debuff } from "../Classes_debuff/Debuff"; +import { damage_types } from "../../Enums/enum_damage_types"; + +export class Player{ + private _name: String; + private _role: String; + private _weapon: Weapon; + private _mx_health: number; + private _health: number; + private _physical_resistance: number; + private _magic_resistance: number; + private _stuuned_states: boolean = false; + private _ability: Ability; + private _debuffs: (Debuff)[] = []; + constructor( + name: String, + role: String, + weapon: Weapon, + health: number, + physical_resistance: number, + magic_resistance: number, + ability: Ability + ) { + this._name = name; + this._role = role; + this._weapon = weapon; + this._mx_health = health; + this._health = health; + this._physical_resistance = (physical_resistance + weapon.increase_phys_resist) * weapon.multiplier_phys_resist; + this._magic_resistance = (magic_resistance + weapon.increase_magic_resist) * weapon.multiplier_magic_resist; + this._ability = ability; + } + + public set health(hp: number) { + this._health = hp; + } + + public set stuuned_states(state: boolean) { + this._stuuned_states = state; + } + + public set physical_resistance(value: number) { + this._physical_resistance = value; + } + + public set magic_resistance(value: number) { + this._magic_resistance = value; + } + + public add_debuff(debuff: Debuff){ + this._debuffs.push(debuff); + } + + public clear_debaffs() { + this._debuffs.length = 0; + } + + public get name(): String { + return this._name; + } + + public get role(): String { + return this._role; + } + + public get health(): number { + return this._health; + } + + public get damage(): number { + return this._weapon.damage + } + + public get type_damage(): String { + return this._weapon.type_damage + } + + public get name_weapon(): String { + return this._weapon.name; + } + + public get stuuned_states(): boolean { + return this._stuuned_states; + } + + public get physical_resistance(): number { + return this._physical_resistance; + } + + public get magic_resistance(): number { + return this._magic_resistance; + } + + public get debuffs(): (Debuff)[] { + return this._debuffs + } + + public role_name(): String { + return `${this._role} '${this._name}'` + } + + public attack(): Hit { + let hit = new Hit(this._weapon.damage, this._weapon.type_damage, false); + hit = activation_ability([this._ability, this._weapon.ability], this, hit); + return hit; + } + + public taking_damage(hit: Hit) { + if (typeof hit.debuff !== 'undefined') { + this.add_debuff(hit.debuff); + } + this.activate_debaffs(); + if (hit.control) { + this._stuuned_states = true; + } + if (hit.type_damage == damage_types.pure) { + hit.damage = hit.damage; + } else if (hit.type_damage == damage_types.phys) { + hit.damage = Math.floor(hit.damage * ((100 - this.physical_resistance) / 100)); + } else if (hit.type_damage == damage_types.mag){ + hit.damage = Math.floor(hit.damage * ((100 - this.magic_resistance) / 100)); + } + this._health -= hit.damage; + console.log(`${this.role} (${this._health} HP) получил ${hit.damage} урона`); + } + + public taking_damage_from_debuff(debuff: Debuff, hit: Hit) { + if (hit.control) { + this._stuuned_states = true; + } + if (hit.type_damage == damage_types.pure) { + hit.damage = hit.damage; + } else if (hit.type_damage == damage_types.phys) { + hit.damage = Math.floor(hit.damage * ((100 - this.physical_resistance) / 100)); + } else if (hit.type_damage == damage_types.mag){ + hit.damage = Math.floor(hit.damage * ((100 - this.magic_resistance) / 100)); + } + this._health -= hit.damage; + console.log(`${this.role} (${this._health} HP) получил ${hit.damage} урона от ${debuff.name_debuff} (до окончания ${debuff.duration} ход(a))`); + } + + public activate_debaffs() { + for (let debuff of this._debuffs) { + if (debuff.duration > 0) { + debuff.duration = debuff.duration - 1; + this.taking_damage_from_debuff(debuff, debuff.activate_debuff()); + } + } + } + + public clear_hero() { + this._health = this._mx_health; + this._debuffs = []; + } + + public view_info() { + return `Роль: ${this._role}, имя: '${this._name}', оружие: ${this._weapon.name} (урон: ${this._weapon.damage})` + } +} \ No newline at end of file diff --git a/rpgsaga/saga/src/lab3/Clasees/Classes_players/Players/Archer.ts b/rpgsaga/saga/src/lab3/Clasees/Classes_players/Players/Archer.ts new file mode 100644 index 000000000..30efc4bd0 --- /dev/null +++ b/rpgsaga/saga/src/lab3/Clasees/Classes_players/Players/Archer.ts @@ -0,0 +1,15 @@ +import { Player } from "../Player"; +import { Weapon } from "../../Classes_weapons/Weapon"; +import { Ability } from "../../Classes_abilities/Ability"; +import { ability_names } from "../../../Enums/enum_abilities"; +import { role_names } from "../../../Enums/enum_roles"; + +export class Archer extends Player{ + constructor( + name: String, + weapon: Weapon, + health: number, + ) { + super(name, role_names.archer, weapon, health, 5, 5, new Ability(17, ability_names.archer_ability)); + } +} \ No newline at end of file diff --git a/rpgsaga/saga/src/lab3/Clasees/Classes_players/Players/Mage.ts b/rpgsaga/saga/src/lab3/Clasees/Classes_players/Players/Mage.ts new file mode 100644 index 000000000..ef2d80242 --- /dev/null +++ b/rpgsaga/saga/src/lab3/Clasees/Classes_players/Players/Mage.ts @@ -0,0 +1,15 @@ +import { Player } from "../Player"; +import { Weapon } from "../../Classes_weapons/Weapon"; +import { Ability } from "../../Classes_abilities/Ability"; +import { ability_names } from "../../../Enums/enum_abilities"; +import { role_names } from "../../../Enums/enum_roles"; + +export class Mage extends Player{ + constructor( + name: String, + weapon: Weapon, + health: number, + ) { + super(name, role_names.mage, weapon, health, 10, 10, new Ability(30, ability_names.mage_ability)); + } +} \ No newline at end of file diff --git a/rpgsaga/saga/src/lab3/Clasees/Classes_players/Players/Warrior.ts b/rpgsaga/saga/src/lab3/Clasees/Classes_players/Players/Warrior.ts new file mode 100644 index 000000000..713498f1b --- /dev/null +++ b/rpgsaga/saga/src/lab3/Clasees/Classes_players/Players/Warrior.ts @@ -0,0 +1,15 @@ +import { Player } from "../Player"; +import { Weapon } from "../../Classes_weapons/Weapon"; +import { Ability } from "../../Classes_abilities/Ability"; +import { ability_names } from "../../../Enums/enum_abilities"; +import { role_names } from "../../../Enums/enum_roles"; + +export class Warrior extends Player{ + constructor( + name: String, + weapon: Weapon, + health: number, + ){ + super(name, role_names.warrior, weapon, health, 20, 20, new Ability(20, ability_names.warrior_ability)); + } +} \ No newline at end of file diff --git a/rpgsaga/saga/src/lab3/Clasees/Classes_weapons/Weapon.ts b/rpgsaga/saga/src/lab3/Clasees/Classes_weapons/Weapon.ts new file mode 100644 index 000000000..21747a0da --- /dev/null +++ b/rpgsaga/saga/src/lab3/Clasees/Classes_weapons/Weapon.ts @@ -0,0 +1,64 @@ +import { Player } from "../Classes_players/Player"; +import { Ability } from "../Classes_abilities/Ability"; + +export class Weapon{ + private _name: string; + private _damage: number; + private _type_damage: String; + private _increase_phys_resist: number; + private _multiplier_phys_resist: number; + private _increase_magic_resist: number; + private _multiplier_magic_resist: number; + private _ability: Ability; + constructor( + name: string, + damage: number, + type_damage: String, + increase_phys_resist: number, + multiplier_phys_resist: number, + increase_magic_resist: number, + multiplier_magic_resist: number, + ability: Ability + ) { + this._name = name; + this._damage = damage; + this._type_damage = type_damage; + this._increase_phys_resist = increase_phys_resist; + this._multiplier_phys_resist = multiplier_phys_resist; + this._increase_magic_resist = increase_magic_resist; + this._multiplier_magic_resist = multiplier_magic_resist; + this._ability = ability; + } + + public get name(): String { + return this._name; + } + + public get damage(): number { + return this._damage; + } + + public get type_damage(): String { + return this._type_damage; + } + + public get increase_phys_resist(): number { + return this._increase_phys_resist; + } + + public get multiplier_phys_resist(): number { + return this._multiplier_phys_resist; + } + + public get increase_magic_resist(): number { + return this._increase_magic_resist; + } + + public get multiplier_magic_resist(): number { + return this._multiplier_magic_resist; + } + + public get ability(): Ability { + return this._ability; + } +} \ No newline at end of file diff --git a/rpgsaga/saga/src/lab3/Clasees/Classes_weapons/Weapons/Elf_Bow.ts b/rpgsaga/saga/src/lab3/Clasees/Classes_weapons/Weapons/Elf_Bow.ts new file mode 100644 index 000000000..e14f74fbd --- /dev/null +++ b/rpgsaga/saga/src/lab3/Clasees/Classes_weapons/Weapons/Elf_Bow.ts @@ -0,0 +1,10 @@ +import { Weapon } from "../Weapon"; +import { Ability } from "../../Classes_abilities/Ability"; +import { weapons_names } from "../../../Enums/enum_weapons"; +import { damage_types } from "../../../Enums/enum_damage_types"; +import { ability_names } from "../../../Enums/enum_abilities"; +export class Elf_Bow extends Weapon{ + constructor () { + super(weapons_names.elf_bow, 20, damage_types.pure, 0, 1, 0, 1, new Ability(0, ability_names.empty)); + } +} \ No newline at end of file diff --git a/rpgsaga/saga/src/lab3/Clasees/Classes_weapons/Weapons/Paladin_Shield.ts b/rpgsaga/saga/src/lab3/Clasees/Classes_weapons/Weapons/Paladin_Shield.ts new file mode 100644 index 000000000..418fb49f3 --- /dev/null +++ b/rpgsaga/saga/src/lab3/Clasees/Classes_weapons/Weapons/Paladin_Shield.ts @@ -0,0 +1,10 @@ +import { Weapon } from "../Weapon"; +import { Ability } from "../../Classes_abilities/Ability"; +import { weapons_names } from "../../../Enums/enum_weapons"; +import { damage_types } from "../../../Enums/enum_damage_types"; +import { ability_names } from "../../../Enums/enum_abilities"; +export class Paladin_Shield extends Weapon{ + constructor () { + super(weapons_names.paladin_sheild, 15, damage_types.phys, 5, 2, 5, 2, new Ability(0, ability_names.empty)); + } +} \ No newline at end of file diff --git a/rpgsaga/saga/src/lab3/Clasees/Classes_weapons/Weapons/Staff_Santa_Claus.ts b/rpgsaga/saga/src/lab3/Clasees/Classes_weapons/Weapons/Staff_Santa_Claus.ts new file mode 100644 index 000000000..1c9ea2b02 --- /dev/null +++ b/rpgsaga/saga/src/lab3/Clasees/Classes_weapons/Weapons/Staff_Santa_Claus.ts @@ -0,0 +1,10 @@ +import { Weapon } from "../Weapon"; +import { Ability } from "../../Classes_abilities/Ability"; +import { weapons_names } from "../../../Enums/enum_weapons"; +import { damage_types } from "../../../Enums/enum_damage_types"; +import { ability_names } from "../../../Enums/enum_abilities"; +export class Staff_Santa_Claus extends Weapon{ + constructor () { + super(weapons_names.staff_santa, 25, damage_types.mag, 0, 1, 0, 1, new Ability(20, ability_names.staff_santa)); + } +} \ No newline at end of file diff --git a/rpgsaga/saga/src/lab3/Enums/enum_abilities.ts b/rpgsaga/saga/src/lab3/Enums/enum_abilities.ts new file mode 100644 index 000000000..00374a957 --- /dev/null +++ b/rpgsaga/saga/src/lab3/Enums/enum_abilities.ts @@ -0,0 +1,7 @@ +export enum ability_names{ + empty = "empty", + archer_ability = "Уселенный выстрел", + warrior_ability = "Разящий удар", + mage_ability = "Поджигание", + staff_santa = "Замораживание" +} diff --git a/rpgsaga/saga/src/lab3/Enums/enum_damage_types.ts b/rpgsaga/saga/src/lab3/Enums/enum_damage_types.ts new file mode 100644 index 000000000..137145533 --- /dev/null +++ b/rpgsaga/saga/src/lab3/Enums/enum_damage_types.ts @@ -0,0 +1,5 @@ +export enum damage_types{ + pure = "pure", + phys = "physical", + mag = "magical" +} \ No newline at end of file diff --git a/rpgsaga/saga/src/lab3/Enums/enum_debuff.ts b/rpgsaga/saga/src/lab3/Enums/enum_debuff.ts new file mode 100644 index 000000000..768804112 --- /dev/null +++ b/rpgsaga/saga/src/lab3/Enums/enum_debuff.ts @@ -0,0 +1,3 @@ +export enum debuff_names{ + burning = "Горение" +} \ No newline at end of file diff --git a/rpgsaga/saga/src/lab3/Enums/enum_names.ts b/rpgsaga/saga/src/lab3/Enums/enum_names.ts new file mode 100644 index 000000000..a8bc54178 --- /dev/null +++ b/rpgsaga/saga/src/lab3/Enums/enum_names.ts @@ -0,0 +1,32 @@ +export enum names{ + "Artemis", + "Luna", + "Dorian", + "Zara", + "Raven", + "Amber", + "Kyos", + "Selena", + "Maya", + "Tarin", + "Niko", + "Irida", + "Leonard", + "Vika", + "Dorothea", + "Phoenix", + "Cassandra", + "Talon", + "Elon", + "Nereya", + "Osiris", + "Astra", + "Rio", + "Ksenia", + "Hermione", + "Valik", + "Taras", + "Orion", + "Zelda", + "Loki" +} \ No newline at end of file diff --git a/rpgsaga/saga/src/lab3/Enums/enum_roles.ts b/rpgsaga/saga/src/lab3/Enums/enum_roles.ts new file mode 100644 index 000000000..c00705593 --- /dev/null +++ b/rpgsaga/saga/src/lab3/Enums/enum_roles.ts @@ -0,0 +1,5 @@ +export enum role_names{ + archer = "Archer", + warrior = "Warrior", + mage = "Mage" +} \ No newline at end of file diff --git a/rpgsaga/saga/src/lab3/Enums/enum_weapons.ts b/rpgsaga/saga/src/lab3/Enums/enum_weapons.ts new file mode 100644 index 000000000..c54b03592 --- /dev/null +++ b/rpgsaga/saga/src/lab3/Enums/enum_weapons.ts @@ -0,0 +1,5 @@ +export enum weapons_names{ + elf_bow = "Elf`s bow", + paladin_sheild = "Paladin`s shield", + staff_santa = "Santa Claus`s staff" +} \ No newline at end of file diff --git a/rpgsaga/saga/src/lab3/Utils/check_operation.ts b/rpgsaga/saga/src/lab3/Utils/check_operation.ts new file mode 100644 index 000000000..5bde55097 --- /dev/null +++ b/rpgsaga/saga/src/lab3/Utils/check_operation.ts @@ -0,0 +1,20 @@ +export function check_operation(chance_trigger: number): boolean { + const value: number = Math.floor(Math.random() * 100) + 1 + if (value <= chance_trigger) { + return true; + } else { + return false; + } +} + +// let all_sum: number = 0 +// for (let j = 0; j < 1000; j++) { +// let count: number = 0; +// for (let i = 0; i < 100; i++) { +// if (check_operation(20)) { +// count++; +// } +// } +// all_sum += count +// } +// console.log(all_sum / 1000) \ No newline at end of file diff --git a/rpgsaga/saga/src/lab3/Utils/create_player.ts b/rpgsaga/saga/src/lab3/Utils/create_player.ts new file mode 100644 index 000000000..dd5b51809 --- /dev/null +++ b/rpgsaga/saga/src/lab3/Utils/create_player.ts @@ -0,0 +1,38 @@ +import { Weapon } from "../Clasees/Classes_weapons/Weapon"; +import { Elf_Bow } from "../Clasees/Classes_weapons/Weapons/Elf_Bow"; +import { Paladin_Shield } from "../Clasees/Classes_weapons/Weapons/Paladin_Shield"; +import { Staff_Santa_Claus } from "../Clasees/Classes_weapons/Weapons/Staff_Santa_Claus"; +import { weapons_names } from "../Enums/enum_weapons"; +import { random_weapon } from "../fun_random/random_weapon"; + + +import { Player } from "../Clasees/Classes_players/Player"; +import { Archer } from "../Clasees/Classes_players/Players/Archer"; +import { Warrior } from "../Clasees/Classes_players/Players/Warrior"; +import { Mage } from "../Clasees/Classes_players/Players/Mage"; +import { role_names } from "../Enums/enum_roles"; + +import { random_name } from "../fun_random/random_name"; +import { random_hero } from "../fun_random/random_hero"; + +export function create_weapon(): Weapon { + const name_weapon: String = random_weapon(); + if (name_weapon == weapons_names.elf_bow) { + return new Elf_Bow(); + } else if (name_weapon == weapons_names.paladin_sheild) { + return new Paladin_Shield(); + } else if (name_weapon == weapons_names.staff_santa) { + return new Staff_Santa_Claus(); + } +} +export function create_player(): Player { + const weapon: Weapon = create_weapon(); + const role_player: String = random_hero(); + if (role_player == role_names.archer) { + return new Archer(random_name(), weapon, 100); + } else if (role_player == role_names.warrior) { + return new Warrior(random_name(), weapon, 100); + } else if (role_player == role_names.mage) { + return new Mage(random_name(), weapon, 100); + } +} \ No newline at end of file diff --git a/rpgsaga/saga/src/lab3/fun_random/random_hero.ts b/rpgsaga/saga/src/lab3/fun_random/random_hero.ts new file mode 100644 index 000000000..b3e9aefb8 --- /dev/null +++ b/rpgsaga/saga/src/lab3/fun_random/random_hero.ts @@ -0,0 +1,7 @@ +import { role_names } from "../Enums/enum_roles"; + +export function random_hero() { + const players = Object.values(role_names).filter(key => isNaN(Number(key))); + const randomIndex = Math.floor(Math.random() * players.length); + return players[randomIndex] +} diff --git a/rpgsaga/saga/src/lab3/fun_random/random_name.ts b/rpgsaga/saga/src/lab3/fun_random/random_name.ts new file mode 100644 index 000000000..ec3d0fe1c --- /dev/null +++ b/rpgsaga/saga/src/lab3/fun_random/random_name.ts @@ -0,0 +1,7 @@ +import { names } from "../Enums/enum_names"; + +export function random_name(): String { + const all_names = Object.values(names).filter(key => isNaN(Number(key))); + const randomIndex = Math.floor(Math.random() * all_names.length); + return String(all_names[randomIndex]) +} diff --git a/rpgsaga/saga/src/lab3/fun_random/random_weapon.ts b/rpgsaga/saga/src/lab3/fun_random/random_weapon.ts new file mode 100644 index 000000000..af7026a73 --- /dev/null +++ b/rpgsaga/saga/src/lab3/fun_random/random_weapon.ts @@ -0,0 +1,8 @@ +import { weapons_names } from "../Enums/enum_weapons"; + +export function random_weapon(): string { + const weapons = Object.values(weapons_names).filter(key => isNaN(Number(key))); + const randomIndex = Math.floor(Math.random() * weapons.length); + return weapons[randomIndex]; +} + diff --git a/rpgsaga/saga/src/lab3/output_lab3.ts b/rpgsaga/saga/src/lab3/output_lab3.ts new file mode 100644 index 000000000..703986435 --- /dev/null +++ b/rpgsaga/saga/src/lab3/output_lab3.ts @@ -0,0 +1,3 @@ +import { battle } from "./Clasees/Classes_Battle"; +const battle_1 = new battle(12); +battle_1.start_game(); diff --git a/rpgsaga/saga/tests/example.spec.ts b/rpgsaga/saga/tests/example.spec.ts index a86cfde79..117097b4b 100644 --- a/rpgsaga/saga/tests/example.spec.ts +++ b/rpgsaga/saga/tests/example.spec.ts @@ -4,4 +4,4 @@ describe('Example', () => { const b = 2; expect(a + b).toEqual(5); }); -}); +}); diff --git a/rpgsaga/saga/tests/lab1_test/TaskAB.spec.ts b/rpgsaga/saga/tests/lab1_test/TaskAB.spec.ts new file mode 100644 index 000000000..52bc30c67 --- /dev/null +++ b/rpgsaga/saga/tests/lab1_test/TaskAB.spec.ts @@ -0,0 +1,12 @@ +import { taskA, taskB } from "../../src/Lab1/formuls"; + +describe('Tests of task A and task B', () => { + it('Func "taskA" return correct lenght', () => { + const y = taskA(1.6, 1.2, 3.7, 0.5); + expect(y).toHaveLength(6); + }); + it('Func "taskB" return correct lenght', () => { + const y = taskB(1.6, [1.28, 1.36, 2.47, 3.68, 4.56]); + expect(y).toHaveLength(5); + }) +}); \ No newline at end of file diff --git a/rpgsaga/saga/tests/lab1_test/formul.spec.ts b/rpgsaga/saga/tests/lab1_test/formul.spec.ts new file mode 100644 index 000000000..dd22edc86 --- /dev/null +++ b/rpgsaga/saga/tests/lab1_test/formul.spec.ts @@ -0,0 +1,36 @@ +import { formula } from "../../src/Lab1/formuls"; + +describe('Test of func formul', () => { + it('Func "formul" return undefind if x = 0', () => { + let y: number = formula(0); + expect(y).toBeNaN() + }); + it('Func "formul" return undefind if x = 1', () => { + let y: number = formula(1); + expect(y).toBeDefined() + }); + it('Func "formul" return undefind if x = -1', () => { + let y: number = formula(-1); + expect(y).toBeDefined() + }); + it('Func "formul" return undefind if x = 0.5', () => { + let y: number = formula(0.5); + expect(y).toBeNaN() + }); + it('Func "formul" return undefind if x = -0.5', () => { + let y: number = formula(-0.5); + expect(y).toBeNaN() + }); + it('Func "formul" return if x = 1.2', () => { + let y = formula(1.2); + expect(y).toBeCloseTo(2.346) + }); + it('Func "formul" return undefind if x = 2.47', () => { + let y = formula(2.47); + expect(y).toBeCloseTo(12.008) + }); + it('Func "formul" return undefind if x = 4.56', () => { + let y = formula(4.56); + expect(y).toBeCloseTo(10972.99) + }); +}) \ No newline at end of file diff --git a/rpgsaga/saga/tests/lab2_test/Volleyball_player_Class.spec.ts b/rpgsaga/saga/tests/lab2_test/Volleyball_player_Class.spec.ts new file mode 100644 index 000000000..c1de63f29 --- /dev/null +++ b/rpgsaga/saga/tests/lab2_test/Volleyball_player_Class.spec.ts @@ -0,0 +1,54 @@ +import { Volleyball_Player } from "../../src/Lab2/Volleyball_player_Class"; + +describe("Volleyball_Player constructor tests", () => { + let person: Volleyball_Player; + beforeEach(() => { + person = new Volleyball_Player("Ivan", 19, 'm', 181, 70, "Setter", 295, 320, "ISUCT"); + }); + it("Should create a person with correct properties", () => { + expect(person.name).toBe("Ivan"); + expect(person.age).toBe(19); + expect(person.gender).toBe("m"); + expect(person.height).toBe(181); + expect(person.weight).toBe(70); + expect(person.position).toBe("Setter"); + expect(person.place_jumping).toBe(295); + expect(person.running_jumping).toBe(320); + expect(person.team).toBe("ISUCT"); + }) + it ("Should throw Error if person's age < 0 or > 110", () => { + expect(() => { + person['age'] = -1; + }).toThrow(`Incorrect age`); + expect(() => { + person['age'] = 1000; + }).toThrow(`Incorrect age`); + }); + it ("Should throw Error if person's gender != 'm', 'w', 'man' or 'woman'", () => { + expect(() => { + person['gender'] = "human"; + }).toThrow(`Incorrect gender`); + }); + it ("Should throw Error if person's place_jumping < height", () => { + expect(() => { + person['place_jumping'] = 169; + }).toThrow(`Incorrect place_jumping`); + }); + it ("Should throw Error if person's running_jumping < height", () => { + expect(() => { + person['running_jumping'] = 179; + }).toThrow(`Incorrect running_jumping`); + }); +}); + +describe("Volleyball_Player methods tests", () => { + let person: Volleyball_Player; + beforeEach(() => { + person = new Volleyball_Player("Ivan", 19, 'm', 181, 70, "Setter", 295, 320, "ISUCT"); + }); + it('Should return the correct info about person', () => { + expect(person.view_player_parameters()).toBe(`Player ${person.name}:\n + Takeoff from a standing jump: ${person.place_jumping - person.height}\n + Takeoff on a running jump: ${person.running_jumping - person.height}`) + }); +}); \ No newline at end of file diff --git a/rpgsaga/saga/tests/lab3_tests/Abilities_test/Archer_ability.spec.ts b/rpgsaga/saga/tests/lab3_tests/Abilities_test/Archer_ability.spec.ts new file mode 100644 index 000000000..28de3fcb7 --- /dev/null +++ b/rpgsaga/saga/tests/lab3_tests/Abilities_test/Archer_ability.spec.ts @@ -0,0 +1,12 @@ +import { Player } from "../../../src/lab3/Clasees/Classes_players/Player"; +import { Elf_Bow } from "../../../src/lab3/Clasees/Classes_weapons/Weapons/Elf_Bow"; +import { Hit } from "../../../src/lab3/Clasees/Class_hit"; +import { activation_archer_ability } from "../../../src/lab3/Clasees/Classes_abilities/Abilities/Archer_ability"; + +test('archer ability should increase damage by 50%', () => { + const weapon = new Elf_Bow() + const player = new Player("Test Archer", "Archer", weapon, 100, 5, 5, {} as any); + const hit = new Hit(100, "phys", false); + const newHit = activation_archer_ability(player, hit); + expect(newHit.damage).toBe(150); +}); \ No newline at end of file diff --git a/rpgsaga/saga/tests/lab3_tests/Abilities_test/Mage_ability.spec.ts b/rpgsaga/saga/tests/lab3_tests/Abilities_test/Mage_ability.spec.ts new file mode 100644 index 000000000..c5d57ed12 --- /dev/null +++ b/rpgsaga/saga/tests/lab3_tests/Abilities_test/Mage_ability.spec.ts @@ -0,0 +1,10 @@ +import { Player } from "../../../src/lab3/Clasees/Classes_players/Player"; +import { Hit } from "../../../src/lab3/Clasees/Class_hit"; +import { activation_mage_ability } from "../../../src/lab3/Clasees/Classes_abilities/Abilities/Mage_ability"; + +test('mage ability should apply burning debuff', () => { + const player = new Player("Test Mage", "Mage", {} as any, 100, 10, 10, {} as any); + const hit = new Hit(100, "mag", false); + const newHit = activation_mage_ability(player, hit); + expect(newHit.debuff).toBeDefined(); +}); \ No newline at end of file diff --git a/rpgsaga/saga/tests/lab3_tests/Abilities_test/Staff_Santa_ability.spec.ts b/rpgsaga/saga/tests/lab3_tests/Abilities_test/Staff_Santa_ability.spec.ts new file mode 100644 index 000000000..2352500cf --- /dev/null +++ b/rpgsaga/saga/tests/lab3_tests/Abilities_test/Staff_Santa_ability.spec.ts @@ -0,0 +1,10 @@ +import { Player } from "../../../src/lab3/Clasees/Classes_players/Player"; +import { Hit } from "../../../src/lab3/Clasees/Class_hit"; +import { activation_staff_santa_ability } from "../../../src/lab3/Clasees/Classes_abilities/Abilities/Staff_Santa_ability"; + +test('staff santa ability should apply control effect', () => { + const player = new Player("Test Santa", "Santa", {} as any, 100, 0, 0, {} as any); + const hit = new Hit(100, "mag", false); + const newHit = activation_staff_santa_ability(player, hit); + expect(newHit.control).toBe(true); +}); \ No newline at end of file diff --git a/rpgsaga/saga/tests/lab3_tests/Abilities_test/Warrior_ability.spec.ts b/rpgsaga/saga/tests/lab3_tests/Abilities_test/Warrior_ability.spec.ts new file mode 100644 index 000000000..905996751 --- /dev/null +++ b/rpgsaga/saga/tests/lab3_tests/Abilities_test/Warrior_ability.spec.ts @@ -0,0 +1,12 @@ +import { Player } from "../../../src/lab3/Clasees/Classes_players/Player"; +import { Paladin_Shield } from "../../../src/lab3/Clasees/Classes_weapons/Weapons/Paladin_Shield"; +import { Hit } from "../../../src/lab3/Clasees/Class_hit"; +import { activation_warriro_ability } from "../../../src/lab3/Clasees/Classes_abilities/Abilities/Warrior_ability"; + +test('warrior ability should increase damage based on resistances', () => { + const weapon = new Paladin_Shield() + const player = new Player("Test Warrior", "Warrior", weapon, 100, 20, 20, {} as any); + const hit = new Hit(100, "phys", false); + const newHit = activation_warriro_ability(player, hit); + expect(newHit.damage).toBeGreaterThan(100); +}); \ No newline at end of file diff --git a/rpgsaga/saga/tests/lab3_tests/Abilities_test/using_abilities.spec.ts b/rpgsaga/saga/tests/lab3_tests/Abilities_test/using_abilities.spec.ts new file mode 100644 index 000000000..ea501f838 --- /dev/null +++ b/rpgsaga/saga/tests/lab3_tests/Abilities_test/using_abilities.spec.ts @@ -0,0 +1,14 @@ +import { Ability } from "../../../src/lab3/Clasees/Classes_abilities/Ability"; +import { Elf_Bow } from "../../../src/lab3/Clasees/Classes_weapons/Weapons/Elf_Bow"; +import { Player } from "../../../src/lab3/Clasees/Classes_players/Player"; +import { Hit } from "../../../src/lab3/Clasees/Class_hit"; +import { activation_ability } from "../../../src/lab3/Clasees/Classes_abilities/using_abilities"; + +test('activation_ability should apply correct ability', () => { + const weapon = new Elf_Bow(); + const player = new Player("Test Player", "Archer", weapon, 100, 5, 5, {} as any); + const hit = new Hit(100, "phys", false); + const abilities = [new Ability(100, "Уселенный выстрел")]; + const newHit = activation_ability(abilities, player, hit); + expect(newHit.damage).toBe(150); +}); \ No newline at end of file diff --git a/rpgsaga/saga/tests/lab3_tests/Classes_test/Ability.spec.ts b/rpgsaga/saga/tests/lab3_tests/Classes_test/Ability.spec.ts new file mode 100644 index 000000000..ce2c39524 --- /dev/null +++ b/rpgsaga/saga/tests/lab3_tests/Classes_test/Ability.spec.ts @@ -0,0 +1,7 @@ +import { Ability } from "../../../src/lab3/Clasees/Classes_abilities/Ability"; + +test('ability should have correct properties', () => { + const ability = new Ability(20, "Test Ability"); + expect(ability.change_ability).toBe(20); + expect(ability.name_ability).toBe("Test Ability"); +}); \ No newline at end of file diff --git a/rpgsaga/saga/tests/lab3_tests/Classes_test/Battle.spec.ts b/rpgsaga/saga/tests/lab3_tests/Classes_test/Battle.spec.ts new file mode 100644 index 000000000..68f239e0d --- /dev/null +++ b/rpgsaga/saga/tests/lab3_tests/Classes_test/Battle.spec.ts @@ -0,0 +1,6 @@ +import { battle } from "../../../src/lab3/Clasees/Classes_Battle"; + +test('battle should start with correct number of players', () => { + const battleInstance = new battle(12); + expect(battleInstance).toBeInstanceOf(battle); +}); \ No newline at end of file diff --git a/rpgsaga/saga/tests/lab3_tests/Classes_test/Debuff_test/Burning.spec.ts b/rpgsaga/saga/tests/lab3_tests/Classes_test/Debuff_test/Burning.spec.ts new file mode 100644 index 000000000..692907c8e --- /dev/null +++ b/rpgsaga/saga/tests/lab3_tests/Classes_test/Debuff_test/Burning.spec.ts @@ -0,0 +1,7 @@ +import { Burning } from "../../../../src/lab3/Clasees/Classes_debuff/Debuffs/Burning"; + +test('burning debuff should have correct properties', () => { + const burning = new Burning(); + expect(burning.name_debuff).toBe("Горение"); + expect(burning.duration).toBe(3); +}); \ No newline at end of file diff --git a/rpgsaga/saga/tests/lab3_tests/Classes_test/Debuff_test/Debuff.spec.ts b/rpgsaga/saga/tests/lab3_tests/Classes_test/Debuff_test/Debuff.spec.ts new file mode 100644 index 000000000..3cfca25eb --- /dev/null +++ b/rpgsaga/saga/tests/lab3_tests/Classes_test/Debuff_test/Debuff.spec.ts @@ -0,0 +1,7 @@ +import { Debuff } from "../../../../src/lab3/Clasees/Classes_debuff/Debuff"; + +test('debuff should have correct properties', () => { + const debuff = new Debuff("Test Debuff", 3, 10, "mag", false); + expect(debuff.name_debuff).toBe("Test Debuff"); + expect(debuff.duration).toBe(3); +}); \ No newline at end of file diff --git a/rpgsaga/saga/tests/lab3_tests/Classes_test/Hit.spec.ts b/rpgsaga/saga/tests/lab3_tests/Classes_test/Hit.spec.ts new file mode 100644 index 000000000..10980ee58 --- /dev/null +++ b/rpgsaga/saga/tests/lab3_tests/Classes_test/Hit.spec.ts @@ -0,0 +1,8 @@ +import { Hit } from "../../../src/lab3/Clasees/Class_hit"; + +test('hit should have correct properties', () => { + const hit = new Hit(100, "phys", false); + expect(hit.damage).toBe(100); + expect(hit.type_damage).toBe("phys"); + expect(hit.control).toBe(false) +}); \ No newline at end of file diff --git a/rpgsaga/saga/tests/lab3_tests/Classes_test/Player_test/Archer.spec.ts b/rpgsaga/saga/tests/lab3_tests/Classes_test/Player_test/Archer.spec.ts new file mode 100644 index 000000000..3f98c7aae --- /dev/null +++ b/rpgsaga/saga/tests/lab3_tests/Classes_test/Player_test/Archer.spec.ts @@ -0,0 +1,7 @@ +import { Archer } from "../../../../src/lab3/Clasees/Classes_players/Players/Archer"; + +test('archer should have correct properties', () => { + const archer = new Archer("Test Archer", {} as any, 100); + expect(archer.role).toBe("Archer"); + expect(archer.health).toBe(100); +}); \ No newline at end of file diff --git a/rpgsaga/saga/tests/lab3_tests/Classes_test/Player_test/Mage.spec.ts b/rpgsaga/saga/tests/lab3_tests/Classes_test/Player_test/Mage.spec.ts new file mode 100644 index 000000000..96aa67ca4 --- /dev/null +++ b/rpgsaga/saga/tests/lab3_tests/Classes_test/Player_test/Mage.spec.ts @@ -0,0 +1,6 @@ +import { Mage } from "../../../../src/lab3/Clasees/Classes_players/Players/Mage"; + +test('mage should have correct properties', () => { + const mage = new Mage("Test Mage", {} as any, 100); + expect(mage.role).toBe("Mage"); +}); \ No newline at end of file diff --git a/rpgsaga/saga/tests/lab3_tests/Classes_test/Player_test/Player.spec.ts b/rpgsaga/saga/tests/lab3_tests/Classes_test/Player_test/Player.spec.ts new file mode 100644 index 000000000..245d9af9b --- /dev/null +++ b/rpgsaga/saga/tests/lab3_tests/Classes_test/Player_test/Player.spec.ts @@ -0,0 +1,7 @@ +import { Player } from "../../../../src/lab3/Clasees/Classes_players/Player"; + +test('player should have correct properties', () => { + const player = new Player("Test Player", "Archer", {} as any, 100, 5, 5, {} as any); + expect(player.name).toBe("Test Player"); + expect(player.role).toBe("Archer"); +}); \ No newline at end of file diff --git a/rpgsaga/saga/tests/lab3_tests/Classes_test/Player_test/Warrior.spec.ts b/rpgsaga/saga/tests/lab3_tests/Classes_test/Player_test/Warrior.spec.ts new file mode 100644 index 000000000..d253f9ff6 --- /dev/null +++ b/rpgsaga/saga/tests/lab3_tests/Classes_test/Player_test/Warrior.spec.ts @@ -0,0 +1,6 @@ +import { Warrior } from "../../../../src/lab3/Clasees/Classes_players/Players/Warrior"; + +test('warrior should have correct properties', () => { + const warrior = new Warrior("Test Warrior", {} as any, 100); + expect(warrior.role).toBe("Warrior"); +}); \ No newline at end of file diff --git a/rpgsaga/saga/tests/lab3_tests/Classes_test/Weapon_test/Elf_Bow.spec.ts b/rpgsaga/saga/tests/lab3_tests/Classes_test/Weapon_test/Elf_Bow.spec.ts new file mode 100644 index 000000000..3d03d0e30 --- /dev/null +++ b/rpgsaga/saga/tests/lab3_tests/Classes_test/Weapon_test/Elf_Bow.spec.ts @@ -0,0 +1,12 @@ +import { Elf_Bow } from "../../../../src/lab3/Clasees/Classes_weapons/Weapons/Elf_Bow"; + +test('elf bow should have correct properties', () => { + const elfBow = new Elf_Bow(); + expect(elfBow.name).toBe("Elf`s bow"); + expect(elfBow.damage).toBe(20); + expect(elfBow.type_damage).toBe('pure'); + expect(elfBow.increase_magic_resist).toBe(0); + expect(elfBow.increase_phys_resist).toBe(0); + expect(elfBow.multiplier_magic_resist).toBe(1); + expect(elfBow.multiplier_phys_resist).toBe(1); +}); \ No newline at end of file diff --git a/rpgsaga/saga/tests/lab3_tests/Classes_test/Weapon_test/Paladin_Shield.spec.ts b/rpgsaga/saga/tests/lab3_tests/Classes_test/Weapon_test/Paladin_Shield.spec.ts new file mode 100644 index 000000000..bfec89075 --- /dev/null +++ b/rpgsaga/saga/tests/lab3_tests/Classes_test/Weapon_test/Paladin_Shield.spec.ts @@ -0,0 +1,12 @@ +import { Paladin_Shield } from "../../../../src/lab3/Clasees/Classes_weapons/Weapons/Paladin_Shield"; + +test('paladin shield should have correct properties', () => { + const paladinShield = new Paladin_Shield(); + expect(paladinShield.name).toBe("Paladin`s shield"); + expect(paladinShield.damage).toBe(15); + expect(paladinShield.type_damage).toBe('physical'); + expect(paladinShield.increase_magic_resist).toBe(5); + expect(paladinShield.increase_phys_resist).toBe(5); + expect(paladinShield.multiplier_magic_resist).toBe(2); + expect(paladinShield.multiplier_phys_resist).toBe(2); +}); \ No newline at end of file diff --git a/rpgsaga/saga/tests/lab3_tests/Classes_test/Weapon_test/Staff_Santa_Claus.spec.ts b/rpgsaga/saga/tests/lab3_tests/Classes_test/Weapon_test/Staff_Santa_Claus.spec.ts new file mode 100644 index 000000000..7a63a681e --- /dev/null +++ b/rpgsaga/saga/tests/lab3_tests/Classes_test/Weapon_test/Staff_Santa_Claus.spec.ts @@ -0,0 +1,13 @@ +import exp = require("constants"); +import { Staff_Santa_Claus } from "../../../../src/lab3/Clasees/Classes_weapons/Weapons/Staff_Santa_Claus"; + +test('staff santa claus should have correct properties', () => { + const staffSantaClaus = new Staff_Santa_Claus(); + expect(staffSantaClaus.name).toBe("Santa Claus`s staff"); + expect(staffSantaClaus.damage).toBe(25); + expect(staffSantaClaus.type_damage).toBe('magical') + expect(staffSantaClaus.increase_magic_resist).toBe(0); + expect(staffSantaClaus.increase_phys_resist).toBe(0); + expect(staffSantaClaus.multiplier_magic_resist).toBe(1); + expect(staffSantaClaus.multiplier_phys_resist).toBe(1); +}); \ No newline at end of file diff --git a/rpgsaga/saga/tests/lab3_tests/Classes_test/Weapon_test/Weapon.spec.ts b/rpgsaga/saga/tests/lab3_tests/Classes_test/Weapon_test/Weapon.spec.ts new file mode 100644 index 000000000..1b9ff1ba0 --- /dev/null +++ b/rpgsaga/saga/tests/lab3_tests/Classes_test/Weapon_test/Weapon.spec.ts @@ -0,0 +1,7 @@ +import { Weapon } from "../../../../src/lab3/Clasees/Classes_weapons/Weapon"; + +test('weapon should have correct properties', () => { + const weapon = new Weapon("Test Weapon", 100, "phys", 0, 1, 0, 1, {} as any); + expect(weapon.name).toBe("Test Weapon"); + expect(weapon.damage).toBe(100); +}); \ No newline at end of file diff --git a/rpgsaga/saga/tests/lab3_tests/Random_test/random_hero.spec.ts b/rpgsaga/saga/tests/lab3_tests/Random_test/random_hero.spec.ts new file mode 100644 index 000000000..447de8281 --- /dev/null +++ b/rpgsaga/saga/tests/lab3_tests/Random_test/random_hero.spec.ts @@ -0,0 +1,6 @@ +import { random_hero } from "../../../src/lab3/fun_random/random_hero"; + +test('random_hero should return a valid role', () => { + const role = random_hero(); + expect(["Archer", "Mage", "Warrior"]).toContain(role); +}); \ No newline at end of file diff --git a/rpgsaga/saga/tests/lab3_tests/Random_test/random_name.spec.ts b/rpgsaga/saga/tests/lab3_tests/Random_test/random_name.spec.ts new file mode 100644 index 000000000..afa44d389 --- /dev/null +++ b/rpgsaga/saga/tests/lab3_tests/Random_test/random_name.spec.ts @@ -0,0 +1,6 @@ +import { random_name } from "../../../src/lab3/fun_random/random_name"; + +test('random_name should return a valid name', () => { + const name = random_name(); + expect(typeof name).toBe("string"); +}); \ No newline at end of file diff --git a/rpgsaga/saga/tests/lab3_tests/Random_test/random_weapon.spec.ts b/rpgsaga/saga/tests/lab3_tests/Random_test/random_weapon.spec.ts new file mode 100644 index 000000000..ee665b86c --- /dev/null +++ b/rpgsaga/saga/tests/lab3_tests/Random_test/random_weapon.spec.ts @@ -0,0 +1,6 @@ +import { random_weapon } from "../../../src/lab3/fun_random/random_weapon"; + +test('random_weapon should return a valid weapon name', () => { + const weapon = random_weapon(); + expect(["Elf`s bow", "Paladin`s shield", "Santa Claus`s staff"]).toContain(weapon); +}); \ No newline at end of file diff --git a/rpgsaga/saga/tests/lab3_tests/check_operation.spec.ts b/rpgsaga/saga/tests/lab3_tests/check_operation.spec.ts new file mode 100644 index 000000000..9e1db9c11 --- /dev/null +++ b/rpgsaga/saga/tests/lab3_tests/check_operation.spec.ts @@ -0,0 +1,6 @@ +import { check_operation } from "../../src/lab3/Utils/check_operation"; + +test('check_operation should return true or false based on chance', () => { + const result = check_operation(50); + expect([true, false]).toContain(result); +}); \ No newline at end of file diff --git a/rpgsaga/saga/tests/lab3_tests/create_player.spec.ts b/rpgsaga/saga/tests/lab3_tests/create_player.spec.ts new file mode 100644 index 000000000..bc3e44a69 --- /dev/null +++ b/rpgsaga/saga/tests/lab3_tests/create_player.spec.ts @@ -0,0 +1,7 @@ +import { create_player } from "../../src/lab3/Utils/create_player"; + +test('create_player should return a valid player', () => { + const player = create_player(); + expect(player).toBeDefined(); + expect(["Archer", "Mage", "Warrior"]).toContain(player.role); +}); \ No newline at end of file