Advertisement
Guest User

Mock Windows Interface Version 3

a guest
Jul 8th, 2024
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.61 KB | None | 0 0
  1. import React, { useState, useEffect } from 'react';
  2. import { X, Minus, Square, Settings, Power, FileText, Grid, Disc } from 'lucide-react';
  3.  
  4. // Notepad Component
  5. const Notepad = ({ onClose }) => {
  6. const [text, setText] = useState('');
  7. return (
  8. <div className="h-full flex flex-col">
  9. <textarea
  10. className="flex-grow p-2 resize-none"
  11. value={text}
  12. onChange={(e) => setText(e.target.value)}
  13. />
  14. </div>
  15. );
  16. };
  17.  
  18. // Minesweeper Component
  19. const Minesweeper = ({ onClose }) => {
  20. const [grid, setGrid] = useState([]);
  21. const [gameOver, setGameOver] = useState(false);
  22.  
  23. useEffect(() => {
  24. initializeGrid();
  25. }, []);
  26.  
  27. const initializeGrid = () => {
  28. const newGrid = Array(8).fill().map(() => Array(8).fill({ isMine: false, isRevealed: false, neighborMines: 0 }));
  29. // Place mines
  30. let minesToPlace = 10;
  31. while (minesToPlace > 0) {
  32. const row = Math.floor(Math.random() * 8);
  33. const col = Math.floor(Math.random() * 8);
  34. if (!newGrid[row][col].isMine) {
  35. newGrid[row][col].isMine = true;
  36. minesToPlace--;
  37. }
  38. }
  39. // Calculate neighbor mines
  40. for (let row = 0; row < 8; row++) {
  41. for (let col = 0; col < 8; col++) {
  42. if (!newGrid[row][col].isMine) {
  43. let count = 0;
  44. for (let r = -1; r <= 1; r++) {
  45. for (let c = -1; c <= 1; c++) {
  46. if (row + r >= 0 && row + r < 8 && col + c >= 0 && col + c < 8) {
  47. if (newGrid[row + r][col + c].isMine) count++;
  48. }
  49. }
  50. }
  51. newGrid[row][col].neighborMines = count;
  52. }
  53. }
  54. }
  55. setGrid(newGrid);
  56. };
  57.  
  58. const revealCell = (row, col) => {
  59. if (gameOver || grid[row][col].isRevealed) return;
  60. const newGrid = [...grid];
  61. newGrid[row][col].isRevealed = true;
  62. if (newGrid[row][col].isMine) {
  63. setGameOver(true);
  64. } else if (newGrid[row][col].neighborMines === 0) {
  65. // Reveal neighboring cells
  66. for (let r = -1; r <= 1; r++) {
  67. for (let c = -1; c <= 1; c++) {
  68. if (row + r >= 0 && row + r < 8 && col + c >= 0 && col + c < 8) {
  69. revealCell(row + r, col + c);
  70. }
  71. }
  72. }
  73. }
  74. setGrid(newGrid);
  75. };
  76.  
  77. return (
  78. <div className="h-full flex flex-col items-center justify-center">
  79. {grid.map((row, rowIndex) => (
  80. <div key={rowIndex} className="flex">
  81. {row.map((cell, colIndex) => (
  82. <button
  83. key={colIndex}
  84. className={`w-6 h-6 border border-gray-400 ${cell.isRevealed ? 'bg-gray-200' : 'bg-gray-300'}`}
  85. onClick={() => revealCell(rowIndex, colIndex)}
  86. >
  87. {cell.isRevealed && (cell.isMine ? '💣' : cell.neighborMines > 0 ? cell.neighborMines : '')}
  88. </button>
  89. ))}
  90. </div>
  91. ))}
  92. {gameOver && <div className="mt-4">Game Over!</div>}
  93. </div>
  94. );
  95. };
  96.  
  97. // Reversi Component
  98. const Reversi = ({ onClose }) => {
  99. const [board, setBoard] = useState(Array(8).fill().map(() => Array(8).fill(null)));
  100. const [currentPlayer, setCurrentPlayer] = useState('black');
  101.  
  102. useEffect(() => {
  103. const newBoard = [...board];
  104. newBoard[3][3] = 'white';
  105. newBoard[3][4] = 'black';
  106. newBoard[4][3] = 'black';
  107. newBoard[4][4] = 'white';
  108. setBoard(newBoard);
  109. }, []);
  110.  
  111. const isValidMove = (row, col) => {
  112. if (board[row][col] !== null) return false;
  113. const directions = [[-1, -1], [-1, 0], [-1, 1], [0, -1], [0, 1], [1, -1], [1, 0], [1, 1]];
  114. for (let [dx, dy] of directions) {
  115. let x = row + dx;
  116. let y = col + dy;
  117. if (x < 0 || x >= 8 || y < 0 || y >= 8 || board[x][y] !== (currentPlayer === 'black' ? 'white' : 'black')) continue;
  118. x += dx;
  119. y += dy;
  120. while (x >= 0 && x < 8 && y >= 0 && y < 8) {
  121. if (board[x][y] === null) break;
  122. if (board[x][y] === currentPlayer) return true;
  123. x += dx;
  124. y += dy;
  125. }
  126. }
  127. return false;
  128. };
  129.  
  130. const makeMove = (row, col) => {
  131. if (!isValidMove(row, col)) return;
  132. const newBoard = [...board];
  133. newBoard[row][col] = currentPlayer;
  134. const directions = [[-1, -1], [-1, 0], [-1, 1], [0, -1], [0, 1], [1, -1], [1, 0], [1, 1]];
  135. for (let [dx, dy] of directions) {
  136. let x = row + dx;
  137. let y = col + dy;
  138. let toFlip = [];
  139. while (x >= 0 && x < 8 && y >= 0 && y < 8) {
  140. if (board[x][y] === null) break;
  141. if (board[x][y] === currentPlayer) {
  142. for (let [fx, fy] of toFlip) {
  143. newBoard[fx][fy] = currentPlayer;
  144. }
  145. break;
  146. }
  147. toFlip.push([x, y]);
  148. x += dx;
  149. y += dy;
  150. }
  151. }
  152. setBoard(newBoard);
  153. setCurrentPlayer(currentPlayer === 'black' ? 'white' : 'black');
  154. };
  155.  
  156. return (
  157. <div className="h-full flex flex-col items-center justify-center">
  158. {board.map((row, rowIndex) => (
  159. <div key={rowIndex} className="flex">
  160. {row.map((cell, colIndex) => (
  161. <button
  162. key={colIndex}
  163. className="w-8 h-8 border border-gray-400 bg-green-600 flex items-center justify-center"
  164. onClick={() => makeMove(rowIndex, colIndex)}
  165. >
  166. {cell && (
  167. <div className={`w-6 h-6 rounded-full ${cell === 'black' ? 'bg-black' : 'bg-white'}`} />
  168. )}
  169. </button>
  170. ))}
  171. </div>
  172. ))}
  173. <div className="mt-4">Current Player: {currentPlayer}</div>
  174. </div>
  175. );
  176. };
  177.  
  178. const Windows95Interface = () => {
  179. const [windows, setWindows] = useState([]);
  180. const [activeWindow, setActiveWindow] = useState(null);
  181. const [dragStart, setDragStart] = useState({ x: 0, y: 0 });
  182. const [startMenuOpen, setStartMenuOpen] = useState(false);
  183. const [settingsOpen, setSettingsOpen] = useState(false);
  184. const [backgroundColor, setBackgroundColor] = useState('#008080');
  185. const [shutdownPrompt, setShutdownPrompt] = useState(false);
  186.  
  187. const handleMouseDown = (e, id) => {
  188. setActiveWindow(id);
  189. setDragStart({ x: e.clientX, y: e.clientY });
  190. };
  191.  
  192. const handleMouseMove = (e) => {
  193. if (activeWindow !== null) {
  194. const dx = e.clientX - dragStart.x;
  195. const dy = e.clientY - dragStart.y;
  196. setWindows(windows.map(w =>
  197. w.id === activeWindow
  198. ? { ...w, x: w.x + dx, y: w.y + dy }
  199. : w
  200. ));
  201. setDragStart({ x: e.clientX, y: e.clientY });
  202. }
  203. };
  204.  
  205. const handleMouseUp = () => {
  206. setActiveWindow(null);
  207. };
  208.  
  209. const minimizeWindow = (id) => {
  210. setWindows(windows.map(w =>
  211. w.id === id ? { ...w, minimized: !w.minimized } : w
  212. ));
  213. };
  214.  
  215. const closeWindow = (id) => {
  216. setWindows(windows.filter(w => w.id !== id));
  217. };
  218.  
  219. const openWindow = (title, content) => {
  220. const newWindow = {
  221. id: Date.now(),
  222. title,
  223. content,
  224. x: 50 + Math.random() * 100,
  225. y: 50 + Math.random() * 100,
  226. width: 400,
  227. height: 300,
  228. minimized: false
  229. };
  230. setWindows([...windows, newWindow]);
  231. setStartMenuOpen(false);
  232. };
  233.  
  234. const toggleStartMenu = () => {
  235. setStartMenuOpen(!startMenuOpen);
  236. };
  237.  
  238. const openSettings = () => {
  239. setSettingsOpen(true);
  240. setStartMenuOpen(false);
  241. };
  242.  
  243. const closeSettings = () => {
  244. setSettingsOpen(false);
  245. };
  246.  
  247. const changeBackgroundColor = (color) => {
  248. setBackgroundColor(color);
  249. };
  250.  
  251. const initiateShutdown = () => {
  252. setShutdownPrompt(true);
  253. setStartMenuOpen(false);
  254. };
  255.  
  256. const cancelShutdown = () => {
  257. setShutdownPrompt(false);
  258. };
  259.  
  260. const confirmShutdown = () => {
  261. setWindows([]);
  262. setShutdownPrompt(false);
  263. alert("Windows is shutting down. It's now safe to turn off your computer.");
  264. };
  265.  
  266. return (
  267. <div
  268. className="w-full h-screen relative overflow-hidden"
  269. style={{ backgroundColor }}
  270. onMouseMove={handleMouseMove}
  271. onMouseUp={handleMouseUp}
  272. >
  273. {windows.map(window => (
  274. <div
  275. key={window.id}
  276. className={`absolute bg-gray-200 border-2 border-gray-400 shadow-lg ${window.minimized ? 'hidden' : ''}`}
  277. style={{
  278. left: `${window.x}px`,
  279. top: `${window.y}px`,
  280. width: `${window.width}px`,
  281. height: `${window.height}px`,
  282. zIndex: activeWindow === window.id ? 10 : 1
  283. }}
  284. >
  285. <div
  286. className="bg-blue-900 text-white px-2 py-1 flex justify-between items-center cursor-move"
  287. onMouseDown={(e) => handleMouseDown(e, window.id)}
  288. >
  289. <span>{window.title}</span>
  290. <div className="flex space-x-1">
  291. <button onClick={() => minimizeWindow(window.id)} className="focus:outline-none">
  292. <Minus size={16} />
  293. </button>
  294. <button className="focus:outline-none">
  295. <Square size={16} />
  296. </button>
  297. <button onClick={() => closeWindow(window.id)} className="focus:outline-none">
  298. <X size={16} />
  299. </button>
  300. </div>
  301. </div>
  302. <div className="p-2 h-[calc(100%-2rem)] overflow-auto">
  303. {window.content}
  304. </div>
  305. </div>
  306. ))}
  307.  
  308. {settingsOpen && (
  309. <div className="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 bg-gray-200 border-2 border-gray-400 shadow-lg p-4 w-80">
  310. <div className="flex justify-between items-center mb-4">
  311. <h2 className="text-lg font-bold">Settings</h2>
  312. <button onClick={closeSettings} className="focus:outline-none">
  313. <X size={16} />
  314. </button>
  315. </div>
  316. <div className="mb-4">
  317. <label className="block mb-2">Background Color:</label>
  318. <div className="flex space-x-2">
  319. <button onClick={() => changeBackgroundColor('#008080')} className="w-6 h-6 bg-teal-600"></button>
  320. <button onClick={() => changeBackgroundColor('#000080')} className="w-6 h-6 bg-blue-900"></button>
  321. <button onClick={() => changeBackgroundColor('#008000')} className="w-6 h-6 bg-green-700"></button>
  322. </div>
  323. </div>
  324. </div>
  325. )}
  326.  
  327. {shutdownPrompt && (
  328. <div className="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 bg-gray-200 border-2 border-gray-400 shadow-lg p-4 w-80">
  329. <h2 className="text-lg font-bold mb-4">Shut Down Windows</h2>
  330. <p className="mb-4">Are you sure you want to shut down your computer?</p>
  331. <div className="flex justify-end space-x-2">
  332. <button onClick={cancelShutdown} className="px-4 py-2 bg-gray-300 hover:bg-gray-400">Cancel</button>
  333. <button onClick={confirmShutdown} className="px-4 py-2 bg-red-500 text-white hover:bg-red-600">OK</button>
  334. </div>
  335. </div>
  336. )}
  337.  
  338. <div className="absolute bottom-0 left-0 right-0 bg-gray-300 h-10 flex items-center px-2">
  339. <button onClick={toggleStartMenu} className="bg-green-600 text-white px-4 py-1 rounded">Start</button>
  340. {startMenuOpen && (
  341. <div className="absolute bottom-10 left-0 w-56 bg-gray-200 border-2 border-gray-400 shadow-lg">
  342. <button onClick={() => openWindow('Notepad', <Notepad />)} className="w-full text-left px-4 py-2 hover:bg-blue-600 hover:text-white flex items-center">
  343. <FileText size={16} className="mr-2" />
  344. Notepad
  345. </button>
  346. <button onClick={() => openWindow('Minesweeper', <Mineswe
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement