mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:27:43 +00:00
GameOfLife: Add choosable patterns
This commit is contained in:
parent
b808815e57
commit
1965d60aeb
6 changed files with 309 additions and 7 deletions
39
Userland/Games/GameOfLife/Pattern.cpp
Normal file
39
Userland/Games/GameOfLife/Pattern.cpp
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Ryan Wilson <ryan@rdwilson.xyz>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "Pattern.h"
|
||||
#include <AK/String.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibGUI/Action.h>
|
||||
#include <stdio.h>
|
||||
|
||||
Pattern::Pattern(Vector<String> pattern)
|
||||
{
|
||||
m_pattern = move(pattern);
|
||||
}
|
||||
|
||||
Pattern::~Pattern()
|
||||
{
|
||||
}
|
||||
|
||||
void Pattern::set_action(GUI::Action* action)
|
||||
{
|
||||
m_action = action;
|
||||
}
|
||||
|
||||
void Pattern::rotate_clockwise()
|
||||
{
|
||||
Vector<String> rotated;
|
||||
for (size_t i = 0; i < m_pattern.first().length(); i++) {
|
||||
StringBuilder builder;
|
||||
for (int j = m_pattern.size() - 1; j >= 0; j--) {
|
||||
builder.append(m_pattern.at(j).substring(i, 1));
|
||||
}
|
||||
rotated.append(builder.to_string());
|
||||
}
|
||||
m_pattern = move(rotated);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue