Advertisement
namemkazaza

Command Executor

Feb 8th, 2020
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.19 KB | None | 0 0
  1. from __future__ import annotations
  2.  
  3.  
  4. class Command:
  5.     def __init__(self, arr, value):
  6.         self.arr = arr
  7.         self.multiplier = value
  8.  
  9.     commands = []
  10.  
  11.     def PushIn(self, command):
  12.         self.commands.append(command)
  13.  
  14.     def pop(self):
  15.         self.commands.pop()
  16.  
  17.     def execute(self):
  18.         for i in range(len(self.arr)):
  19.             for j in range(len(self.arr[i])):
  20.                 self.arr[i][j] += self.multiplier
  21.         return self.arr
  22.  
  23.     def redo(self):
  24.         for i in range(len(self.arr)):
  25.             for j in range(len(self.arr[i])):
  26.                 self.arr[i][j] += self.multiplier
  27.             self.PushIn(self.execute())
  28.  
  29.     def undo(self):
  30.         for i in range(len(self.arr)):
  31.             for j in range(len(self.arr[i])):
  32.                 self.arr[i][j] -= self.multiplier
  33.             self.commands.pop()
  34.  
  35.  
  36. class CommandExecutor:
  37.  
  38.  
  39.  
  40. class App:
  41.     def PrintArray(arr):
  42.         for i in range(len(arr)):
  43.             print(*arr[i])
  44.  
  45.     def main(self):
  46.         print('starting')
  47.         arr = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
  48.         plus = Command(arr, 5)
  49.         plus.execute()
  50.         self.PrintArray(arr)
  51.  
  52.  
  53. App.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement